gecko-dev/dom/browser-element/mochitest/browserElement_SetVisible.js
Justin Lebar 4ca15feade Bug 852847 - Part 2: Do things later in our browser-element tests, thus avoiding doing things before the browser-element machinery has loaded. r=kk1ff
Also set network.disable.ipc.security to true and leave it that way. This prevents security errors in the tests which happen when we pop the pref.

--HG--
extra : rebase_source : 95f7ca7c3b71cdc0e3e6fd1cfb663a5653f3ab6f
2013-03-28 15:51:10 -04:00

76 lines
2.3 KiB
JavaScript

/* Any copyright is dedicated to the public domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test the setVisible property for mozbrowser
"use strict";
SimpleTest.waitForExplicitFinish();
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.addPermission();
var iframeScript = function() {
content.document.addEventListener("visibilitychange", function() {
sendAsyncMessage('test:visibilitychange', {
hidden: content.document.hidden
});
}, false);
}
function runTest() {
var mm;
var numEvents = 0;
var iframe1 = document.createElement('iframe');
SpecialPowers.wrap(iframe1).mozbrowser = true;
iframe1.src = 'data:text/html,1';
document.body.appendChild(iframe1);
function recvVisibilityChanged(msg) {
msg = SpecialPowers.wrap(msg);
numEvents++;
if (numEvents === 1) {
ok(true, 'iframe recieved visibility changed');
ok(msg.json.hidden === true, 'hidden attribute correctly set');
iframe1.setVisible(false);
iframe1.setVisible(true);
} else if (numEvents === 2) {
ok(msg.json.hidden === false, 'hidden attribute correctly set');
// Allow some time in case we generate too many events
setTimeout(function() {
mm.removeMessageListener('test:visibilitychange', recvVisibilityChanged);
SimpleTest.finish();
}, 100);
} else {
ok(false, 'Too many visibilitychange events');
}
}
function iframeLoaded() {
testGetVisible();
}
function testGetVisible() {
iframe1.setVisible(false);
iframe1.getVisible().onsuccess = function(evt) {
ok(evt.target.result === false, 'getVisible() responds false after setVisible(false)');
iframe1.setVisible(true);
iframe1.getVisible().onsuccess = function(evt) {
ok(evt.target.result === true, 'getVisible() responds true after setVisible(true)');
testVisibilityChanges();
};
};
}
function testVisibilityChanges() {
mm = SpecialPowers.getBrowserFrameMessageManager(iframe1);
mm.addMessageListener('test:visibilitychange', recvVisibilityChanged);
mm.loadFrameScript('data:,(' + iframeScript.toString() + ')();', false);
iframe1.setVisible(false);
}
iframe1.addEventListener('mozbrowserloadend', iframeLoaded);
}
addEventListener('testready', runTest);