Refactor sorted array mapping machinery in LocaleToScriptMapping.cpp for reuse elsewhere
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / html / browsers / origin / relaxing-the-same-origin-restriction / document_domain_setter_srcdoc.html
1 <!DOCTYPE html>
2 <script src="/resources/testharness.js"></script>
3 <script src="/resources/testharnessreport.js"></script>
4 <body>
5 <!-- SEKRITS! -->
6 <input id="sekrit" value="omg!">
7
8 <script>
9   function postMessageToFrame(frame, message) {
10     return new Promise(resolve => {
11       var c = new MessageChannel();
12       c.port1.onmessage = e => {
13         resolve({ data: e.data, frame: frame })
14       };
15       frame.contentWindow.postMessage(message, '*', [c.port2]);
16     });
17   }
18
19   function createFrame() {
20     return new Promise(resolve => {
21       var i = document.createElement('iframe');
22       i.srcdoc = `
23           <script>
24             window.addEventListener('message', e => {
25               if (e.data.domain !== undefined) {
26                 try {
27                   document.domain = e.data.domain;
28                   e.ports[0].postMessage('Done');
29                 } catch(error) {
30                   e.ports[0].postMessage(error.name);
31                 }
32               } else if (e.data == 'poke-at-parent') {
33                 try {
34                   var sekrit = window.parent.document.body.querySelector('#sekrit').value;
35                   e.ports[0].postMessage(sekrit);
36                 } catch(error) {
37                   e.ports[0].postMessage(error.name);
38                 }
39               }
40             });
41             window.parent.postMessage('Hi!', '*');
42           </scr` + `ipt>`;
43       window.addEventListener('message', m => {
44         if (m.source == i.contentWindow)
45           resolve(i);
46       });
47       document.body.appendChild(i);
48     });
49   }
50
51   promise_test(t => {
52     return createFrame()
53       .then(f => postMessageToFrame(f, 'poke-at-parent'))
54       .then(result => {
55         assert_equals(result.data, document.querySelector('#sekrit').value);
56         result.frame.remove();
57       });
58   }, "srcdoc can access with no 'document.domain' modification.");
59
60   promise_test(t => {
61     return createFrame()
62       .then(f => postMessageToFrame(f, { domain: window.location.hostname }))
63       .then(result => {
64         assert_equals(result.data, 'Done');
65         return postMessageToFrame(result.frame, 'poke-at-parent')
66           .then(result => {
67         assert_equals(result.data, document.querySelector('#sekrit').value);
68             result.frame.remove();
69           });
70       });
71   }, "srcdoc can access with valid 'document.domain'.");
72
73   promise_test(t => {
74     return createFrame()
75       .then(f => {
76         document.domain = window.location.hostname;
77         return postMessageToFrame(f, 'poke-at-parent');
78       })
79       .then(result => {
80         assert_equals(result.data, document.querySelector('#sekrit').value);
81         result.frame.remove();
82       });
83   }, "srcdoc can access when parent modifies 'document.domain'.");
84 </script>