Bug 968308 - Part 4: Fix testUITelemetry bustage. r=liuche
authorSola Ogunsakin <oogunsakin@mozilla.com>
Mon, 31 Mar 2014 14:41:54 -0700
changeset 194913 607347c9a202ea6f629b7f80712aa9d95cd406cf
parent 194912 a58e8a657b499d0fb92dbbbe12055d0d33c0cc8e
child 194914 862e63e75fd30d7ed87fd9c4eac727cad15d66a3
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche
bugs968308
milestone31.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 968308 - Part 4: Fix testUITelemetry bustage. r=liuche
mobile/android/base/tests/testUITelemetry.java
mobile/android/base/tests/testUITelemetry.js
--- a/mobile/android/base/tests/testUITelemetry.java
+++ b/mobile/android/base/tests/testUITelemetry.java
@@ -2,43 +2,47 @@ package org.mozilla.gecko.tests;
 
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.PrefsHelper;
 import org.mozilla.gecko.Telemetry;
 
 import android.util.Log;
 
 public class testUITelemetry extends JavascriptTest {
+    // Prefix used to distinguish test events and sessions from
+    // real ones. Used by the javascript part of the test.
+    static final String TEST_PREFIX = "TEST-";
+
     public testUITelemetry() {
         super("testUITelemetry.js");
     }
 
     @Override
     public void testJavascript() throws Exception {
         blockForGeckoReady();
 
         // We can't run these tests unless telemetry is turned on --
         // the events will be dropped on the floor.
         Log.i("GeckoTest", "Enabling telemetry.");
         PrefsHelper.setPref(AppConstants.TELEMETRY_PREF_NAME, true);
 
         Log.i("GeckoTest", "Adding telemetry events.");
         try {
-            Telemetry.sendUIEvent("enone", "method0");
-            Telemetry.startUISession("foo");
-            Telemetry.sendUIEvent("efoo", "method1");
-            Telemetry.startUISession("foo");
-            Telemetry.sendUIEvent("efoo", "method2");
-            Telemetry.startUISession("bar");
-            Telemetry.sendUIEvent("efoobar", "method3", "foobarextras");
-            Telemetry.stopUISession("foo", "reasonfoo");
-            Telemetry.sendUIEvent("ebar", "method4", "barextras");
-            Telemetry.stopUISession("bar", "reasonbar");
-            Telemetry.stopUISession("bar", "reasonbar2");
-            Telemetry.sendUIEvent("enone", "method5");
+            Telemetry.sendUIEvent(TEST_PREFIX + "enone", "method0");
+            Telemetry.startUISession(TEST_PREFIX + "foo");
+            Telemetry.sendUIEvent(TEST_PREFIX + "efoo", "method1");
+            Telemetry.startUISession(TEST_PREFIX + "foo");
+            Telemetry.sendUIEvent(TEST_PREFIX + "efoo", "method2");
+            Telemetry.startUISession(TEST_PREFIX + "bar");
+            Telemetry.sendUIEvent(TEST_PREFIX + "efoobar", "method3", "foobarextras");
+            Telemetry.stopUISession(TEST_PREFIX + "foo", "reasonfoo");
+            Telemetry.sendUIEvent(TEST_PREFIX + "ebar", "method4", "barextras");
+            Telemetry.stopUISession(TEST_PREFIX + "bar", "reasonbar");
+            Telemetry.stopUISession(TEST_PREFIX + "bar", "reasonbar2");
+            Telemetry.sendUIEvent(TEST_PREFIX + "enone", "method5");
         } catch (Exception e) {
             Log.e("GeckoTest", "Oops.", e);
         }
 
         Log.i("GeckoTest", "Running remaining JS test code.");
         super.testJavascript();
     }
 }
--- a/mobile/android/base/tests/testUITelemetry.js
+++ b/mobile/android/base/tests/testUITelemetry.js
@@ -4,16 +4,19 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/Services.jsm");
 
+const TEST_PREFIX = "TEST-";
+const TEST_REGEX = new RegExp("^" + TEST_PREFIX);
+
 function do_check_array_eq(a1, a2) {
   do_check_eq(a1.length, a2.length);
   for (let i = 0; i < a1.length; ++i) {
     do_check_eq(a1[i], a2[i]);
   }
 }
 
 function getObserver() {
@@ -32,27 +35,31 @@ add_test(function test_enabled() {
   let obs = getObserver();
   do_check_true(!!obs);
   do_check_true(obs.enabled);
   run_next_test();
 });
 
 add_test(function test_telemetry_events() {
   let obs = getObserver();
-  let measurements = obs.getUIMeasurements();
+  let measurements = obs.getUIMeasurements().filter(function(m) {
+    // Only want events and sessions that were generated by
+    // the Java-side of the test.
+    return TEST_REGEX.test(m.type == "event" ? m.action : m.name);
+  });
 
   let expected = [
-    ["event", "enone", "method0", [], null],
-    ["event", "efoo", "method1", ["foo"], null],
-    ["event", "efoo", "method2", ["foo"], null],
-    ["event", "efoobar", "method3", ["foo", "bar"], "foobarextras"],
-    ["session", "foo", "reasonfoo"],
-    ["event", "ebar", "method4", ["bar"], "barextras"],
-    ["session", "bar", "reasonbar"],
-    ["event", "enone", "method5", [], null],
+    ["event",   TEST_PREFIX + "enone",   "method0", [], null],
+    ["event",   TEST_PREFIX + "efoo",    "method1", ["foo"], null],
+    ["event",   TEST_PREFIX + "efoo",    "method2", ["foo"], null],
+    ["event",   TEST_PREFIX + "efoobar", "method3", ["foo", "bar"], "foobarextras"],
+    ["session", TEST_PREFIX + "foo",     "reasonfoo"],
+    ["event",   TEST_PREFIX + "ebar",    "method4", ["bar"], "barextras"],
+    ["session", TEST_PREFIX + "bar",     "reasonbar"],
+    ["event",   TEST_PREFIX + "enone",   "method5", [], null],
   ];
 
   do_check_eq(expected.length, measurements.length);
 
   for (let i = 0; i < measurements.length; ++i) {
     let m = measurements[i];
 
     let type = m[0];