mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-08 20:47:44 +00:00
09a262787c
We are white-listing the existing set of tests that use setTimeout like this. Hopefully these tests will be investigated and fixed in the future, so that we can narrow down the white-list. This check is only turned on for mochitest-plain for now.
77 lines
2.3 KiB
JavaScript
77 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);
|
|
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');
|
|
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);
|