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_TopBarrier.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_TopBarrier.js')
-rw-r--r-- | dom/browser-element/mochitest/browserElement_TopBarrier.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/dom/browser-element/mochitest/browserElement_TopBarrier.js b/dom/browser-element/mochitest/browserElement_TopBarrier.js new file mode 100644 index 000000000..3bd68854c --- /dev/null +++ b/dom/browser-element/mochitest/browserElement_TopBarrier.js @@ -0,0 +1,81 @@ +/* Any copyright is dedicated to the public domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that an <iframe mozbrowser> is a window.{top,parent,frameElement} barrier. +"use strict"; + +SimpleTest.waitForExplicitFinish(); +browserElementTestHelpers.setEnabledPref(true); +browserElementTestHelpers.addPermission(); + +var iframe; +function runTest() { + iframe = document.createElement('iframe'); + iframe.addEventListener('mozbrowserloadend', function() { + try { + outerIframeLoaded(); + } catch(e) { + dump("Got error: " + e + '\n'); + } + }); + iframe.setAttribute('mozbrowser', 'true'); + iframe.src = 'data:text/html,Outer iframe <iframe id="inner-iframe"></iframe>'; + // For kicks, this test uses a display:none iframe. This shouldn't make a + // difference in anything. + iframe.style.display = 'none'; + document.body.appendChild(iframe); +} + +var numMsgReceived = 0; +function outerIframeLoaded() { + // If you're changing the amount of is() calls in injectedScript, + // also change the number in waitForMessages accordingly + var injectedScript = + "data:,function is(a, b, desc) { \ + if (a == b) { \ + sendAsyncMessage('test:test-pass', desc); \ + } else { \ + sendAsyncMessage('test:test-fail', desc + ' ' + a + ' != ' + b); \ + } \ + } \ + is(content.window.top, content.window, 'top'); \ + is(content.window.content, content.window, 'content'); \ + is(content.window.parent, content.window, 'parent'); \ + is(content.window.frameElement, null, 'frameElement'); \ + var innerIframe = content.document.getElementById('inner-iframe'); \ + var innerWindow = innerIframe.contentWindow; \ + is(innerWindow.top, content.window, 'inner top'); \ + is(innerWindow.content, content.window, 'inner content'); \ + is(innerWindow.parent, content.window, 'inner parent'); \ + is(innerWindow.frameElement, innerIframe, 'inner frameElement');" + + var mm = SpecialPowers.getBrowserFrameMessageManager(iframe); + + function onRecvTestPass(msg) { + numMsgReceived++; + ok(true, msg.json); + } + mm.addMessageListener('test:test-pass', onRecvTestPass); + + function onRecvTestFail(msg) { + numMsgReceived++; + ok(false, msg.json); + } + mm.addMessageListener('test:test-fail', onRecvTestFail); + + mm.loadFrameScript(injectedScript, /* allowDelayedLoad = */ false); + + // 8 is the number of is() calls in injectedScript + waitForMessages(8); +} + +function waitForMessages(num) { + if (numMsgReceived < num) { + SimpleTest.executeSoon(function() { waitForMessages(num); }); + return; + } + + SimpleTest.finish(); +} + +addEventListener('testready', runTest); |