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