Bug 1129849 - Proper B2G identification for worker navigator tests. r=bent
authorAlexandre Lissy <lissyx@lissyx.dyndns.org>
Mon, 09 Feb 2015 03:11:00 -0500
changeset 255868 bad9e5d50b32655179d10107d15ffb35e53b20ad
parent 255867 d9df89f77ab16747a0f306d8888e432c91470152
child 255869 4898846a00bcecc105d05738d59df81d708f5056
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs1129849
milestone38.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 1129849 - Proper B2G identification for worker navigator tests. r=bent
dom/workers/test/navigator_worker.js
dom/workers/test/test_navigator.html
--- a/dom/workers/test/navigator_worker.js
+++ b/dom/workers/test/navigator_worker.js
@@ -13,66 +13,73 @@ var supportedProps = [
   "product",
   "taintEnabled",
   "userAgent",
   "onLine",
   "language",
   "languages",
 ];
 
-var isDesktop = !/Mobile|Tablet/.test(navigator.userAgent);
-var isB2G = !isDesktop && !navigator.userAgent.contains("Android");
-
-// Prepare the interface map showing if a propery should exist in this build.
-// For example, if interfaceMap[foo] = true means navigator.foo should exist.
-var interfaceMap = {};
-
-for (var prop of supportedProps) {
-  if (typeof(prop) === "string") {
-    interfaceMap[prop] = true;
-    continue;
+self.onmessage = function(event) {
+  if (!event || !event.data) {
+    return;
   }
 
-  if (prop.b2g === !isB2G) {
-    interfaceMap[prop.name] = false;
-    continue;
+  startTest(event.data.isB2G);
+};
+
+function startTest(isB2G) {
+  // Prepare the interface map showing if a propery should exist in this build.
+  // For example, if interfaceMap[foo] = true means navigator.foo should exist.
+  var interfaceMap = {};
+
+  for (var prop of supportedProps) {
+    if (typeof(prop) === "string") {
+      interfaceMap[prop] = true;
+      continue;
+    }
+
+    if (prop.b2g === !isB2G) {
+      interfaceMap[prop.name] = false;
+      continue;
+    }
+
+    interfaceMap[prop.name] = true;
   }
 
-  interfaceMap[prop.name] = true;
-}
-
-for (var prop in navigator) {
-  // Make sure the list is current!
-  if (!interfaceMap[prop]) {
-    throw "Navigator has the '" + prop + "' property that isn't in the list!";
-  }
-}
-
-var obj;
-
-for (var prop in interfaceMap) {
-  // Skip the property that is not supposed to exist in this build.
-  if (!interfaceMap[prop]) {
-    continue;
+  for (var prop in navigator) {
+    // Make sure the list is current!
+    if (!interfaceMap[prop]) {
+      throw "Navigator has the '" + prop + "' property that isn't in the list!";
+    }
   }
 
-  if (typeof navigator[prop] == "undefined") {
-    throw "Navigator has no '" + prop + "' property!";
+  var obj;
+
+  for (var prop in interfaceMap) {
+    // Skip the property that is not supposed to exist in this build.
+    if (!interfaceMap[prop]) {
+      continue;
+    }
+
+    if (typeof navigator[prop] == "undefined") {
+      throw "Navigator has no '" + prop + "' property!";
+    }
+
+    obj = { name:  prop };
+
+    if (prop === "taintEnabled") {
+      obj.value = navigator[prop]();
+    } else if (prop === "getDataStores") {
+      obj.value = typeof navigator[prop];
+    } else {
+      obj.value = navigator[prop];
+    }
+
+    postMessage(JSON.stringify(obj));
   }
 
-  obj = { name:  prop };
-
-  if (prop === "taintEnabled") {
-    obj.value = navigator[prop]();
-  } else if (prop === "getDataStores") {
-    obj.value = typeof navigator[prop];
-  } else {
-    obj.value = navigator[prop];
-  }
+  obj = {
+    name: "testFinished"
+  };
 
   postMessage(JSON.stringify(obj));
 }
-
-obj = {
-  name: "testFinished"
-};
-
-postMessage(JSON.stringify(obj));
--- a/dom/workers/test/test_navigator.html
+++ b/dom/workers/test/test_navigator.html
@@ -55,14 +55,16 @@ Tests of DOM Worker Navigator
        "Mismatched navigator string for " + args.name + "!");
   };
 
   worker.onerror = function(event) {
     ok(false, "Worker had an error: " + event.message);
     SimpleTest.finish();
   }
 
+  worker.postMessage({ 'isB2G': SpecialPowers.isB2G });
+
   SimpleTest.waitForExplicitFinish();
 
 </script>
 </pre>
 </body>
 </html>