fune/toolkit/modules/tests/browser/file_web_channel_iframe.html
Gijs Kruitbosch 00778dd54e Bug 1591212 - make webchannel work with fission, r=vladikoff,mconley
Differential Revision: https://phabricator.services.mozilla.com/D51214

--HG--
rename : toolkit/modules/WebChannel.jsm => toolkit/actors/WebChannelParent.jsm
rename : browser/base/content/test/general/browser_web_channel.js => toolkit/modules/tests/browser/browser_web_channel.js
rename : browser/base/content/test/general/browser_web_channel.html => toolkit/modules/tests/browser/file_web_channel.html
rename : browser/base/content/test/general/browser_web_channel_iframe.html => toolkit/modules/tests/browser/file_web_channel_iframe.html
extra : moz-landing-system : lando
2019-11-02 00:39:35 +00:00

96 lines
2.4 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>web_channel_test (iframe)</title>
</head>
<body>
<script>
var REDIRECTED_IFRAME_SRC_ROOT = "http://example.org/" + location.pathname;
window.onload = function() {
var testName = window.location.search.replace(/^\?/, "");
switch (testName) {
case "iframe":
test_iframe();
break;
case "iframe_pre_redirect":
test_iframe_pre_redirect();
break;
case "iframe_post_redirect":
test_iframe_post_redirect();
break;
default:
throw new Error(`INVALID TEST NAME ${testName}`);
}
};
function test_iframe() {
var firstMessage = new window.CustomEvent("WebChannelMessageToChrome", {
detail: JSON.stringify({
id: "twoway",
message: {
command: "one",
},
}),
});
window.addEventListener("WebChannelMessageToContent", function(e) {
var secondMessage = new window.CustomEvent("WebChannelMessageToChrome", {
detail: JSON.stringify({
id: "twoway",
message: {
command: "two",
detail: e.detail.message,
},
}),
});
if (!e.detail.message.error) {
window.dispatchEvent(secondMessage);
}
}, true);
window.dispatchEvent(firstMessage);
}
function test_iframe_pre_redirect() {
var firstMessage = new window.CustomEvent("WebChannelMessageToChrome", {
detail: JSON.stringify({
id: "pre_redirect",
message: {
command: "redirecting",
},
}),
});
window.dispatchEvent(firstMessage);
document.location = REDIRECTED_IFRAME_SRC_ROOT + "?iframe_post_redirect";
}
function test_iframe_post_redirect() {
window.addEventListener("WebChannelMessageToContent", function(e) {
var echoMessage = new window.CustomEvent("WebChannelMessageToChrome", {
detail: JSON.stringify({
id: "post_redirect",
message: e.detail.message,
}),
});
window.dispatchEvent(echoMessage);
}, true);
// Let the test parent know the page has loaded and is ready to echo events
var loadedMessage = new window.CustomEvent("WebChannelMessageToChrome", {
detail: JSON.stringify({
id: "post_redirect",
message: {
command: "loaded",
},
}),
});
window.dispatchEvent(loadedMessage);
}
</script>
</body>
</html>