Sitelet https://web.archive.org/web/20220420055708/https://github.com/nodejs/node/commit/eb9d7a437e
Skip to content
Permalink
Browse files
test: update WPT harness and tests
PR-URL: #33770
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
  • Loading branch information
targos authored and nodejs-github-bot committed Sep 16, 2020
1 parent 9cf9e4a commit eb9d7a437e960753a7344d7e7885e6e3df4370aa
Showing with 9,646 additions and 1,775 deletions.
  1. +8 −7 test/fixtures/wpt/README.md
  2. +3 −0 test/fixtures/wpt/common/META.yml
  3. +116 −0 test/fixtures/wpt/common/PrefixedLocalStorage.js
  4. +1 −0 test/fixtures/wpt/common/PrefixedLocalStorage.js.headers
  5. +100 −0 test/fixtures/wpt/common/PrefixedPostMessage.js
  6. +1 −0 test/fixtures/wpt/common/PrefixedPostMessage.js.headers
  7. +10 −0 test/fixtures/wpt/common/README.md
  8. +31 −0 test/fixtures/wpt/common/arrays.js
  9. 0 test/fixtures/wpt/common/blank.html
  10. +8 −0 test/fixtures/wpt/common/domain-setter.sub.html
  11. +2 −0 test/fixtures/wpt/common/dummy.xhtml
  12. +1 −0 test/fixtures/wpt/common/dummy.xml
  13. +58 −0 test/fixtures/wpt/common/get-host-info.sub.js
  14. +1 −0 test/fixtures/wpt/common/get-host-info.sub.js.headers
  15. +55 −0 test/fixtures/wpt/common/media.js
  16. +1 −0 test/fixtures/wpt/common/media.js.headers
  17. +68 −0 test/fixtures/wpt/common/object-association.js
  18. +1 −0 test/fixtures/wpt/common/object-association.js.headers
  19. +56 −0 test/fixtures/wpt/common/performance-timeline-utils.js
  20. +1 −0 test/fixtures/wpt/common/performance-timeline-utils.js.headers
  21. +20 −0 test/fixtures/wpt/common/reftest-wait.js
  22. +1 −0 test/fixtures/wpt/common/reftest-wait.js.headers
  23. +19 −0 test/fixtures/wpt/common/rendering-utils.js
  24. +13 −0 test/fixtures/wpt/common/sab.js
  25. +460 −0 test/fixtures/wpt/common/security-features/README.md
  26. +1,281 −0 test/fixtures/wpt/common/security-features/resources/common.sub.js
  27. +1 −0 test/fixtures/wpt/common/security-features/resources/common.sub.js.headers
  28. +30 −0 test/fixtures/wpt/common/security-features/scope/template/document.html.template
  29. +29 −0 test/fixtures/wpt/common/security-features/scope/template/worker.js.template
  30. +16 −0 test/fixtures/wpt/common/security-features/subresource/template/document.html.template
  31. +9 −0 test/fixtures/wpt/common/security-features/subresource/template/font.css.template
  32. +3 −0 test/fixtures/wpt/common/security-features/subresource/template/image.css.template
  33. +3 −0 test/fixtures/wpt/common/security-features/subresource/template/script.js.template
  34. +5 −0 test/fixtures/wpt/common/security-features/subresource/template/shared-worker.js.template
  35. +1 −0 test/fixtures/wpt/common/security-features/subresource/template/static-import.js.template
  36. +3 −0 test/fixtures/wpt/common/security-features/subresource/template/svg.css.template
  37. +5 −0 test/fixtures/wpt/common/security-features/subresource/template/svg.embedded.template
  38. +3 −0 test/fixtures/wpt/common/security-features/subresource/template/worker.js.template
  39. +546 −0 test/fixtures/wpt/common/security-features/tools/spec.src.json
  40. +1 −0 test/fixtures/wpt/common/security-features/tools/template/disclaimer.template
  41. +1 −0 test/fixtures/wpt/common/security-features/tools/template/spec_json.js.template
  42. +26 −0 test/fixtures/wpt/common/security-features/tools/template/test.debug.html.template
  43. +22 −0 test/fixtures/wpt/common/security-features/tools/template/test.release.html.template
  44. +62 −0 test/fixtures/wpt/common/security-features/types.md
  45. BIN test/fixtures/wpt/common/square.png
  46. +57 −0 test/fixtures/wpt/common/stringifiers.js
  47. +1 −0 test/fixtures/wpt/common/stringifiers.js.headers
  48. +83 −0 test/fixtures/wpt/common/subset-tests-by-key.js
  49. +60 −0 test/fixtures/wpt/common/subset-tests.js
  50. +67 −0 test/fixtures/wpt/common/test-setting-immutable-prototype.js
  51. +1 −0 test/fixtures/wpt/common/test-setting-immutable-prototype.js.headers
  52. +4 −0 test/fixtures/wpt/common/text-plain.txt
  53. +98 −0 test/fixtures/wpt/common/utils.js
  54. +1 −0 test/fixtures/wpt/common/utils.js.headers
  55. +50 −0 test/fixtures/wpt/common/worklet-reftest.js
  56. +1 −0 test/fixtures/wpt/common/worklet-reftest.js.headers
  57. +1 −1 test/fixtures/wpt/console/console-label-conversion.any.js
  58. +40 −0 test/fixtures/wpt/console/console-namespace-object-class-string.any.js
  59. +7 −2 test/fixtures/wpt/encoding/api-invalid-label.any.js
  60. +2 −1 test/fixtures/wpt/encoding/api-replacement-encodings.any.js
  61. +17 −0 test/fixtures/wpt/encoding/bom-handling.html
  62. +1 −0 test/fixtures/wpt/encoding/bom-handling.html.headers
  63. +49 −40 test/fixtures/wpt/encoding/encodeInto.any.js
  64. +1 −0 test/fixtures/wpt/encoding/legacy-mb-japanese/euc-jp/eucjp-decode-cseucpkdfmtjapanese.html
  65. +1 −0 test/fixtures/wpt/encoding/legacy-mb-japanese/euc-jp/eucjp-decode-errors.html
  66. +1 −0 test/fixtures/wpt/encoding/legacy-mb-japanese/euc-jp/eucjp-decode-x-euc-jp.html
  67. +1 −0 test/fixtures/wpt/encoding/legacy-mb-japanese/euc-jp/eucjp-decode.html
  68. +1 −0 test/fixtures/wpt/encoding/legacy-mb-japanese/iso-2022-jp/iso2022jp-decode-errors.html
  69. +1 −0 test/fixtures/wpt/encoding/legacy-mb-japanese/shift_jis/sjis-encode-href.html
  70. +18 −0 test/fixtures/wpt/encoding/legacy-mb-korean/euc-kr/euckr-decode-ksc_5601.html
  71. +1 −0 test/fixtures/wpt/encoding/legacy-mb-korean/euc-kr/euckr-encode-form-windows-949.html
  72. +1 −0 test/fixtures/wpt/encoding/legacy-mb-tchinese/big5/big5-encode-form-cn-big5.html
  73. +1 −0 test/fixtures/wpt/encoding/legacy-mb-tchinese/big5/big5-encode-href-errors-han.html
  74. +1 −0 test/fixtures/wpt/encoding/legacy-mb-tchinese/big5/big5-encode-href-errors-hangul.html
  75. +11 −5 test/fixtures/wpt/encoding/resources/encodings.js
  76. +7 −7 test/fixtures/wpt/encoding/streams/backpressure.any.js
  77. +12 −12 test/fixtures/wpt/encoding/streams/decode-attributes.any.js
  78. +3 −17 test/fixtures/wpt/encoding/streams/decode-bad-chunks.any.js
  79. +1 −1 test/fixtures/wpt/encoding/streams/decode-ignore-bom.any.js
  80. +2 −2 test/fixtures/wpt/encoding/streams/decode-incomplete-input.any.js
  81. +3 −3 test/fixtures/wpt/encoding/streams/decode-non-utf8.any.js
  82. +1 −1 test/fixtures/wpt/encoding/streams/decode-split-character.any.js
  83. +39 −33 test/fixtures/wpt/encoding/streams/decode-utf8.any.js
  84. +5 −5 test/fixtures/wpt/encoding/streams/encode-bad-chunks.any.js
  85. +1 −1 test/fixtures/wpt/encoding/streams/encode-utf8.any.js
  86. +1 −1 test/fixtures/wpt/encoding/streams/readable-writable-properties.any.js
  87. +37 −80 test/fixtures/wpt/encoding/streams/realms.window.js
  88. +20 −15 test/fixtures/wpt/encoding/textdecoder-copy.any.js
  89. +12 −3 test/fixtures/wpt/encoding/textdecoder-fatal-single-byte.any.js
  90. +3 −3 test/fixtures/wpt/encoding/textdecoder-fatal-streaming.any.js
  91. +4 −4 test/fixtures/wpt/encoding/textdecoder-fatal.any.js
  92. +12 −0 test/fixtures/wpt/encoding/textdecoder-ignorebom.any.js
  93. +23 −17 test/fixtures/wpt/encoding/textdecoder-streaming.any.js
  94. +1 −1 test/fixtures/wpt/encoding/textdecoder-utf16-surrogates.any.js
  95. +6 −6 test/fixtures/wpt/html/webappapis/microtask-queuing/queue-microtask.any.js
  96. +29 −0 test/fixtures/wpt/html/webappapis/timers/cleartimeout-clearinterval.any.js
  97. +1 −0 test/fixtures/wpt/html/webappapis/timers/negative-setinterval.html
  98. +1 −0 test/fixtures/wpt/html/webappapis/timers/negative-settimeout.html
  99. +1 −0 test/fixtures/wpt/html/webappapis/timers/type-long-setinterval.html
  100. +1 −0 test/fixtures/wpt/html/webappapis/timers/type-long-settimeout.html
  101. +21 −21 test/fixtures/wpt/interfaces/console.idl
  102. +47 −47 test/fixtures/wpt/interfaces/dom.idl
  103. +2 −2 test/fixtures/wpt/interfaces/encoding.idl
  104. +2 −2 test/fixtures/wpt/interfaces/hr-time.idl
  105. +273 −194 test/fixtures/wpt/interfaces/html.idl
  106. +6 −6 test/fixtures/wpt/interfaces/url.idl
  107. +0 −1 test/fixtures/wpt/resources/META.yml
  108. +47 −1 test/fixtures/wpt/resources/check-layout-th.js
  109. +495 −179 test/fixtures/wpt/resources/idlharness.js
  110. +5 −17 test/fixtures/wpt/resources/readme.md
  111. +108 −0 test/fixtures/wpt/resources/sriharness.js
  112. +84 −0 test/fixtures/wpt/resources/test-only-api.js
  113. +2 −0 test/fixtures/wpt/resources/test-only-api.js.headers
  114. +33 −11 test/fixtures/wpt/resources/testdriver-actions.js
  115. +300 −4 test/fixtures/wpt/resources/testdriver.js
  116. +624 −118 test/fixtures/wpt/resources/testharness.js
  117. +3,126 −873 test/fixtures/wpt/resources/webidl2/lib/webidl2.js
  118. +6 −6 test/fixtures/wpt/url/failure.html
  119. +1 −1 test/fixtures/wpt/url/historical.any.js
  120. +36 −7 test/fixtures/wpt/url/resources/setters_tests.json
  121. +22 −0 test/fixtures/wpt/url/resources/toascii.json
  122. +305 −2 test/fixtures/wpt/url/resources/urltestdata.json
  123. +1 −1 test/fixtures/wpt/url/toascii.window.js
  124. +1 −1 test/fixtures/wpt/url/url-constructor.html
  125. +1 −1 test/fixtures/wpt/url/url-searchparams.any.js
  126. +125 −0 test/fixtures/wpt/url/url-setters-stripping.any.js
  127. +5 −1 test/fixtures/wpt/url/urlencoded-parser.any.js
  128. +42 −3 test/fixtures/wpt/url/urlsearchparams-constructor.any.js
  129. +12 −0 test/fixtures/wpt/url/urlsearchparams-stringifier.any.js
  130. +11 −7 test/fixtures/wpt/versions.json
  131. +4 −1 test/wpt/status/console.json
  132. +3 −0 test/wpt/status/encoding.json
  133. +9 −0 test/wpt/status/url.json
