Bug 991600 - Make sure that registering the content policy doesn't race with the call to sendBeacon; r=rbarnes
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 22 Apr 2014 14:31:55 -0400
changeset 198119 39041565bfa9a7f5b9e983df9f8e2fb8a3e6a3c4
parent 198118 0de0cedf6a7dd87c4a76a198243a5280402550b0
child 198120 84b4cf605262bff4881bc08859a45f7611482fc3
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)
reviewersrbarnes
bugs991600
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 991600 - Make sure that registering the content policy doesn't race with the call to sendBeacon; r=rbarnes
dom/tests/mochitest/beacon/test_beaconContentPolicy.html
--- a/dom/tests/mochitest/beacon/test_beaconContentPolicy.html
+++ b/dom/tests/mochitest/beacon/test_beaconContentPolicy.html
@@ -20,17 +20,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 var beaconUrl = "http://mochi.test:8888/tests/dom/tests/mochitest/beacon/beacon-handler.sjs";
 
 const Cc = SpecialPowers.Cc;
 const Ci = SpecialPowers.Ci;
 
 // not enabled by default yet.
 SimpleTest.waitForExplicitFinish();
 
-var policy = setupPolicy();
+var policy;
 
 SpecialPowers.pushPrefEnv({'set': [["beacon.enabled", true]]}, beginTest);
 
 function setupPolicy() {
   var policyID = SpecialPowers.wrap(SpecialPowers.Components).ID("{b80e19d0-878f-d41b-2654-194714a4115c}");
   var policyName = "@mozilla.org/testpolicy;1";
   var policy = {
     // nsISupports implementation
@@ -83,15 +83,20 @@ function teardownPolicy() {
     var componentManager = SpecialPowers.wrap(SpecialPowers.Components).manager.QueryInterface(Ci.nsIComponentRegistrar);
     componentManager.unregisterFactory(policy.policyID, policy.policy);
     var categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
     categoryManager.deleteCategoryEntry("content-policy", policy.policyName, false);
   }, 0);
 }
 
 function beginTest() {
-  navigator.sendBeacon(beaconUrl, "bacon would have been a better name than beacon");
+  policy = setupPolicy();
+  // Make sure to hit the event loop here in order to ensure that nsContentPolicy
+  // has been notified of the newly registered policy.
+  SimpleTest.executeSoon(function() {
+    navigator.sendBeacon(beaconUrl, "bacon would have been a better name than beacon");
+  });
 }
 
 </script>
 </pre>
 </body>
 </html>