Skip to content

Commit

Permalink
Cleaner same and cross origin hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
yoavweiss committed Mar 29, 2019
1 parent 8274e5f commit 88a7ad4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
5 changes: 5 additions & 0 deletions common/get-host-info.sub.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ function get_host_info() {
var HTTP_PORT = '{{ports[http][0]}}';
var HTTP_PORT2 = '{{ports[http][1]}}';
var HTTPS_PORT = '{{ports[https][0]}}';
var PROTOCOL = window.location.protocol;
var IS_HTTPS = (PROTOCOL == "https:");
var HTTP_PORT_ELIDED = HTTP_PORT == "80" ? "" : (":" + HTTP_PORT);
var HTTP_PORT2_ELIDED = HTTP_PORT2 == "80" ? "" : (":" + HTTP_PORT2);
var HTTPS_PORT_ELIDED = HTTPS_PORT == "443" ? "" : (":" + HTTPS_PORT);
var PORT_ELIDED = IS_HTTPS ? HTTPS_PORT_ELIDED : HTTP_PORT_ELIDED;
var ORIGINAL_HOST = '{{host}}';
var REMOTE_HOST = (ORIGINAL_HOST === 'localhost') ? '127.0.0.1' : ('www1.' + ORIGINAL_HOST);
var OTHER_HOST = '{{domains[www2]}}';
Expand All @@ -18,10 +21,12 @@ function get_host_info() {
ORIGINAL_HOST: ORIGINAL_HOST,
REMOTE_HOST: REMOTE_HOST,

ORIGIN: PROTOCOL + "//" + ORIGINAL_HOST + PORT_ELIDED,
HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + HTTP_PORT_ELIDED,
HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + HTTPS_PORT_ELIDED,
HTTPS_ORIGIN_WITH_CREDS: 'https://foo:bar@' + ORIGINAL_HOST + HTTPS_PORT_ELIDED,
HTTP_ORIGIN_WITH_DIFFERENT_PORT: 'http://' + ORIGINAL_HOST + HTTP_PORT2_ELIDED,
REMOTE_ORIGIN: PROTOCOL + "//" + REMOTE_HOST + PORT_ELIDED,
HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + HTTP_PORT_ELIDED,
HTTP_NOTSAMESITE_ORIGIN: 'http://' + NOTSAMESITE_HOST + HTTP_PORT_ELIDED,
HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT: 'http://' + REMOTE_HOST + HTTP_PORT2_ELIDED,
Expand Down
11 changes: 6 additions & 5 deletions resource-timing/crossorigin-sandwich-TAO.sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
<link rel="help" href="http://www.w3.org/TR/resource-timing/#performanceresourcetiming"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="resources/webperftestharness.js"></script>
<script src="resources/webperftestharnessextension.js"></script>

<script>
setup({explicit_done: true});
test_namespace('getEntriesByName');
const pageOrigin = "{{host}}:{{ports[http][0]}}"
const crossOrigin = "{{domains[www]}}:{{ports[http][0]}}"
const pageOrigin = get_host_info()['ORIGIN'];
const crossOrigin = get_host_info()['REMOTE_ORIGIN'];

function onload_test()
{
Expand All @@ -35,10 +36,10 @@
<body>
<iframe id="frameContext" src="" style="width: 250px; height: 250px;"></iframe>
<script>
let destUrl = 'http://' + pageOrigin + '/resource-timing/resources/multi_redirect.py?';
destUrl += 'page_origin=' + 'http://' + pageOrigin;
let destUrl = pageOrigin + '/resource-timing/resources/multi_redirect.py?';
destUrl += 'page_origin=' + pageOrigin;
destUrl += '&timing_allow=1';
destUrl += '&cross_origin=' + 'http://' + crossOrigin;
destUrl += '&cross_origin=' + crossOrigin;
const frameContext = document.getElementById('frameContext');
frameContext.onload = onload_test;
frameContext.src = destUrl;
Expand Down
11 changes: 6 additions & 5 deletions resource-timing/crossorigin-sandwich-no-TAO.sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
<link rel="help" href="http://www.w3.org/TR/resource-timing/#performanceresourcetiming"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="resources/webperftestharness.js"></script>
<script src="resources/webperftestharnessextension.js"></script>

<script>
setup({explicit_done: true});
test_namespace('getEntriesByName');
const pageOrigin = "{{host}}:{{ports[http][0]}}"
const crossOrigin = "{{domains[www]}}:{{ports[http][0]}}"
const pageOrigin = get_host_info()['ORIGIN'];
const crossOrigin = get_host_info()['REMOTE_ORIGIN'];

function onload_test()
{
Expand All @@ -35,9 +36,9 @@
<body>
<iframe id="frameContext" src="" style="width: 250px; height: 250px;"></iframe>
<script>
let destUrl = 'http://' + pageOrigin + '/resource-timing/resources/multi_redirect.py?';
destUrl += 'page_origin=' + 'http://' + pageOrigin;
destUrl += '&cross_origin=' + 'http://' + crossOrigin;
let destUrl = pageOrigin + '/resource-timing/resources/multi_redirect.py?';
destUrl += 'page_origin=' + pageOrigin;
destUrl += '&cross_origin=' + crossOrigin;
const frameContext = document.getElementById('frameContext');
frameContext.onload = onload_test;
frameContext.src = destUrl;
Expand Down

0 comments on commit 88a7ad4

Please sign in to comment.