dom/browser-element/mochitest/browserElement_SetVisibleFrames.js

changeset 2
7e26c7da4463
equal deleted inserted replaced
-1:000000000000 0:afb7a3e8340b
1 /* Any copyright is dedicated to the public domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 // Bug 762939 - Test that visibility propagates down properly through
5 // hierarchies of <iframe mozbrowser>.
6 //
7 // In this test, we modify the parent's visibility and check that the child's
8 // visibility is changed as appopriate. We test modifying the child's
9 // visibility in a separate testcase.
10
11 "use strict";
12
13 SimpleTest.waitForExplicitFinish();
14 browserElementTestHelpers.setEnabledPref(true);
15 browserElementTestHelpers.addPermission();
16
17 var iframe;
18
19 function runTest() {
20 var principal = SpecialPowers.wrap(document).nodePrincipal;
21 SpecialPowers.addPermission("browser", true, { url: SpecialPowers.wrap(principal.URI).spec,
22 appId: principal.appId,
23 isInBrowserElement: true });
24
25 iframe = document.createElement('iframe');
26 SpecialPowers.wrap(iframe).mozbrowser = true;
27
28 // Our test involves three <iframe mozbrowser>'s, parent, child1, and child2.
29 // child1 and child2 are contained inside parent. child1 is visibile, and
30 // child2 is not.
31 //
32 // For the purposes of this test, we want there to be a process barrier
33 // between child{1,2} and parent. Therefore parent must be a non-remote
34 // <iframe mozbrowser>, until bug 761935 is resolved and we can have nested
35 // content processes.
36 iframe.remote = false;
37
38 iframe.addEventListener('mozbrowsershowmodalprompt', checkMessage);
39 expectMessage('parent:ready', test1);
40
41 document.body.appendChild(iframe);
42 iframe.src = 'file_browserElement_SetVisibleFrames_Outer.html';
43 }
44
45 function test1() {
46 expectMessage('child1:hidden', getVisibleTest1);
47 iframe.setVisible(false);
48 }
49
50 function getVisibleTest1() {
51 iframe.getVisible().onsuccess = function(evt) {
52 ok(evt.target.result === false, 'getVisible shows a hidden frame');
53 test2();
54 };
55 }
56
57 function test2() {
58 expectMessage('child1:visible', getVisibleTest2);
59 iframe.setVisible(true);
60 }
61
62 function getVisibleTest2() {
63 iframe.getVisible().onsuccess = function(evt) {
64 ok(evt.target.result === true, 'getVisible shows a displayed frame');
65 finish();
66 };
67 }
68
69 function finish() {
70 // We need to remove this listener because when this test finishes and the
71 // iframe containing this document is navigated, we'll fire a
72 // visibilitychange(false) event on all child iframes. That's OK and
73 // expected, but if we don't remove our listener, then we'll end up causing
74 // the /next/ test to fail!
75 iframe.removeEventListener('mozbrowsershowmodalprompt', checkMessage);
76
77 var principal = SpecialPowers.wrap(document).nodePrincipal;
78 SpecialPowers.removePermission("browser", { url: SpecialPowers.wrap(principal.URI).spec,
79 appId: principal.appId,
80 isInBrowserElement: true });
81
82 SimpleTest.finish();
83 }
84
85 var expectedMsg = null;
86 var expectedMsgCallback = null;
87 function expectMessage(msg, next) {
88 expectedMsg = msg;
89 expectedMsgCallback = next;
90 }
91
92 function checkMessage(e) {
93 var msg = e.detail.message;
94 is(msg, expectedMsg);
95 if (msg == expectedMsg) {
96 expectedMsg = null;
97 SimpleTest.executeSoon(function() { expectedMsgCallback() });
98 }
99 }
100
101 addEventListener('testready', runTest);

mercurial