dom/browser-element/mochitest/browserElement_SetVisibleFrames.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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

mercurial