2012-06-10 23:44:50 +00:00
|
|
|
/* Any copyright is dedicated to the public domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
2012-06-09 16:05:31 +00:00
|
|
|
|
2012-06-10 23:44:50 +00:00
|
|
|
// Test the setVisible property for mozbrowser
|
|
|
|
"use strict";
|
2012-05-27 12:39:04 +00:00
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
2014-12-11 18:34:40 +00:00
|
|
|
SimpleTest.requestFlakyTimeout("untriaged");
|
2013-03-28 19:51:10 +00:00
|
|
|
browserElementTestHelpers.setEnabledPref(true);
|
|
|
|
browserElementTestHelpers.addPermission();
|
2012-05-27 12:39:04 +00:00
|
|
|
|
|
|
|
var iframeScript = function() {
|
2012-11-16 22:22:56 +00:00
|
|
|
content.document.addEventListener("visibilitychange", function() {
|
2012-05-27 12:39:04 +00:00
|
|
|
sendAsyncMessage('test:visibilitychange', {
|
2012-11-16 22:22:56 +00:00
|
|
|
hidden: content.document.hidden
|
2012-05-27 12:39:04 +00:00
|
|
|
});
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function runTest() {
|
2012-05-28 17:55:48 +00:00
|
|
|
var mm;
|
2012-05-27 12:39:04 +00:00
|
|
|
var numEvents = 0;
|
|
|
|
var iframe1 = document.createElement('iframe');
|
2014-10-31 02:39:15 +00:00
|
|
|
iframe1.setAttribute('mozbrowser', 'true');
|
2012-05-27 12:39:04 +00:00
|
|
|
iframe1.src = 'data:text/html,1';
|
|
|
|
|
|
|
|
document.body.appendChild(iframe1);
|
|
|
|
|
|
|
|
function recvVisibilityChanged(msg) {
|
2012-08-15 03:54:33 +00:00
|
|
|
msg = SpecialPowers.wrap(msg);
|
2012-05-27 12:39:04 +00:00
|
|
|
numEvents++;
|
|
|
|
if (numEvents === 1) {
|
|
|
|
ok(true, 'iframe recieved visibility changed');
|
2012-11-16 22:22:56 +00:00
|
|
|
ok(msg.json.hidden === true, 'hidden attribute correctly set');
|
2012-05-27 12:39:04 +00:00
|
|
|
iframe1.setVisible(false);
|
|
|
|
iframe1.setVisible(true);
|
|
|
|
} else if (numEvents === 2) {
|
2012-11-16 22:22:56 +00:00
|
|
|
ok(msg.json.hidden === false, 'hidden attribute correctly set');
|
2012-05-27 12:39:04 +00:00
|
|
|
// Allow some time in case we generate too many events
|
|
|
|
setTimeout(function() {
|
2012-05-28 17:55:48 +00:00
|
|
|
mm.removeMessageListener('test:visibilitychange', recvVisibilityChanged);
|
2012-05-27 12:39:04 +00:00
|
|
|
SimpleTest.finish();
|
|
|
|
}, 100);
|
|
|
|
} else {
|
2012-11-16 22:22:56 +00:00
|
|
|
ok(false, 'Too many visibilitychange events');
|
2012-05-27 12:39:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function iframeLoaded() {
|
2013-01-07 16:46:23 +00:00
|
|
|
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() {
|
2012-05-28 17:55:48 +00:00
|
|
|
mm = SpecialPowers.getBrowserFrameMessageManager(iframe1);
|
2012-05-27 12:39:04 +00:00
|
|
|
mm.addMessageListener('test:visibilitychange', recvVisibilityChanged);
|
|
|
|
mm.loadFrameScript('data:,(' + iframeScript.toString() + ')();', false);
|
|
|
|
iframe1.setVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
iframe1.addEventListener('mozbrowserloadend', iframeLoaded);
|
|
|
|
}
|
|
|
|
|
2013-03-28 19:51:10 +00:00
|
|
|
addEventListener('testready', runTest);
|