@@ -10,14 +10,15 @@ See [test/wpt](../../wpt/README.md) for information on how these tests are run.

Last update:

- console: https://github.com/web-platform-tests/wpt/tree/9786a4b131/console
- encoding: https://github.com/web-platform-tests/wpt/tree/5059d2c777/encoding
- url: https://github.com/web-platform-tests/wpt/tree/43feb7f612/url
- resources: https://github.com/web-platform-tests/wpt/tree/e1fddfbf80/resources
- interfaces: https://github.com/web-platform-tests/wpt/tree/8ada332aea/interfaces
- html/webappapis/microtask-queuing: https://github.com/web-platform-tests/wpt/tree/0c3bed38df/html/webappapis/microtask-queuing
- html/webappapis/timers: https://github.com/web-platform-tests/wpt/tree/ddfe9c089b/html/webappapis/timers
- console: https://github.com/web-platform-tests/wpt/tree/3b1f72e99a/console
- encoding: https://github.com/web-platform-tests/wpt/tree/11e6941923/encoding
- url: https://github.com/web-platform-tests/wpt/tree/551c9d604f/url
- resources: https://github.com/web-platform-tests/wpt/tree/55e9dc7f5e/resources
- interfaces: https://github.com/web-platform-tests/wpt/tree/4471cda31b/interfaces
- html/webappapis/microtask-queuing: https://github.com/web-platform-tests/wpt/tree/2c5c3c4c27/html/webappapis/microtask-queuing
- html/webappapis/timers: https://github.com/web-platform-tests/wpt/tree/264f12bc7b/html/webappapis/timers
- hr-time: https://github.com/web-platform-tests/wpt/tree/a5d1774ecf/hr-time
- common: https://github.com/web-platform-tests/wpt/tree/4dacb6e2ff/common

