summaryrefslogtreecommitdiffstats
path: root/dom/xul/test/file_bug1069772.xul
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/xul/test/file_bug1069772.xul
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-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 'dom/xul/test/file_bug1069772.xul')
-rw-r--r--dom/xul/test/file_bug1069772.xul143
1 files changed, 143 insertions, 0 deletions
diff --git a/dom/xul/test/file_bug1069772.xul b/dom/xul/test/file_bug1069772.xul
new file mode 100644
index 000000000..b90985246
--- /dev/null
+++ b/dom/xul/test/file_bug1069772.xul
@@ -0,0 +1,143 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
+ type="text/css"?>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1069772
+-->
+<window title="Mozilla Bug 1069772"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onload="run();">
+
+ <!-- test code goes here -->
+ <script type="application/javascript">
+ <![CDATA[
+
+ const {interfaces: Ci, classes: Cc, results: Cr, utils: Cu} = Components;
+ Cu.import("resource://testing-common/ContentTask.jsm");
+ Cu.import("resource://testing-common/BrowserTestUtils.jsm");
+ Cu.import("resource://gre/modules/Services.jsm");
+ ContentTask.setTestScope(window.opener.wrappedJSObject);
+
+ let imports = ['SimpleTest', 'ok', 'is'];
+ for (let name of imports) {
+ window[name] = window.opener.wrappedJSObject[name];
+ }
+
+ /** Test for Bug 1069772 **/
+ function run() {
+ // test the transition:
+ // prerender => visible => hidden => visible
+ // on a non-remote browser
+ createPrerenderedBrowser(false)
+ .then(browser => verifyBrowser(browser, true, false))
+ .then(browser => verifyVisibility(browser, 'prerender'))
+ .then(browser => makePrerenderedBrowserActive(browser))
+ .then(browser => verifyBrowser(browser, false, false))
+ .then(browser => verifyVisibility(browser, 'visible'))
+ .then(browser => hideBrowser(browser))
+ .then(browser => verifyBrowser(browser, false, false))
+ .then(browser => verifyVisibility(browser, 'hidden'))
+ .then(browser => showBrowser(browser))
+ .then(browser => verifyBrowser(browser, false, false))
+ .then(browser => verifyVisibility(browser, 'visible'))
+
+ // test the transition:
+ // prerender => visible => hidden => visible
+ // on a remote browser
+ .then(() => createPrerenderedBrowser(true))
+ .then(browser => verifyBrowser(browser, true, true))
+ .then(browser => verifyVisibility(browser, 'prerender'))
+ .then(browser => makePrerenderedBrowserActive(browser))
+ .then(browser => verifyBrowser(browser, false, true))
+ .then(browser => verifyVisibility(browser, 'visible'))
+ .then(browser => hideBrowser(browser))
+ .then(browser => verifyBrowser(browser, false, true))
+ .then(browser => verifyVisibility(browser, 'hidden'))
+ .then(browser => showBrowser(browser))
+ .then(browser => verifyBrowser(browser, false, true))
+ .then(browser => verifyVisibility(browser, 'visible'))
+
+ // finish test
+ .then(() => {
+ window.close();
+ SimpleTest.finish();
+ });
+ }
+
+ function createPrerenderedBrowser(remote) {
+ let browser = document.createElement('browser');
+ browser.setAttribute('type', 'content');
+ browser.setAttribute('prerendered', true);
+ browser.setAttribute('remote', remote);
+ browser.setAttribute('src', 'data:text/html;charset=UTF-8,<html><body>' +
+ '<iframe id="iframe" src="data:text/html;charset=UTF-8,Hello Frame!">' +
+ '</iframe></body></html>');
+
+ // wait for 'load' and 'pageshow'
+ let promises = [];
+ promises.push(BrowserTestUtils.browserLoaded(browser));
+ promises.push(new Promise(resolve =>
+ Services.mm.addMessageListener('test:pageshow', resolve)));
+ Services.mm.loadFrameScript('data:,' +
+ 'addEventListener("pageshow", ' +
+ '() => sendAsyncMessage("test:pageshow", null), false);',
+ true);
+
+ document.getElementById('stack').appendChild(browser);
+ return Promise.all(promises).then(() => browser);
+ }
+
+ function verifyBrowser(browser, prerendered, remote) {
+ let docShellOrTabParent = remote ?
+ browser.frameLoader.tabParent : browser.frameLoader.docShell;
+ ok(docShellOrTabParent, 'docShellOrTabParent should not be null');
+ is(docShellOrTabParent.isPrerendered, prerendered,
+ 'isPrerendered should be ' + prerendered);
+ return browser;
+ }
+
+ function verifyVisibility(browser, visibility) {
+ return ContentTask.spawn(browser, visibility, (v) => {
+ let iframe = content.document.getElementById('iframe');
+ is(content.document.visibilityState, v, 'check doc.visibilityState');
+ is(content.document.hidden, v != 'visible', 'check doc.hidden');
+ is(iframe.contentDocument.visibilityState, v, 'check iframe doc.visibilityState');
+ is(iframe.contentDocument.hidden, v != 'visible', 'check iframe doc.hidden');
+ }).then(() => browser);
+ }
+
+ function makePrerenderedBrowserActive(browser) {
+ let promise = waitForVisibilityChange(browser);
+ browser.setAttribute('prerendered', false);
+ browser.makePrerenderedBrowserActive();
+ return promise.then(() => browser);
+ }
+
+ function hideBrowser(browser) {
+ let promise = waitForVisibilityChange(browser);
+ browser.docShellIsActive = false;
+ return promise.then(() => browser);
+ }
+
+ function showBrowser(browser) {
+ let promise = waitForVisibilityChange(browser);
+ browser.docShellIsActive = true;
+ return promise.then(() => browser);
+ }
+
+ function waitForVisibilityChange(browser) {
+ return ContentTask.spawn(browser, null, () => {
+ return new Promise(resolve => {
+ let iframe = content.document.getElementById('iframe');
+ iframe.contentDocument.addEventListener('visibilitychange', function listener() {
+ iframe.contentDocument.removeEventListener('visibilitychange', listener);
+ resolve();
+ });
+ });
+ });
+ }
+
+ ]]>
+ </script>
+ <stack id="stack" flex="1" />
+</window>