Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit eb9d7a4

Browse filesBrowse files
targosnodejs-github-bot
authored andcommitted
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>
1 parent 9cf9e4a commit eb9d7a4
Copy full SHA for eb9d7a4

File tree

Expand file treeCollapse file tree

133 files changed

+9646
-1775
lines changed
Open diff view settings
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

133 files changed

+9646
-1775
lines changed
Open diff view settings
Collapse file

‎test/fixtures/wpt/README.md‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/README.md
+8-7Lines changed: 8 additions & 7 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ See [test/wpt](../../wpt/README.md) for information on how these tests are run.
1010

1111
Last update:
1212

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

2223
[Web Platform Tests]: https://github.com/web-platform-tests/wpt
2324
[`git node wpt`]: https://github.com/nodejs/node-core-utils/blob/master/docs/git-node.md#git-node-wpt
Collapse file

‎test/fixtures/wpt/common/META.yml‎

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
suggested_reviewers:
2+
- zqzhang
3+
- deniak
Collapse file
+116Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/**
2+
* Supports pseudo-"namespacing" localStorage for a given test
3+
* by generating and using a unique prefix for keys. Why trounce on other
4+
* tests' localStorage items when you can keep it "separated"?
5+
*
6+
* PrefixedLocalStorageTest: Instantiate in testharness.js tests to generate
7+
* a new unique-ish prefix
8+
* PrefixedLocalStorageResource: Instantiate in supporting test resource
9+
* files to use/share a prefix generated by a test.
10+
*/
11+
var PrefixedLocalStorage = function () {
12+
this.prefix = ''; // Prefix for localStorage keys
13+
this.param = 'prefixedLocalStorage'; // Param to use in querystrings
14+
};
15+
16+
PrefixedLocalStorage.prototype.clear = function () {
17+
if (this.prefix === '') { return; }
18+
Object.keys(localStorage).forEach(sKey => {
19+
if (sKey.indexOf(this.prefix) === 0) {
20+
localStorage.removeItem(sKey);
21+
}
22+
});
23+
};
24+
25+
/**
26+
* Append/replace prefix parameter and value in URI querystring
27+
* Use to generate URLs to resource files that will share the prefix.
28+
*/
29+
PrefixedLocalStorage.prototype.url = function (uri) {
30+
function updateUrlParameter (uri, key, value) {
31+
var i = uri.indexOf('#');
32+
var hash = (i === -1) ? '' : uri.substr(i);
33+
uri = (i === -1) ? uri : uri.substr(0, i);
34+
var re = new RegExp(`([?&])${key}=.*?(&|$)`, 'i');
35+
var separator = uri.indexOf('?') !== -1 ? '&' : '?';
36+
uri = (uri.match(re)) ? uri.replace(re, `$1${key}=${value}$2`) :
37+
`${uri}${separator}${key}=${value}`;
38+
return uri + hash;
39+
}
40+
return updateUrlParameter(uri, this.param, this.prefix);
41+
};
42+
43+
PrefixedLocalStorage.prototype.prefixedKey = function (baseKey) {
44+
return `${this.prefix}${baseKey}`;
45+
};
46+
47+
PrefixedLocalStorage.prototype.setItem = function (baseKey, value) {
48+
localStorage.setItem(this.prefixedKey(baseKey), value);
49+
};
50+
51+
/**
52+
* Listen for `storage` events pertaining to a particular key,
53+
* prefixed with this object's prefix. Ignore when value is being set to null
54+
* (i.e. removeItem).
55+
*/
56+
PrefixedLocalStorage.prototype.onSet = function (baseKey, fn) {
57+
window.addEventListener('storage', e => {
58+
var match = this.prefixedKey(baseKey);
59+
if (e.newValue !== null && e.key.indexOf(match) === 0) {
60+
fn.call(this, e);
61+
}
62+
});
63+
};
64+
65+
/*****************************************************************************
66+
* Use in a testharnessjs test to generate a new key prefix.
67+
* async_test(t => {
68+
* var prefixedStorage = new PrefixedLocalStorageTest();
69+
* t.add_cleanup(() => prefixedStorage.cleanup());
70+
* /...
71+
* });
72+
*/
73+
var PrefixedLocalStorageTest = function () {
74+
PrefixedLocalStorage.call(this);
75+
this.prefix = `${document.location.pathname}-${Math.random()}-${Date.now()}-`;
76+
};
77+
PrefixedLocalStorageTest.prototype = Object.create(PrefixedLocalStorage.prototype);
78+
PrefixedLocalStorageTest.prototype.constructor = PrefixedLocalStorageTest;
79+
80+
/**
81+
* Use in a cleanup function to clear out prefixed entries in localStorage
82+
*/
83+
PrefixedLocalStorageTest.prototype.cleanup = function () {
84+
this.setItem('closeAll', 'true');
85+
this.clear();
86+
};
87+
88+
/*****************************************************************************
89+
* Use in test resource files to share a prefix generated by a
90+
* PrefixedLocalStorageTest. Will look in URL querystring for prefix.
91+
* Setting `close_on_cleanup` opt truthy will make this script's window listen
92+
* for storage `closeAll` event from controlling test and close itself.
93+
*
94+
* var PrefixedLocalStorageResource({ close_on_cleanup: true });
95+
*/
96+
var PrefixedLocalStorageResource = function (options) {
97+
PrefixedLocalStorage.call(this);
98+
this.options = Object.assign({}, {
99+
close_on_cleanup: false
100+
}, options || {});
101+
// Check URL querystring for prefix to use
102+
var regex = new RegExp(`[?&]${this.param}(=([^&#]*)|&|#|$)`),
103+
results = regex.exec(document.location.href);
104+
if (results && results[2]) {
105+
this.prefix = results[2];
106+
}
107+
// Optionally have this window close itself when the PrefixedLocalStorageTest
108+
// sets a `closeAll` item.
109+
if (this.options.close_on_cleanup) {
110+
this.onSet('closeAll', () => {
111+
window.close();
112+
});
113+
}
114+
};
115+
PrefixedLocalStorageResource.prototype = Object.create(PrefixedLocalStorage.prototype);
116+
PrefixedLocalStorageResource.prototype.constructor = PrefixedLocalStorageResource;
Collapse file
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Content-Type: text/javascript; charset=utf-8
Collapse file
+100Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/**
2+
* Supports pseudo-"namespacing" for window-posted messages for a given test
3+
* by generating and using a unique prefix that gets wrapped into message
4+
* objects. This makes it more feasible to have multiple tests that use
5+
* `window.postMessage` in a single test file. Basically, make it possible
6+
* for the each test to listen for only the messages that are pertinent to it.
7+
*
8+
* 'Prefix' not an elegant term to use here but this models itself after
9+
* PrefixedLocalStorage.
10+
*
11+
* PrefixedMessageTest: Instantiate in testharness.js tests to generate
12+
* a new unique-ish prefix that can be used by other test support files
13+
* PrefixedMessageResource: Instantiate in supporting test resource
14+
* files to use/share a prefix generated by a test.
15+
*/
16+
var PrefixedMessage = function () {
17+
this.prefix = '';
18+
this.param = 'prefixedMessage'; // Param to use in querystrings
19+
};
20+
21+
/**
22+
* Generate a URL that adds/replaces param with this object's prefix
23+
* Use to link to test support files that make use of
24+
* PrefixedMessageResource.
25+
*/
26+
PrefixedMessage.prototype.url = function (uri) {
27+
function updateUrlParameter (uri, key, value) {
28+
var i = uri.indexOf('#');
29+
var hash = (i === -1) ? '' : uri.substr(i);
30+
uri = (i === -1) ? uri : uri.substr(0, i);
31+
var re = new RegExp(`([?&])${key}=.*?(&|$)`, 'i');
32+
var separator = uri.indexOf('?') !== -1 ? '&' : '?';
33+
uri = (uri.match(re)) ? uri.replace(re, `$1${key}=${value}$2`) :
34+
`${uri}${separator}${key}=${value}`;
35+
return uri + hash;
36+
}
37+
return updateUrlParameter(uri, this.param, this.prefix);
38+
};
39+
40+
/**
41+
* Add an eventListener on `message` but only invoke the given callback
42+
* for messages whose object contains this object's prefix. Remove the
43+
* event listener once the anticipated message has been received.
44+
*/
45+
PrefixedMessage.prototype.onMessage = function (fn) {
46+
window.addEventListener('message', e => {
47+
if (typeof e.data === 'object' && e.data.hasOwnProperty('prefix')) {
48+
if (e.data.prefix === this.prefix) {
49+
// Only invoke callback when `data` is an object containing
50+
// a `prefix` key with this object's prefix value
51+
// Note fn is invoked with "unwrapped" data first, then the event `e`
52+
// (which contains the full, wrapped e.data should it be needed)
53+
fn.call(this, e.data.data, e);
54+
window.removeEventListener('message', fn);
55+
}
56+
}
57+
});
58+
};
59+
60+
/**
61+
* Instantiate in a test file (e.g. during `setup`) to create a unique-ish
62+
* prefix that can be shared by support files
63+
*/
64+
var PrefixedMessageTest = function () {
65+
PrefixedMessage.call(this);
66+
this.prefix = `${document.location.pathname}-${Math.random()}-${Date.now()}-`;
67+
};
68+
PrefixedMessageTest.prototype = Object.create(PrefixedMessage.prototype);
69+
PrefixedMessageTest.prototype.constructor = PrefixedMessageTest;
70+
71+
/**
72+
* Instantiate in a test support script to use a "prefix" generated by a
73+
* PrefixedMessageTest in a controlling test file. It will look for
74+
* the prefix in a URL param (see also PrefixedMessage#url)
75+
*/
76+
var PrefixedMessageResource = function () {
77+
PrefixedMessage.call(this);
78+
// Check URL querystring for prefix to use
79+
var regex = new RegExp(`[?&]${this.param}(=([^&#]*)|&|#|$)`),
80+
results = regex.exec(document.location.href);
81+
if (results && results[2]) {
82+
this.prefix = results[2];
83+
}
84+
};
85+
PrefixedMessageResource.prototype = Object.create(PrefixedMessage.prototype);
86+
PrefixedMessageResource.prototype.constructor = PrefixedMessageResource;
87+
88+
/**
89+
* This is how a test resource document can "send info" to its
90+
* opener context. It will whatever message is being sent (`data`) in
91+
* an object that injects the prefix.
92+
*/
93+
PrefixedMessageResource.prototype.postToOpener = function (data) {
94+
if (window.opener) {
95+
window.opener.postMessage({
96+
prefix: this.prefix,
97+
data: data
98+
}, '*');
99+
}
100+
};
Collapse file
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Content-Type: text/javascript; charset=utf-8
Collapse file

