Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / test / data / post_message.html
blob11fdbefc7b640e82e3748dc43e99227e69f5ca7d
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 our parent's opener.
18 function postToOpenerOfParent(msg, origin) {
19 parent.opener.postMessage(msg, origin);
20 return true;
23 // Send a message to our parent's opener.
24 function postToOpenerOfSibling(siblingName, msg, origin) {
25 parent.frames[siblingName].opener.postMessage(msg, origin);
26 return true;
29 // Send a message to a window named "foo".
30 function postToFoo(msg) {
31 var w = window.open("", "foo");
32 w.postMessage(msg, "*");
33 return true;
36 function openPopup(url) {
37 popup = window.open(url);
40 function postToPopup(msg) {
41 popup.postMessage(msg, "*");
42 return true;
45 // Send a message to parent.
46 function postToParent(msg) {
47 parent.postMessage(msg, "*");
48 return true;
51 // Send a message to sibling.
52 function postToSibling(msg, sibling) {
53 parent.frames[sibling].postMessage(msg, "*");
54 return true;
57 // Send a message to a subframe of window named "foo".
58 function postToFooFrame(msg) {
59 var w = window.open("", "foo");
60 w.frames[0][0].postMessage(msg, "*");
61 return true;
64 function registerUnload() {
65 window.addEventListener('unload', function(e) {
66 postToParent("message-from-unload", "*");
67 });
70 // Listen to incoming messages.
71 var receivedMessages = 0;
72 var receivedMessagesWithPort = 0;
73 window.addEventListener("message", messageReceived, false);
74 function messageReceived(event) {
75 receivedMessages++;
76 if (event.data === "2-1-reply") {
77 event.source.postMessage("msg4", "*");
78 } else if (event.data === "subframe-msg") {
79 event.source.postMessage("subframe-msg-reply", "*");
80 } else if (event.data === "subframe-msg-reply") {
81 domAutomationController.setAutomationId(0);
82 domAutomationController.send("done-" + window.name);
84 if (event.ports && event.ports.length > 0) {
85 receivedMessagesWithPort++;
86 var port = event.ports[0];
87 port.start();
88 port.postMessage("msg-back-via-port");
89 // Change the title to generate a notification.
90 document.title = event.data.message;
91 } else {
92 document.title = event.data;
95 </script>
96 </head>
98 </html>