forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upstream fast/workers to external/wpt/workers: first batch.
Bug: 795636 Change-Id: Ifbeaf7eab76b992ac41a4dc7f23ec46f72ad8ca2 Reviewed-on: https://chromium-review.googlesource.com/c/1412827 Commit-Queue: Katie Dillon <kdillon@chromium.org> Reviewed-by: Hiroki Nakagawa <nhiroki@chromium.org> Cr-Commit-Position: refs/heads/master@{#625734}
- Loading branch information
Showing
55 changed files
with
381 additions
and
498 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
third_party/blink/web_tests/external/wpt/workers/SharedWorker-MessageEvent-source.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// META: global=!default,sharedworker | ||
const t = async_test("Make sure that MessageEvent.source is properly set in connect event."); | ||
onconnect = t.step_func_done((event) => { | ||
assert_equals(event.__proto__, MessageEvent.prototype); | ||
assert_equals(event.source, event.ports[0]); | ||
}); |
60 changes: 60 additions & 0 deletions
60
third_party/blink/web_tests/external/wpt/workers/SharedWorker-constructor.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!DOCTYPE html> | ||
<title>Test SharedWorker constructor functionality.</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
|
||
test(() => { | ||
assert_throws(new Error(), | ||
function() { | ||
new SharedWorker({toString:function(){throw new Error()}}, "name") }, | ||
"toString exception not propagagted"); | ||
}, "Test toString exception propagated correctly."); | ||
|
||
test(() => { | ||
assert_throws(new RangeError(), | ||
function() { | ||
var foo = {toString:function(){new Worker(foo)}} | ||
new SharedWorker(foo, name); }, | ||
"Trying to create workers recursively did not result in an exception."); | ||
}, "Test recursive worker creation results in exception."); | ||
|
||
test(() => { | ||
assert_throws(new TypeError(), | ||
function() { new SharedWorker(); }, | ||
"Invoking SharedWorker constructor without arguments did not result in an exception."); | ||
}, "Test SharedWorker creation without arguments results in exception."); | ||
|
||
test(() => { | ||
try { | ||
var worker = new SharedWorker("support/SharedWorker-common.js"); | ||
} catch (ex) { | ||
assert_unreached("Constructor failed when no name is passed: (" + ex + ")"); | ||
} | ||
}, "Test SharedWorker constructor without a name does not result in an exception."); | ||
|
||
test(() => { | ||
try { | ||
var worker = new SharedWorker("support/SharedWorker-common.js", null); | ||
} catch (ex) { | ||
assert_unreached("Constructor failed when null name is passed: (" + ex + ")"); | ||
} | ||
}, "Test SharedWorker constructor with null name does not result in an exception."); | ||
|
||
test(() => { | ||
try { | ||
var worker = new SharedWorker("support/SharedWorker-common.js", undefined); | ||
} catch (ex) { | ||
assert_unreached("Constructor failed when undefined name is passed: (" + ex + ")"); | ||
} | ||
}, "Test SharedWorker constructor with undefined name does not result in an exception."); | ||
|
||
test(() => { | ||
try { | ||
var worker = new SharedWorker("support/SharedWorker-common.js", "name"); | ||
} catch (ex) { | ||
assert_unreached("Invoking SharedWorker constructor resulted in an exception: (" + ex + ")"); | ||
} | ||
}, "Test SharedWorker constructor suceeds."); | ||
|
||
</script> |
18 changes: 18 additions & 0 deletions
18
third_party/blink/web_tests/external/wpt/workers/SharedWorker-exception.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<title>This test checks whether exceptions in SharedWorkers are logged to the parent document. An exception should be logged to the error console.</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="support/SharedWorker-create-common.js"></script> | ||
<script> | ||
async_test(function(t) { | ||
var worker = createWorker(); | ||
worker.postMessage("throw"); | ||
worker.postMessage("ping"); | ||
worker.onmessage = function(evt) { | ||
// Wait for response from ping - that's how we know we have thrown the exception. | ||
if (evt.data == "PASS: Received ping message") { | ||
t.done(); | ||
} | ||
}; | ||
}); | ||
</script> |
15 changes: 15 additions & 0 deletions
15
third_party/blink/web_tests/external/wpt/workers/SharedWorker-replace-EventHandler.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// META: global=!default,sharedworker | ||
// https://crbug.com/239669 | ||
const t = async_test("Tests that repeatedly setting 'onerror' within a shared worker doesnt crash."); | ||
onconnect = t.step_func_done((event) => { | ||
function update() { | ||
onerror = undefined; | ||
} | ||
try { | ||
for (var i = 0; i < 8; ++i) { | ||
update(); | ||
} | ||
} catch (ex) { | ||
assert_unreached("FAIL: unexpected exception (" + ex + ") received while updating onerror event handler."); | ||
} | ||
}); |
37 changes: 37 additions & 0 deletions
37
third_party/blink/web_tests/external/wpt/workers/SharedWorker-script-error.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!DOCTYPE html> | ||
<title>Test SharedWorker script error handling functionality.</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
promise_test(t => { | ||
let worker; | ||
|
||
return new Promise((resolve) => { | ||
worker = new SharedWorker("support/SharedWorker-script-error.js"); | ||
// Shared workers should only invoke onerror for loading errors. | ||
worker.onerror = function(evt) { | ||
assert_unreached("FAIL: onerror invoked for a script error."); | ||
}; | ||
worker.port.postMessage("unhandledError"); | ||
worker.port.onmessage = resolve; | ||
}).then(e => { | ||
assert_equals(e.data, "SUCCESS: unhandled error generated"); | ||
}); | ||
}, 'Test script error unhandled.') | ||
|
||
promise_test(t => { | ||
let worker; | ||
|
||
return new Promise((resolve) => { | ||
worker = new SharedWorker("support/SharedWorker-script-error.js"); | ||
// Shared workers should only invoke onerror for loading errors. | ||
worker.onerror = function(evt) { | ||
assert_unreached("FAIL: onerror invoked for a script error."); | ||
}; | ||
worker.port.postMessage("handledError"); | ||
worker.port.onmessage = resolve; | ||
}).then(e => { | ||
assert_equals(e.data, "SUCCESS: error handled via onerror"); | ||
}); | ||
}, 'Test script error handled.') | ||
</script> |
17 changes: 17 additions & 0 deletions
17
third_party/blink/web_tests/external/wpt/workers/SharedWorker-simple.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<title>Test simple shared worker construction case.</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
promise_test(t => { | ||
let worker; | ||
|
||
return new Promise(resolve => { | ||
worker = new SharedWorker('support/SharedWorker-common.js', 'name'); | ||
worker.port.postMessage("ping"); | ||
worker.port.onmessage = resolve; | ||
}).then(e => { | ||
assert_equals(e.data, "PASS: Received ping message"); | ||
}); | ||
}); | ||
</script> |
5 changes: 5 additions & 0 deletions
5
third_party/blink/web_tests/external/wpt/workers/Worker-base64.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// META: global=!default,worker | ||
test(() => { | ||
assert_true(typeof atob === 'function'); | ||
assert_true(typeof btoa === 'function'); | ||
}, 'Tests that atob() / btoa() functions are exposed to workers'); |
12 changes: 12 additions & 0 deletions
12
third_party/blink/web_tests/external/wpt/workers/Worker-call.worker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
importScripts("/resources/testharness.js"); | ||
test(() => { | ||
try { | ||
postMessage("SUCCESS: postMessage() called directly"); | ||
postMessage.call(null, "SUCCESS: postMessage() invoked via postMessage.call()"); | ||
var saved = postMessage; | ||
saved("SUCCESS: postMessage() called via intermediate variable"); | ||
} catch (ex) { | ||
assert_unreached("FAIL: unexpected exception (" + ex + ") received while calling functions from the worker context."); | ||
} | ||
}, 'Test calling functions from WorkerContext.'); | ||
done(); |
7 changes: 7 additions & 0 deletions
7
third_party/blink/web_tests/external/wpt/workers/Worker-constructor-proto.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//META: global=!default, worker | ||
test(() => { | ||
proto = new Number(42) | ||
assert_equals(String(Object.getPrototypeOf(WorkerLocation)), "function () { [native code] }"); | ||
WorkerLocation.__proto__ = proto; | ||
assert_object_equals(Object.getPrototypeOf(WorkerLocation), Object(42)); | ||
}, 'Tests that setting the proto of a built in constructor is not reset.'); |
14 changes: 14 additions & 0 deletions
14
third_party/blink/web_tests/external/wpt/workers/Worker-location.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// META: global=!default, dedicatedworker, sharedworker | ||
test(() => { | ||
assert_equals(String(WorkerLocation), "function WorkerLocation() { [native code] }"); | ||
assert_true(location instanceof Object); | ||
assert_equals(location.href, "http://web-platform.test:8001/workers/Worker-location.any.worker.js") | ||
assert_equals(location.origin, "http://web-platform.test:8001"); | ||
assert_equals(location.protocol, "http:"); | ||
assert_equals(location.host, "web-platform.test:8001"); | ||
assert_equals(location.hostname, "web-platform.test"); | ||
assert_equals(location.port, "8001"); | ||
assert_equals(location.pathname, "/workers/Worker-location.any.worker.js"); | ||
assert_equals(location.search, ""); | ||
assert_equals(location.hash, ""); | ||
}, 'Test WorkerLocation properties.'); |
9 changes: 9 additions & 0 deletions
9
third_party/blink/web_tests/external/wpt/workers/Worker-replace-global-constructor.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// META: global=!default,worker | ||
test(() => { | ||
try { | ||
self.MessageEvent = 'PASS'; | ||
assert_equals(self.MessageEvent, 'PASS'); | ||
} catch (ex) { | ||
assert_unreached("FAIL: unexpected exception (" + ex + ") received while replacing global constructor MessageEvent."); | ||
} | ||
}, 'Test replacing global constructors in a worker context.'); |
9 changes: 9 additions & 0 deletions
9
third_party/blink/web_tests/external/wpt/workers/Worker-replace-self.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// META: global=!default,worker | ||
test(() => { | ||
try { | ||
self = 'PASS'; | ||
assert_true(self instanceof WorkerGlobalScope); | ||
} catch (ex) { | ||
assert_unreached("FAIL: unexpected exception (" + ex + ") received while replacing self."); | ||
} | ||
}, 'Test that self is not replaceable.'); |
33 changes: 33 additions & 0 deletions
33
third_party/blink/web_tests/external/wpt/workers/Worker-simultaneous-errors.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!DOCTYPE html> | ||
<title>Test simultaneous errors on workers.</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
promise_test(t => { | ||
var workers = 4; | ||
var promises = []; | ||
|
||
for (i = 0; i < workers; ++i) { | ||
var worker = new Worker('support/throw-on-message-Worker.js'); | ||
promises.push(new Promise(function(resolve, reject) { | ||
var error = 0; | ||
worker.onmessage = function(event) { | ||
if (event.data === 'second') | ||
resolve(error); | ||
else if (event.data === 'error') | ||
++error; | ||
} | ||
})); | ||
worker.postMessage('first'); | ||
worker.postMessage('second'); | ||
} | ||
|
||
return Promise.all(promises).then(e => { | ||
var sum = 0; | ||
for (var key in e) { | ||
sum += e[key] | ||
} | ||
assert_equals(sum, workers); | ||
}); | ||
}); | ||
</script> |
22 changes: 22 additions & 0 deletions
22
third_party/blink/web_tests/external/wpt/workers/Worker-termination-with-port-messages.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<title>This test terminates a worker when there are many undelivered MessagePort messages still waiting to be dispatched into the Worker Context. This causes termination of JS execution and test should not try to dispatch the remaining messages. Test succeeds if it does not hang or crash (if worker thread is running in the separate process, that process could hang or crash).</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
async_test(function(t) { | ||
var worker = new Worker("support/Worker-termination-with-port-messages.js"); | ||
var channel = new MessageChannel(); | ||
|
||
channel.port2.onmessage = function(evt) | ||
{ | ||
// On first message back from worker, terminate it. | ||
worker.terminate(); | ||
t.done(); | ||
} | ||
channel.port2.start(); | ||
|
||
worker.postMessage("", [channel.port1]); | ||
for (i = 0; i < 1000; i++) | ||
channel.port2.postMessage("message to worker"); | ||
}); | ||
</script> |
12 changes: 12 additions & 0 deletions
12
third_party/blink/web_tests/external/wpt/workers/WorkerNavigator.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// META: global=!default, worker | ||
test(() => { | ||
assert_equals(typeof navigator, "object"); | ||
assert_true(navigator instanceof WorkerNavigator); | ||
assert_equals(navigator.appName, "Netscape"); | ||
assert_true(navigator.appVersion.indexOf('WebKit') != 0); | ||
assert_equals(typeof navigator.platform, "string"); | ||
assert_true(navigator.userAgent.indexOf('WebKit') != 0); | ||
assert_equals(typeof navigator.onLine, "boolean"); | ||
assert_equals(navigator.appCodeName, 'Mozilla'); | ||
assert_equals(navigator.product, 'Gecko'); | ||
}, "Testing Navigator properties on workers."); |
32 changes: 32 additions & 0 deletions
32
third_party/blink/web_tests/external/wpt/workers/support/SharedWorker-common.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function generateError() | ||
{ | ||
// Generate an exception by accessing an undefined variable. | ||
foo.bar = 0; | ||
} | ||
|
||
onconnect = function(event) { | ||
event.ports[0].onmessage = function(evt) { handleMessage(evt, event.ports[0]); }; | ||
}; | ||
|
||
function handleMessage(event, port) { | ||
self.port = port; | ||
if (event.data == "ping") | ||
port.postMessage("PASS: Received ping message"); | ||
else if (event.data == "close") | ||
close(); | ||
else if (event.data == "done") | ||
port.postMessage("DONE"); | ||
else if (event.data == "throw") | ||
generateError(); | ||
else if (event.data == "testingNameAttribute") | ||
port.postMessage(self.name); | ||
else if (/eval.+/.test(event.data)) { | ||
try { | ||
port.postMessage(event.data.substr(5) + ": " + eval(event.data.substr(5))); | ||
} catch (ex) { | ||
port.postMessage(event.data.substr(5) + ": " + ex); | ||
} | ||
} | ||
else | ||
port.postMessage("FAILURE: Received unknown message: " + event.data); | ||
} |
8 changes: 8 additions & 0 deletions
8
third_party/blink/web_tests/external/wpt/workers/support/SharedWorker-create-common.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Make a SharedWorker that has the same external interface as a DedicatedWorker, to use in shared test code. | ||
function createWorker() | ||
{ | ||
var worker = new SharedWorker('support/SharedWorker-common.js', 'name'); | ||
worker.port.onmessage = function(evt) { worker.onmessage(evt); }; | ||
worker.postMessage = function(msg, port) { worker.port.postMessage(msg, port); }; | ||
return worker; | ||
} |
22 changes: 22 additions & 0 deletions
22
third_party/blink/web_tests/external/wpt/workers/support/SharedWorker-script-error.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
onconnect = function(event) { | ||
event.ports[0].onmessage = function(evt) { handleMessage(evt, event.ports[0]); }; | ||
}; | ||
|
||
function handleMessage(event, port) { | ||
if (event.data == "unhandledError") { | ||
// Generate an unhandled error. | ||
onerror = null; | ||
setTimeout(function() { | ||
port.postMessage("SUCCESS: unhandled error generated"); | ||
}, 100); | ||
generateError(); // Undefined function call | ||
} else if (event.data == "handledError") { | ||
onerror = function() { | ||
port.postMessage("SUCCESS: error handled via onerror"); | ||
return true; | ||
}; | ||
generateError(); // Undefined function call | ||
} else { | ||
port.postMessage("FAIL: Got unexpected message: " + event.data); | ||
} | ||
}; |
16 changes: 16 additions & 0 deletions
16
third_party/blink/web_tests/external/wpt/workers/support/Worker-common.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
onmessage = function(evt) | ||
{ | ||
if (evt.data == "ping") | ||
postMessage("pong"); | ||
else if (evt.data == "freeze") | ||
while (1) {} | ||
else if (evt.data == "close") | ||
close(); | ||
else if (/eval.+/.test(evt.data)) { | ||
try { | ||
postMessage(evt.data.substr(5) + ": " + eval(evt.data.substr(5))); | ||
} catch (ex) { | ||
postMessage(evt.data.substr(5) + ": " + ex); | ||
} | ||
} | ||
} |
Oops, something went wrong.