[Web Platform Tests]: https://github.com/web-platform-tests/wpt
[`git node wpt`]: https://github.com/nodejs/node-core-utils/blob/master/docs/git-node.md#git-node-wpt
@@ -0,0 +1,3 @@
suggested_reviewers:
- zqzhang
- deniak
@@ -0,0 +1,116 @@
/**
* Supports pseudo-"namespacing" localStorage for a given test
* by generating and using a unique prefix for keys. Why trounce on other
* tests' localStorage items when you can keep it "separated"?
*
* PrefixedLocalStorageTest: Instantiate in testharness.js tests to generate
* a new unique-ish prefix
* PrefixedLocalStorageResource: Instantiate in supporting test resource
* files to use/share a prefix generated by a test.
*/
var PrefixedLocalStorage = function () {
this.prefix = ''; // Prefix for localStorage keys
this.param = 'prefixedLocalStorage'; // Param to use in querystrings
};

PrefixedLocalStorage.prototype.clear = function () {
if (this.prefix === '') { return; }
Object.keys(localStorage).forEach(sKey => {
if (sKey.indexOf(this.prefix) === 0) {
localStorage.removeItem(sKey);
}
});
};

/**
* Append/replace prefix parameter and value in URI querystring
* Use to generate URLs to resource files that will share the prefix.
*/
PrefixedLocalStorage.prototype.url = function (uri) {
function updateUrlParameter (uri, key, value) {
var i = uri.indexOf('#');
var hash = (i === -1) ? '' : uri.substr(i);
uri = (i === -1) ? uri : uri.substr(0, i);
var re = new RegExp(`([?&])${key}=.*?(&|$)`, 'i');
var separator = uri.indexOf('?') !== -1 ? '&' : '?';
uri = (uri.match(re)) ? uri.replace(re, `$1${key}=${value}$2`) :
`${uri}${separator}${key}=${value}`;
return uri + hash;
}
return updateUrlParameter(uri, this.param, this.prefix);
};

