tenfourfox/dom/broadcastchannel/tests/test_broadcastchannel_mozbrowser2.html
Cameron Kaiser c9b2922b70 hello FPR
2017-04-19 00:56:45 -07:00

137 lines
3.4 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test for BroadcastChannel - iframe mozbrowser</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<div id="container"></div>
<script type="application/javascript">
var gHostedManifestURL = 'http://test/tests/dom/broadcastchannel/tests/server.sjs?testToken=file_mozbrowser2.html';
var gApp;
function cbError() {
ok(false, "Error callback invoked");
finish();
}
function createBC() {
var bc = new BroadcastChannel('foobar');
bc.onmessage = function(e) {
is(e.data, "Done!", "A message has been received!");
nextStep();
}
nextStep();
}
function completeOperation() {
var bc = new BroadcastChannel('foobar');
bc.postMessage("Done!");
}
function installApp() {
var request = navigator.mozApps.install(gHostedManifestURL);
request.onerror = cbError;
request.onsuccess = function() {
gApp = request.result;
nextStep();
}
}
function uninstallApp() {
// Uninstall the app.
var request = navigator.mozApps.mgmt.uninstall(gApp);
request.onerror = cbError;
request.onsuccess = function() {
// All done.
info("All done");
nextStep();
}
}
function testApp() {
var ifr = document.createElement('iframe');
ifr.setAttribute('mozbrowser', 'true');
ifr.setAttribute('mozapp', gApp.manifestURL);
ifr.setAttribute('src', gApp.manifest.launch_path);
var domParent = document.getElementById('container');
// Set us up to listen for messages from the app.
var listener = function(e) {
ok(true, "Messaging from app complete");
ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
domParent.removeChild(ifr);
nextStep();
}
// This event is triggered when the app calls "alert".
ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
domParent.appendChild(ifr);
}
var steps = [
// Permissions
function() {
SpecialPowers.pushPermissions(
[{ "type": "browser", "allow": 1, "context": document },
{ "type": "embed-apps", "allow": 1, "context": document },
{ "type": "webapps-manage", "allow": 1, "context": document }], nextStep);
},
function() {
SpecialPowers.pushPrefEnv({"set": [["network.disable.ipc.security", true],
["browser.pagethumbnails.capturing_disabled", true],
["dom.mozBrowserFramesEnabled", true],
["dom.ipc.browser_frames.oop_by_default", false],
["dom.ipc.tabs.disabled", false],
["dom.testing.ignore_ipc_principal", true],
["security.mixed_content.block_active_content", false]]},
nextStep);
},
// No confirmation needed when an app is installed
function() {
SpecialPowers.autoConfirmAppInstall(() =>
SpecialPowers.autoConfirmAppUninstall(nextStep));
},
createBC,
// Installing the app
installApp,
// Run tests in app
testApp,
// Uninstall the app
uninstallApp,
// finish
completeOperation
];
function finish() {
SimpleTest.finish();
}
function nextStep() {
if (!steps.length) {
SimpleTest.finish();
return;
}
var step = steps.shift();
step();
}
SimpleTest.waitForExplicitFinish();
nextStep();
</script>
</body>
</html>