Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / test / data / post_message.html
blobb56764d1c3c2b55a697d46278b74b6d82ec150e9
1 <html>
3 <head><title>Post message tests</title>
4 <script>
5 // Send a message to our opener, and it will reply.
6 function postToOpener(msg, origin) {
7 window.opener.postMessage(msg, origin);
8 return true;
11 // Send a message to our opener's opener.
12 function postToOpenerOfOpener(msg, origin) {
13 window.opener.opener.postMessage(msg, origin);
14 return true;
17 // Send a message to a window named "foo".
18 function postToFoo(msg) {
19 var w = window.open("", "foo");
20 w.postMessage(msg, "*");
21 return true;
24 function openPopup(url) {
25 popup = window.open(url);
28 function postToPopup(msg) {
29 popup.postMessage(msg, "*");
30 return true;
33 // Send a message to parent.
34 function postToParent(msg) {
35 parent.postMessage(msg, "*");
36 return true;
39 // Send a message to sibling.
40 function postToSibling(msg, sibling) {
41 parent.frames[sibling].postMessage(msg, "*");
42 return true;
45 // Send a message to a subframe of window named "foo".
46 function postToFooFrame(msg) {
47 var w = window.open("", "foo");
48 w.frames[0][0].postMessage(msg, "*");
49 return true;
52 function registerUnload() {
53 window.addEventListener('unload', function(e) {
54 postToParent("message-from-unload", "*");
55 });
58 // Listen to incoming messages.
59 var receivedMessages = 0;
60 var receivedMessagesWithPort = 0;
61 window.addEventListener("message", messageReceived, false);
62 function messageReceived(event) {
63 receivedMessages++;
64 if (event.data === "2-1-reply") {
65 event.source.postMessage("msg4", "*");
66 } else if (event.data === "subframe-msg") {
67 event.source.postMessage("subframe-msg-reply", "*");
68 } else if (event.data === "subframe-msg-reply") {
69 domAutomationController.setAutomationId(0);
70 domAutomationController.send("done-" + window.name);
72 if (event.ports && event.ports.length > 0) {
73 receivedMessagesWithPort++;
74 var port = event.ports[0];
75 port.start();
76 port.postMessage("msg-back-via-port");
77 // Change the title to generate a notification.
78 document.title = event.data.message;
79 } else {
80 document.title = event.data;
83 </script>
84 </head>
86 </html>