PrefixedLocalStorage.prototype.prefixedKey = function (baseKey) {
return `${this.prefix}${baseKey}`;
};

PrefixedLocalStorage.prototype.setItem = function (baseKey, value) {
localStorage.setItem(this.prefixedKey(baseKey), value);
};

/**
* Listen for `storage` events pertaining to a particular key,
* prefixed with this object's prefix. Ignore when value is being set to null
* (i.e. removeItem).
*/
PrefixedLocalStorage.prototype.onSet = function (baseKey, fn) {
window.addEventListener('storage', e => {
var match = this.prefixedKey(baseKey);
if (e.newValue !== null && e.key.indexOf(match) === 0) {
fn.call(this, e);
}
});
};

/*****************************************************************************
* Use in a testharnessjs test to generate a new key prefix.
* async_test(t => {
* var prefixedStorage = new PrefixedLocalStorageTest();
* t.add_cleanup(() => prefixedStorage.cleanup());
* /...
* });
*/
var PrefixedLocalStorageTest = function () {
PrefixedLocalStorage.call(this);
this.prefix = `${document.location.pathname}-${Math.random()}-${Date.now()}-`;
};
PrefixedLocalStorageTest.prototype = Object.create(PrefixedLocalStorage.prototype);
PrefixedLocalStorageTest.prototype.constructor = PrefixedLocalStorageTest;

