mobile/android/base/tests/testUITelemetry.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/tests/testUITelemetry.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,49 @@
     1.4 +package org.mozilla.gecko.tests;
     1.5 +
     1.6 +import org.mozilla.gecko.AppConstants;
     1.7 +import org.mozilla.gecko.PrefsHelper;
     1.8 +import org.mozilla.gecko.Telemetry;
     1.9 +
    1.10 +import android.util.Log;
    1.11 +
    1.12 +public class testUITelemetry extends JavascriptTest {
    1.13 +    // Prefix used to distinguish test events and sessions from
    1.14 +    // real ones. Used by the javascript part of the test.
    1.15 +    static final String TEST_PREFIX = "TEST-";
    1.16 +
    1.17 +    public testUITelemetry() {
    1.18 +        super("testUITelemetry.js");
    1.19 +    }
    1.20 +
    1.21 +    @Override
    1.22 +    public void testJavascript() throws Exception {
    1.23 +        blockForGeckoReady();
    1.24 +
    1.25 +        // We can't run these tests unless telemetry is turned on --
    1.26 +        // the events will be dropped on the floor.
    1.27 +        Log.i("GeckoTest", "Enabling telemetry.");
    1.28 +        PrefsHelper.setPref(AppConstants.TELEMETRY_PREF_NAME, true);
    1.29 +
    1.30 +        Log.i("GeckoTest", "Adding telemetry events.");
    1.31 +        try {
    1.32 +            Telemetry.sendUIEvent(TEST_PREFIX + "enone", "method0");
    1.33 +            Telemetry.startUISession(TEST_PREFIX + "foo");
    1.34 +            Telemetry.sendUIEvent(TEST_PREFIX + "efoo", "method1");
    1.35 +            Telemetry.startUISession(TEST_PREFIX + "foo");
    1.36 +            Telemetry.sendUIEvent(TEST_PREFIX + "efoo", "method2");
    1.37 +            Telemetry.startUISession(TEST_PREFIX + "bar");
    1.38 +            Telemetry.sendUIEvent(TEST_PREFIX + "efoobar", "method3", "foobarextras");
    1.39 +            Telemetry.stopUISession(TEST_PREFIX + "foo", "reasonfoo");
    1.40 +            Telemetry.sendUIEvent(TEST_PREFIX + "ebar", "method4", "barextras");
    1.41 +            Telemetry.stopUISession(TEST_PREFIX + "bar", "reasonbar");
    1.42 +            Telemetry.stopUISession(TEST_PREFIX + "bar", "reasonbar2");
    1.43 +            Telemetry.sendUIEvent(TEST_PREFIX + "enone", "method5");
    1.44 +        } catch (Exception e) {
    1.45 +            Log.e("GeckoTest", "Oops.", e);
    1.46 +        }
    1.47 +
    1.48 +        Log.i("GeckoTest", "Running remaining JS test code.");
    1.49 +        super.testJavascript();
    1.50 +    }
    1.51 +}
    1.52 +

mercurial