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