diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/mochitest/tests/browser/browser_waitForFocus.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/mochitest/tests/browser/browser_waitForFocus.js')
-rw-r--r-- | testing/mochitest/tests/browser/browser_waitForFocus.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/testing/mochitest/tests/browser/browser_waitForFocus.js b/testing/mochitest/tests/browser/browser_waitForFocus.js new file mode 100644 index 000000000..8f9e27586 --- /dev/null +++ b/testing/mochitest/tests/browser/browser_waitForFocus.js @@ -0,0 +1,69 @@ + +const gBaseURL = "https://example.com/browser/testing/mochitest/tests/browser/"; + +function *promiseTabLoadEvent(tab, url) +{ + return new Promise(function (resolve, reject) { + function handleLoadEvent(event) { + if (event.originalTarget != tab.linkedBrowser.contentDocument || + event.target.location.href == "about:blank" || + (url && event.target.location.href != url)) { + return; + } + + tab.linkedBrowser.removeEventListener("load", handleLoadEvent, true); + resolve(event); + } + + tab.linkedBrowser.addEventListener("load", handleLoadEvent, true, true); + if (url) + tab.linkedBrowser.loadURI(url); + }); +} + +// Load a new blank tab +add_task(function *() { + yield BrowserTestUtils.openNewForegroundTab(gBrowser); + + gURLBar.focus(); + + let browser = gBrowser.selectedBrowser; + yield SimpleTest.promiseFocus(browser.contentWindowAsCPOW, true); + + is(document.activeElement, browser, "Browser is focused when about:blank is loaded"); + + gBrowser.removeCurrentTab(); + gURLBar.focus(); +}); + +// Load a tab with a subframe inside it and wait until the subframe is focused +add_task(function *() { + let tab = gBrowser.addTab(); + gBrowser.selectedTab = tab; + + let browser = gBrowser.getBrowserForTab(tab); + yield promiseTabLoadEvent(tab, gBaseURL + "waitForFocusPage.html"); + + yield SimpleTest.promiseFocus(browser.contentWindowAsCPOW); + + is(document.activeElement, browser, "Browser is focused when page is loaded"); + + yield SimpleTest.promiseFocus(browser.contentWindowAsCPOW.frames[0]); + + is(browser.contentWindowAsCPOW.document.activeElement.localName, "iframe", "Child iframe is focused"); + + gBrowser.removeCurrentTab(); +}); + +// Pass a browser to promiseFocus +add_task(function *() { + yield BrowserTestUtils.openNewForegroundTab(gBrowser, gBaseURL + "waitForFocusPage.html"); + + gURLBar.focus(); + + yield SimpleTest.promiseFocus(gBrowser.selectedBrowser); + + is(document.activeElement, gBrowser.selectedBrowser, "Browser is focused when promiseFocus is passed a browser"); + + gBrowser.removeCurrentTab(); +}); |