| Index: third_party/WebKit/LayoutTests/http/tests/security/upgrade-insecure-requests/resources/testharness-helper.js
|
| diff --git a/third_party/WebKit/LayoutTests/http/tests/security/upgrade-insecure-requests/resources/testharness-helper.js b/third_party/WebKit/LayoutTests/http/tests/security/upgrade-insecure-requests/resources/testharness-helper.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b71df95b539a9fed835fbea58714c5b6d686aef3
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/http/tests/security/upgrade-insecure-requests/resources/testharness-helper.js
|
| @@ -0,0 +1,96 @@
|
| +const Host = {
|
| + SAME_ORIGIN: "same-origin",
|
| + CROSS_ORIGIN: "cross-origin",
|
| +};
|
| +
|
| +const Protocol = {
|
| + INSECURE: "insecure",
|
| + SECURE: "secure",
|
| +};
|
| +
|
| +const ResourceType = {
|
| + IMAGE: "image",
|
| + FRAME: "frame",
|
| +};
|
| +
|
| +// These tests rely on some unintuitive cleverness due to Blink's test setup:
|
| +// 'Upgrade-Insecure-Requests' does not upgrade the port number, so we use URLs
|
| +// in the form `http://[domain]:8443`. If the upgrade fails, the load will fail,
|
| +// as we don't serve HTTP over port 8443.
|
| +function generateURL(host, protocol, resourceType) {
|
| + var url = new URL("http://127.0.0.1:8443/security/resources/");
|
| + url.protocol = protocol == Protocol.INSECURE ? "http" : "https";
|
| + url.hostname = host == Host.SAME_ORIGIN ? "127.0.0.1" : "example.test";
|
| + if (resourceType == ResourceType.IMAGE)
|
| + url.pathname += "abe.png";
|
| + else if (resourceType == ResourceType.FRAME)
|
| + url.pathname += "post-origin-to-parent.html";
|
| + return {
|
| + name: protocol + "/" + host + " " + resourceType,
|
| + url: url.toString()
|
| + };
|
| +}
|
| +
|
| +function generateRedirect(host, protocol, target) {
|
| + var url = "http://127.0.0.1:8443/security/resources/redir.php?url=" + encodeURIComponent(target.url);
|
| + url.protocol = protocol == Protocol.INSECURE ? "http" : "https";
|
| + url.hostname = host == Host.SAME_ORIGIN ? "127.0.0.1" : "example.test";
|
| + return {
|
| + name: protocol + "/" + host + " => " + target.name,
|
| + url: url.toString()
|
| + };
|
| +}
|
| +
|
| +function assert_image_loads(test, url, height, width) {
|
| + var i = document.createElement('img');
|
| + i.onload = test.step_func_done(_ => {
|
| + assert_equals(i.naturalHeight, height, "Height.");
|
| + assert_equals(i.naturalWidth, width, "Width.");
|
| + });
|
| + i.onerror = test.unreached_func(url + " should load successfully.");
|
| + i.src = url;
|
| +}
|
| +
|
| +function assert_image_loads_in_srcdoc(test, url, height, width) {
|
| + var frame = document.createElement('iframe');
|
| + frame.srcdoc = "yay!";
|
| + frame.onload = _ => {
|
| + var i = frame.contentDocument.createElement('img');
|
| + i.onload = test.step_func_done(_ => {
|
| + assert_equals(i.naturalHeight, height, "Height.");
|
| + assert_equals(i.naturalWidth, width, "Width.");
|
| + });
|
| + i.onerror = test.unreached_func(url + " should load successfully.");
|
| + i.src = url;
|
| + };
|
| +
|
| + document.body.appendChild(frame);
|
| +}
|
| +
|
| +function assert_image_loads_in_blank(test, url, height, width) {
|
| + var frame = document.createElement('iframe');
|
| + frame.onload = _ => {
|
| + var i = frame.contentDocument.createElement('img');
|
| + i.onload = test.step_func_done(_ => {
|
| + assert_equals(i.naturalHeight, height, "Height.");
|
| + assert_equals(i.naturalWidth, width, "Width.");
|
| + });
|
| + i.onerror = test.unreached_func(url + " should load successfully.");
|
| + i.src = url;
|
| + };
|
| +
|
| + document.body.appendChild(frame);
|
| +}
|
| +
|
| +function assert_frame_loads(test, url) {
|
| + var i = document.createElement('iframe');
|
| +
|
| + window.addEventListener('message', test.step_func(e => {
|
| + if (e.source == i.contentWindow) {
|
| + test.done();
|
| + }
|
| + }));
|
| +
|
| + i.src = url;
|
| + document.body.appendChild(i);
|
| +}
|
|
|