Bug 1303167 P5 Fix test that attempts to use setTimeout() during modal dialog. r=smaug
authorBen Kelly <ben@wanderview.com>
Wed, 26 Oct 2016 10:20:16 -0700
changeset 346333 7f26ccd5a281eb8c0e001cb52f6ff9fdc1edd024
parent 346332 8a4820cef74e475bcaf23ea0b9f6f60dad6f57c7
child 346334 e0f4b01bb284c15605f7931d0e7286af3d98b732
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1303167
milestone52.0a1
Bug 1303167 P5 Fix test that attempts to use setTimeout() during modal dialog. r=smaug
toolkit/components/passwordmgr/test/chrome_timeout.js
toolkit/components/passwordmgr/test/mochitest.ini
toolkit/components/passwordmgr/test/test_master_password.html
new file mode 100644
--- /dev/null
+++ b/toolkit/components/passwordmgr/test/chrome_timeout.js
@@ -0,0 +1,11 @@
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+addMessageListener('setTimeout', msg => {
+  let timer = Cc['@mozilla.org/timer;1'].createInstance(Ci.nsITimer);
+  timer.init(_ => {
+    sendAsyncMessage('timeout');
+  }, msg.delay, Ci.nsITimer.TYPE_ONE_SHOT);
+});
+
+sendAsyncMessage('ready');
--- a/toolkit/components/passwordmgr/test/mochitest.ini
+++ b/toolkit/components/passwordmgr/test/mochitest.ini
@@ -3,16 +3,17 @@ skip-if = buildapp == 'mulet' || buildap
 support-files =
   authenticate.sjs
   blank.html
   formsubmit.sjs
   prompt_common.js
   pwmgr_common.js
   subtst_master_pass.html
   subtst_prompt_async.html
+  chrome_timeout.js
 
 [test_master_password.html]
 skip-if = toolkit == 'android' # Tests desktop prompts
 [test_prompt_async.html]
 skip-if = toolkit == 'android' # Tests desktop prompts
 [test_xhr.html]
 skip-if = toolkit == 'android' # Tests desktop prompts
 [test_xml_load.html]
--- a/toolkit/components/passwordmgr/test/test_master_password.html
+++ b/toolkit/components/passwordmgr/test/test_master_password.html
@@ -228,18 +228,25 @@ function checkTest4A() {
     // driven from DOMContentLoaded, if that blocks due to prompting for a MP,
     // the load even will also be blocked until the prompt is dismissed).
     iframe2.onload = checkTest4B_delay;
     iframe2.src = exampleCom + "subtst_master_pass.html";
 }
 
 function checkTest4B_delay() {
     // Testing a negative, wait a little to give the login manager a chance to
-    // (incorrectly) fill in the form.
-    setTimeout(checkTest4B, 500);
+    // (incorrectly) fill in the form.  Note, we cannot use setTimeout()
+    // here because the modal window suspends all window timers.  Instead we
+    // must use a chrome script to use nsITimer directly.
+    let chromeURL = SimpleTest.getTestFileURL("chrome_timeout.js");
+    let script = SpecialPowers.loadChromeScript(chromeURL);
+    script.addMessageListener('ready', _ => {
+      script.sendAsyncMessage('setTimeout', { delay: 500 });
+    });
+    script.addMessageListener('timeout', checkTest4B);
 }
 
 function checkTest4B() {
     ok(true, "checkTest4B starting");
     // iframe2 should load without having triggered a MP prompt (because one
     // is already waiting)
 
     // check contents of iframe2 fields