OLD | NEW |
(Empty) | |
| 1 const Host = { |
| 2 SAME_ORIGIN: "same-origin", |
| 3 CROSS_ORIGIN: "cross-origin", |
| 4 }; |
| 5 |
| 6 const Protocol = { |
| 7 INSECURE: "insecure", |
| 8 SECURE: "secure", |
| 9 }; |
| 10 |
| 11 const ResourceType = { |
| 12 IMAGE: "image", |
| 13 FRAME: "frame", |
| 14 }; |
| 15 |
| 16 // These tests rely on some unintuitive cleverness due to Blink's test setup: |
| 17 // 'Upgrade-Insecure-Requests' does not upgrade the port number, so we use URLs |
| 18 // in the form `http://[domain]:8443`. If the upgrade fails, the load will fail, |
| 19 // as we don't serve HTTP over port 8443. |
| 20 function generateURL(host, protocol, resourceType) { |
| 21 var url = new URL("http://127.0.0.1:8443/security/resources/"); |
| 22 url.protocol = protocol == Protocol.INSECURE ? "http" : "https"; |
| 23 url.hostname = host == Host.SAME_ORIGIN ? "127.0.0.1" : "example.test"; |
| 24 if (resourceType == ResourceType.IMAGE) |
| 25 url.pathname += "abe.png"; |
| 26 else if (resourceType == ResourceType.FRAME) |
| 27 url.pathname += "post-origin-to-parent.html"; |
| 28 return { |
| 29 name: protocol + "/" + host + " " + resourceType, |
| 30 url: url.toString() |
| 31 }; |
| 32 } |
| 33 |
| 34 function generateRedirect(host, protocol, target) { |
| 35 var url = "http://127.0.0.1:8443/security/resources/redir.php?url=" + encodeUR
IComponent(target.url); |
| 36 url.protocol = protocol == Protocol.INSECURE ? "http" : "https"; |
| 37 url.hostname = host == Host.SAME_ORIGIN ? "127.0.0.1" : "example.test"; |
| 38 return { |
| 39 name: protocol + "/" + host + " => " + target.name, |
| 40 url: url.toString() |
| 41 }; |
| 42 } |
| 43 |
| 44 function assert_image_loads(test, url, height, width) { |
| 45 var i = document.createElement('img'); |
| 46 i.onload = test.step_func_done(_ => { |
| 47 assert_equals(i.naturalHeight, height, "Height."); |
| 48 assert_equals(i.naturalWidth, width, "Width."); |
| 49 }); |
| 50 i.onerror = test.unreached_func(url + " should load successfully."); |
| 51 i.src = url; |
| 52 } |
| 53 |
| 54 function assert_image_loads_in_srcdoc(test, url, height, width) { |
| 55 var frame = document.createElement('iframe'); |
| 56 frame.srcdoc = "yay!"; |
| 57 frame.onload = _ => { |
| 58 var i = frame.contentDocument.createElement('img'); |
| 59 i.onload = test.step_func_done(_ => { |
| 60 assert_equals(i.naturalHeight, height, "Height."); |
| 61 assert_equals(i.naturalWidth, width, "Width."); |
| 62 }); |
| 63 i.onerror = test.unreached_func(url + " should load successfully."); |
| 64 i.src = url; |
| 65 }; |
| 66 |
| 67 document.body.appendChild(frame); |
| 68 } |
| 69 |
| 70 function assert_image_loads_in_blank(test, url, height, width) { |
| 71 var frame = document.createElement('iframe'); |
| 72 frame.onload = _ => { |
| 73 var i = frame.contentDocument.createElement('img'); |
| 74 i.onload = test.step_func_done(_ => { |
| 75 assert_equals(i.naturalHeight, height, "Height."); |
| 76 assert_equals(i.naturalWidth, width, "Width."); |
| 77 }); |
| 78 i.onerror = test.unreached_func(url + " should load successfully."); |
| 79 i.src = url; |
| 80 }; |
| 81 |
| 82 document.body.appendChild(frame); |
| 83 } |
| 84 |
| 85 function assert_frame_loads(test, url) { |
| 86 var i = document.createElement('iframe'); |
| 87 |
| 88 window.addEventListener('message', test.step_func(e => { |
| 89 if (e.source == i.contentWindow) { |
| 90 test.done(); |
| 91 } |
| 92 })); |
| 93 |
| 94 i.src = url; |
| 95 document.body.appendChild(i); |
| 96 } |
OLD | NEW |