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 179957 39041565bfa9a7f5b9e983df9f8e2fb8a3e6a3c4
parent 179956 0de0cedf6a7dd87c4a76a198243a5280402550b0
child 179958 84b4cf605262bff4881bc08859a45f7611482fc3
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersrbarnes
bugs991600
milestone31.0a1
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>