Bug 1303167 P5 Fix test that attempts to use setTimeout() during modal dialog. r=smaug

This commit is contained in:
Ben Kelly 2016-10-26 10:20:16 -07:00
parent 9d590cbd9f
commit bffc547933
3 changed files with 21 additions and 2 deletions

View File

@ -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');

View File

@ -8,6 +8,7 @@ support-files =
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

View File

@ -233,8 +233,15 @@ function checkTest4A() {
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() {