|
1 /* Any copyright is dedicated to the public domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 // Test the setVisible property for mozbrowser |
|
5 "use strict"; |
|
6 |
|
7 SimpleTest.waitForExplicitFinish(); |
|
8 browserElementTestHelpers.setEnabledPref(true); |
|
9 browserElementTestHelpers.addPermission(); |
|
10 |
|
11 var iframeScript = function() { |
|
12 content.document.addEventListener("visibilitychange", function() { |
|
13 sendAsyncMessage('test:visibilitychange', { |
|
14 hidden: content.document.hidden |
|
15 }); |
|
16 }, false); |
|
17 } |
|
18 |
|
19 function runTest() { |
|
20 var mm; |
|
21 var numEvents = 0; |
|
22 var iframe1 = document.createElement('iframe'); |
|
23 SpecialPowers.wrap(iframe1).mozbrowser = true; |
|
24 iframe1.src = 'data:text/html,1'; |
|
25 |
|
26 document.body.appendChild(iframe1); |
|
27 |
|
28 function recvVisibilityChanged(msg) { |
|
29 msg = SpecialPowers.wrap(msg); |
|
30 numEvents++; |
|
31 if (numEvents === 1) { |
|
32 ok(true, 'iframe recieved visibility changed'); |
|
33 ok(msg.json.hidden === true, 'hidden attribute correctly set'); |
|
34 iframe1.setVisible(false); |
|
35 iframe1.setVisible(true); |
|
36 } else if (numEvents === 2) { |
|
37 ok(msg.json.hidden === false, 'hidden attribute correctly set'); |
|
38 // Allow some time in case we generate too many events |
|
39 setTimeout(function() { |
|
40 mm.removeMessageListener('test:visibilitychange', recvVisibilityChanged); |
|
41 SimpleTest.finish(); |
|
42 }, 100); |
|
43 } else { |
|
44 ok(false, 'Too many visibilitychange events'); |
|
45 } |
|
46 } |
|
47 |
|
48 function iframeLoaded() { |
|
49 testGetVisible(); |
|
50 } |
|
51 |
|
52 function testGetVisible() { |
|
53 iframe1.setVisible(false); |
|
54 iframe1.getVisible().onsuccess = function(evt) { |
|
55 ok(evt.target.result === false, 'getVisible() responds false after setVisible(false)'); |
|
56 |
|
57 iframe1.setVisible(true); |
|
58 iframe1.getVisible().onsuccess = function(evt) { |
|
59 ok(evt.target.result === true, 'getVisible() responds true after setVisible(true)'); |
|
60 testVisibilityChanges(); |
|
61 }; |
|
62 }; |
|
63 } |
|
64 |
|
65 function testVisibilityChanges() { |
|
66 mm = SpecialPowers.getBrowserFrameMessageManager(iframe1); |
|
67 mm.addMessageListener('test:visibilitychange', recvVisibilityChanged); |
|
68 mm.loadFrameScript('data:,(' + iframeScript.toString() + ')();', false); |
|
69 iframe1.setVisible(false); |
|
70 } |
|
71 |
|
72 iframe1.addEventListener('mozbrowserloadend', iframeLoaded); |
|
73 } |
|
74 |
|
75 addEventListener('testready', runTest); |