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 /dom/browser-element/mochitest/browserElement_SetVisible.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 'dom/browser-element/mochitest/browserElement_SetVisible.js')
-rw-r--r-- | dom/browser-element/mochitest/browserElement_SetVisible.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/dom/browser-element/mochitest/browserElement_SetVisible.js b/dom/browser-element/mochitest/browserElement_SetVisible.js new file mode 100644 index 000000000..dac8d7e42 --- /dev/null +++ b/dom/browser-element/mochitest/browserElement_SetVisible.js @@ -0,0 +1,75 @@ +/* Any copyright is dedicated to the public domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test the setVisible property for mozbrowser +"use strict"; + +SimpleTest.waitForExplicitFinish(); +SimpleTest.requestFlakyTimeout("untriaged"); +browserElementTestHelpers.setEnabledPref(true); + +var iframeScript = function() { + content.document.addEventListener("visibilitychange", function() { + sendAsyncMessage('test:visibilitychange', { + hidden: content.document.hidden + }); + }, false); +} + +function runTest() { + var mm; + var numEvents = 0; + var iframe1 = document.createElement('iframe'); + iframe1.setAttribute('mozbrowser', 'true'); + iframe1.src = 'data:text/html,1'; + + document.body.appendChild(iframe1); + + function recvVisibilityChanged(msg) { + msg = SpecialPowers.wrap(msg); + numEvents++; + if (numEvents === 1) { + ok(true, 'iframe recieved visibility changed'); + ok(msg.json.hidden === true, 'hidden attribute correctly set'); + iframe1.setVisible(false); + iframe1.setVisible(true); + } else if (numEvents === 2) { + ok(msg.json.hidden === false, 'hidden attribute correctly set'); + // Allow some time in case we generate too many events + setTimeout(function() { + mm.removeMessageListener('test:visibilitychange', recvVisibilityChanged); + SimpleTest.finish(); + }, 100); + } else { + ok(false, 'Too many visibilitychange events'); + } + } + + function iframeLoaded() { + testGetVisible(); + } + + function testGetVisible() { + iframe1.setVisible(false); + iframe1.getVisible().onsuccess = function(evt) { + ok(evt.target.result === false, 'getVisible() responds false after setVisible(false)'); + + iframe1.setVisible(true); + iframe1.getVisible().onsuccess = function(evt) { + ok(evt.target.result === true, 'getVisible() responds true after setVisible(true)'); + testVisibilityChanges(); + }; + }; + } + + function testVisibilityChanges() { + mm = SpecialPowers.getBrowserFrameMessageManager(iframe1); + mm.addMessageListener('test:visibilitychange', recvVisibilityChanged); + mm.loadFrameScript('data:,(' + iframeScript.toString() + ')();', false); + iframe1.setVisible(false); + } + + iframe1.addEventListener('mozbrowserloadend', iframeLoaded); +} + +addEventListener('testready', runTest); |