‎test/fixtures/wpt/common/README.md‎

Copy file name to clipboard
+10Lines changed: 10 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
The files in this directory are non-infrastructure support files that can be used by tests.
2+
3+
* `blank.html` - An empty HTML document.
4+
* `domain-setter.sub.html` - An HTML document that sets `document.domain`.
5+
* `dummy.xhtml` - An XHTML document.
6+
* `dummy.xml` - An XML document.
7+
* `text-plain.txt` - A text/plain document.
8+
* `*.js` - Utility scripts. These are documented in the source.
9+
* `*.py` - wptserve [Python Handlers](https://web-platform-tests.org/writing-tests/python-handlers/). These are documented in the source.
10+
* `security-features` - Documented in `security-features/README.md`.
Collapse file

‎test/fixtures/wpt/common/arrays.js‎

Copy file name to clipboard
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Callback for checking equality of c and d.
3+
*
4+
* @callback equalityCallback
5+
* @param {*} c
6+
* @param {*} d
7+
* @returns {boolean}
8+
*/
9+
10+
/**
11+
* Returns true if the given arrays are equal. Optionally can pass an equality function.
12+
* @param {Array} a
13+
* @param {Array} b
14+
* @param {equalityCallback} callbackFunction - defaults to `c === d`
15+
* @returns {boolean}
16+
*/
17+
export function areArraysEqual(a, b, equalityFunction = (c, d) => { return c === d; }) {
18+
try {
19+
if (a.length !== b.length)
20+
return false;
21+
22+
for (let i = 0; i < a.length; i++) {
23+
if (!equalityFunction(a[i], b[i]))
24+
return false;
25+
}
26+
} catch (ex) {
27+
return false;
28+
}
29+
30+
return true;
31+
}
Collapse file

‎test/fixtures/wpt/common/blank.html‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/common/blank.html
Whitespace-only changes.
Collapse file
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>A page that will likely be same-origin-domain but not same-origin</title>
4+
5+
<script>
6+
"use strict";
7+
document.domain = "{{host}}";
8+
</script>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.