/**
* Use in a cleanup function to clear out prefixed entries in localStorage
*/
PrefixedLocalStorageTest.prototype.cleanup = function () {
this.setItem('closeAll', 'true');
this.clear();
};

/*****************************************************************************
* Use in test resource files to share a prefix generated by a
* PrefixedLocalStorageTest. Will look in URL querystring for prefix.
* Setting `close_on_cleanup` opt truthy will make this script's window listen
* for storage `closeAll` event from controlling test and close itself.
*
* var PrefixedLocalStorageResource({ close_on_cleanup: true });
*/
var PrefixedLocalStorageResource = function (options) {
PrefixedLocalStorage.call(this);
this.options = Object.assign({}, {
close_on_cleanup: false
}, options || {});
// Check URL querystring for prefix to use
var regex = new RegExp(`[?&]${this.param}(=([^&#]*)|&|#|$)`),
results = regex.exec(document.location.href);
if (results && results[2]) {
this.prefix = results[2];
}
// Optionally have this window close itself when the PrefixedLocalStorageTest
// sets a `closeAll` item.
if (this.options.close_on_cleanup) {
this.onSet('closeAll', () => {
window.close();
});
}
};
PrefixedLocalStorageResource.prototype = Object.create(PrefixedLocalStorage.prototype);
PrefixedLocalStorageResource.prototype.constructor = PrefixedLocalStorageResource;
@@ -0,0 +1 @@
Content-Type: text/javascript; charset=utf-8
@@ -0,0 +1,100 @@
/**
* Supports pseudo-"namespacing" for window-posted messages for a given test
* by generating and using a unique prefix that gets wrapped into message
* objects. This makes it more feasible to have multiple tests that use
* `window.postMessage` in a single test file. Basically, make it possible
* for the each test to listen for only the messages that are pertinent to it.
*
* 'Prefix' not an elegant term to use here but this models itself after
* PrefixedLocalStorage.
*
* PrefixedMessageTest: Instantiate in testharness.js tests to generate
* a new unique-ish prefix that can be used by other test support files
* PrefixedMessageResource: Instantiate in supporting test resource
* files to use/share a prefix generated by a test.
*/
var PrefixedMessage = function () {
this.prefix = '';
this.param = 'prefixedMessage'; // Param to use in querystrings
};

/**
* Generate a URL that adds/replaces param with this object's prefix
* Use to link to test support files that make use of
* PrefixedMessageResource.
*/
PrefixedMessage.prototype.url = function (uri) {
function updateUrlParameter (uri, key, value) {
var i = uri.indexOf('#');
var hash = (i === -1) ? '' : uri.substr(i);
uri = (i === -1) ? uri : uri.substr(0, i);
var re = new RegExp(`([?&])${key}=.*?(&|$)`, 'i');
var separator = uri.indexOf('?') !== -1 ? '&' : '?';
uri = (uri.match(re)) ? uri.replace(re, `$1${key}=${value}$2`) :
`${uri}${separator}${key}=${value}`;
return uri + hash;
}
return updateUrlParameter(uri, this.param, this.prefix);
};

/**
* Add an eventListener on `message` but only invoke the given callback
* for messages whose object contains this object's prefix. Remove the
* event listener once the anticipated message has been received.
*/
PrefixedMessage.prototype.onMessage = function (fn) {
window.addEventListener('message', e => {
if (typeof e.data === 'object' && e.data.hasOwnProperty('prefix')) {
if (e.data.prefix === this.prefix) {
// Only invoke callback when `data` is an object containing
// a `prefix` key with this object's prefix value
// Note fn is invoked with "unwrapped" data first, then the event `e`
// (which contains the full, wrapped e.data should it be needed)
fn.call(this, e.data.data, e);
window.removeEventListener('message', fn);
}
}
});
};

/**
* Instantiate in a test file (e.g. during `setup`) to create a unique-ish
* prefix that can be shared by support files
*/
var PrefixedMessageTest = function () {
PrefixedMessage.call(this);
this.prefix = `${document.location.pathname}-${Math.random()}-${Date.now()}-`;
};
PrefixedMessageTest.prototype = Object.create(PrefixedMessage.prototype);
PrefixedMessageTest.prototype.constructor = PrefixedMessageTest;

