gecko-dev/dom/browser-element/mochitest/browserElement_SetVisible.js
Alexandre Lissy 6798f02654 Bug 1286530 - Clean AvailableIn, CheckAnyPermissions and CheckAllPermissions from WebIDL r=bz,fabrice
MozReview-Commit-ID: 6EQfBM09xUE

--HG--
rename : dom/contacts/tests/test_contacts_cache.xul => dom/contacts/tests/test_contacts_a_cache.xul
rename : dom/contacts/tests/test_contacts_shutdown.xul => dom/contacts/tests/test_contacts_a_shutdown.xul
rename : dom/contacts/tests/test_contacts_upgrade.xul => dom/contacts/tests/test_contacts_a_upgrade.xul
rename : dom/mobilemessage/tests/mochitest/mochitest.ini => dom/mobilemessage/tests/mochitest/chrome.ini
extra : rebase_source : 5f708f2a927fafff66626367ef07080785ba9f55
2016-04-21 15:48:59 +02:00

75 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();
SimpleTest.requestFlakyTimeout("untriaged");
browserElementTestHelpers.setEnabledPref(true);
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');
iframe1.setAttribute('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);