summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/tests/browser/newtabwebchannel_basic.html
diff options
context:
space:
mode:
Diffstat (limited to 'browser/components/newtab/tests/browser/newtabwebchannel_basic.html')
-rw-r--r--browser/components/newtab/tests/browser/newtabwebchannel_basic.html36
1 files changed, 36 insertions, 0 deletions
diff --git a/browser/components/newtab/tests/browser/newtabwebchannel_basic.html b/browser/components/newtab/tests/browser/newtabwebchannel_basic.html
new file mode 100644
index 000000000..7f3c79920
--- /dev/null
+++ b/browser/components/newtab/tests/browser/newtabwebchannel_basic.html
@@ -0,0 +1,36 @@
+<html>
+ <head>
+ <meta charset="utf8">
+ <title>Newtab WebChannel test</title>
+ </head>
+ <body>
+ <script>
+ document.onreadystatechange = function () {
+ let msg = new window.CustomEvent("WebChannelMessageToChrome", {
+ detail: JSON.stringify({
+ id: "newtab",
+ message: JSON.stringify({type: "foo", data: "bar"}),
+ })
+ });
+ window.dispatchEvent(msg);
+ };
+
+ window.addEventListener("WebChannelMessageToContent", function(e) {
+ if (e.detail.message && e.detail.message.type.startsWith("respond")) {
+ var detail = {
+ id: "newtab",
+ message: JSON.stringify({type: "reply", data: "quuz"}),
+ };
+ if (e.detail.message.type !== "respond_object") {
+ detail = JSON.stringify(detail);
+ }
+ let reply = new window.CustomEvent("WebChannelMessageToChrome", {
+ detail: detail
+ });
+ window.dispatchEvent(reply);
+ }
+ }, true);
+
+ </script>
+ </body>
+</html>