/**
* Instantiate in a test support script to use a "prefix" generated by a
* PrefixedMessageTest in a controlling test file. It will look for
* the prefix in a URL param (see also PrefixedMessage#url)
*/
var PrefixedMessageResource = function () {
PrefixedMessage.call(this);
// Check URL querystring for prefix to use
var regex = new RegExp(`[?&]${this.param}(=([^&#]*)|&|#|$)`),
results = regex.exec(document.location.href);
if (results && results[2]) {
this.prefix = results[2];
}
};
PrefixedMessageResource.prototype = Object.create(PrefixedMessage.prototype);
PrefixedMessageResource.prototype.constructor = PrefixedMessageResource;

/**
* This is how a test resource document can "send info" to its
* opener context. It will whatever message is being sent (`data`) in
* an object that injects the prefix.
*/
PrefixedMessageResource.prototype.postToOpener = function (data) {
if (window.opener) {
window.opener.postMessage({
prefix: this.prefix,
data: data
}, '*');
}
};
@@ -0,0 +1 @@
Content-Type: text/javascript; charset=utf-8
@@ -0,0 +1,10 @@
The files in this directory are non-infrastructure support files that can be used by tests.

* `blank.html` - An empty HTML document.
* `domain-setter.sub.html` - An HTML document that sets `document.domain`.
* `dummy.xhtml` - An XHTML document.
* `dummy.xml` - An XML document.
* `text-plain.txt` - A text/plain document.
* `*.js` - Utility scripts. These are documented in the source.
* `*.py` - wptserve [Python Handlers](https://web-platform-tests.org/writing-tests/python-handlers/). These are documented in the source.
* `security-features` - Documented in `security-features/README.md`.
@@ -0,0 +1,31 @@
/**
* Callback for checking equality of c and d.
*
* @callback equalityCallback
* @param {*} c
* @param {*} d
* @returns {boolean}
*/

/**
* Returns true if the given arrays are equal. Optionally can pass an equality function.
* @param {Array} a
* @param {Array} b
* @param {equalityCallback} callbackFunction - defaults to `c === d`
* @returns {boolean}
*/
export function areArraysEqual(a, b, equalityFunction = (c, d) => { return c === d; }) {
try {
if (a.length !== b.length)
return false;

for (let i = 0; i < a.length; i++) {
if (!equalityFunction(a[i], b[i]))
return false;
}
} catch (ex) {
return false;
}

return true;
}
Empty file.
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>A page that will likely be same-origin-domain but not same-origin</title>

<script>
"use strict";
document.domain = "{{host}}";
</script>
@@ -0,0 +1,2 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Dummy XHTML document</title></head><body /></html>
@@ -0,0 +1 @@
<foo>Dummy XML document</foo>
@@ -0,0 +1,58 @@
/**
* Host information for cross-origin tests.
* @returns {Object} with properties for different host information.
*/
function get_host_info() {

var HTTP_PORT = '{{ports[http][0]}}';
var HTTP_PORT2 = '{{ports[http][1]}}';
var HTTPS_PORT = '{{ports[https][0]}}';
var HTTPS_PORT2 = '{{ports[https][1]}}';
var PROTOCOL = self.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]}}';
var NOTSAMESITE_HOST = (ORIGINAL_HOST === 'localhost') ? '127.0.0.1' : ('{{hosts[alt][]}}');

return {
HTTP_PORT: HTTP_PORT,
HTTP_PORT2: HTTP_PORT2,
HTTPS_PORT: HTTPS_PORT,
HTTPS_PORT2: HTTPS_PORT2,
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,
HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + HTTPS_PORT_ELIDED,
HTTPS_REMOTE_ORIGIN_WITH_CREDS: 'https://foo:bar@' + REMOTE_HOST + HTTPS_PORT_ELIDED,
HTTPS_NOTSAMESITE_ORIGIN: 'https://' + NOTSAMESITE_HOST + HTTPS_PORT_ELIDED,
UNAUTHENTICATED_ORIGIN: 'http://' + OTHER_HOST + HTTP_PORT_ELIDED,
AUTHENTICATED_ORIGIN: 'https://' + OTHER_HOST + HTTPS_PORT_ELIDED
};
}

/**
* When a default port is used, location.port returns the empty string.
* This function attempts to provide an exact port, assuming we are running under wptserve.
* @param {*} loc - can be Location/<a>/<area>/URL, but assumes http/https only.
* @returns {string} The port number.
*/
function get_port(loc) {
if (loc.port) {
return loc.port;
}
return loc.protocol === 'https:' ? '443' : '80';
}
@@ -0,0 +1 @@
Content-Type: text/javascript; charset=utf-8

0 comments on commit eb9d7a4

Please sign in to comment.