|
1 /* Any copyright is dedicated to the public domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 // Test that an <iframe mozbrowser> is a window.{top,parent,frameElement} barrier. |
|
5 "use strict"; |
|
6 |
|
7 SimpleTest.waitForExplicitFinish(); |
|
8 browserElementTestHelpers.setEnabledPref(true); |
|
9 browserElementTestHelpers.addPermission(); |
|
10 |
|
11 var iframe; |
|
12 function runTest() { |
|
13 iframe = document.createElement('iframe'); |
|
14 iframe.addEventListener('mozbrowserloadend', function() { |
|
15 try { |
|
16 outerIframeLoaded(); |
|
17 } catch(e) { |
|
18 dump("Got error: " + e + '\n'); |
|
19 } |
|
20 }); |
|
21 SpecialPowers.wrap(iframe).mozbrowser = true; |
|
22 iframe.src = 'data:text/html,Outer iframe <iframe id="inner-iframe"></iframe>'; |
|
23 // For kicks, this test uses a display:none iframe. This shouldn't make a |
|
24 // difference in anything. |
|
25 iframe.style.display = 'none'; |
|
26 document.body.appendChild(iframe); |
|
27 } |
|
28 |
|
29 var numMsgReceived = 0; |
|
30 function outerIframeLoaded() { |
|
31 var injectedScript = |
|
32 "data:,function is(a, b, desc) { \ |
|
33 if (a == b) { \ |
|
34 sendAsyncMessage('test:test-pass', desc); \ |
|
35 } else { \ |
|
36 sendAsyncMessage('test:test-fail', desc + ' ' + a + ' != ' + b); \ |
|
37 } \ |
|
38 } \ |
|
39 is(content.window.top, content.window, 'top'); \ |
|
40 is(content.window.content, content.window, 'content'); \ |
|
41 is(content.window.parent, content.window, 'parent'); \ |
|
42 is(content.window.frameElement, null, 'frameElement'); \ |
|
43 var innerIframe = content.document.getElementById('inner-iframe'); \ |
|
44 var innerWindow = innerIframe.contentWindow; \ |
|
45 is(innerWindow.top, content.window, 'inner top'); \ |
|
46 is(innerWindow.content, content.window, 'inner content'); \ |
|
47 is(innerWindow.parent, content.window, 'inner parent'); \ |
|
48 is(innerWindow.frameElement, innerIframe, 'inner frameElement');" |
|
49 |
|
50 var mm = SpecialPowers.getBrowserFrameMessageManager(iframe); |
|
51 |
|
52 function onRecvTestPass(msg) { |
|
53 numMsgReceived++; |
|
54 ok(true, msg.json); |
|
55 } |
|
56 mm.addMessageListener('test:test-pass', onRecvTestPass); |
|
57 |
|
58 function onRecvTestFail(msg) { |
|
59 numMsgReceived++; |
|
60 ok(false, msg.json); |
|
61 } |
|
62 mm.addMessageListener('test:test-fail', onRecvTestFail); |
|
63 |
|
64 mm.loadFrameScript(injectedScript, /* allowDelayedLoad = */ false); |
|
65 |
|
66 waitForMessages(6); |
|
67 } |
|
68 |
|
69 function waitForMessages(num) { |
|
70 if (numMsgReceived < num) { |
|
71 SimpleTest.executeSoon(function() { waitForMessages(num); }); |
|
72 return; |
|
73 } |
|
74 |
|
75 SimpleTest.finish(); |
|
76 } |
|
77 |
|
78 addEventListener('testready', runTest); |