Skip to content

Commit

Permalink
Upstream fast/workers to external/wpt/workers: first batch.
Browse files Browse the repository at this point in the history
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
kjd564 authored and Commit Bot committed Jan 24, 2019
1 parent b430338 commit 40748e1
Show file tree
Hide file tree
Showing 55 changed files with 381 additions and 498 deletions.
1 change: 0 additions & 1 deletion third_party/blink/web_tests/ASANExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ crbug.com/882756 external/wpt/requestidlecallback/cancel-invoked.html [ Timeout

# Stack use-after-return detection
crbug.com/438499 [ Linux ] crypto/worker-random-values-limits.html [ Timeout ]
crbug.com/438499 [ Linux ] fast/workers/simultaneous-errors.html [ Timeout ]
crbug.com/438499 [ Linux ] fast/workers/worker-multi-startup.html [ Timeout ]
crbug.com/438499 [ Linux ] http/tests/websocket/workers/worker-simple.html [ Timeout ]
crbug.com/438499 [ Linux ] http/tests/workers/text-encoding.html [ Timeout ]
Expand Down
1 change: 0 additions & 1 deletion third_party/blink/web_tests/MSANExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ crbug.com/420198 [ Linux ] fast/css/fontface-arraybuffer.html [ Skip ]

# Deliberate infinite recursion. A JS exception is expected, but may crash with
# a stack overflow due to bloated stack frames under MSan.
crbug.com/420606 [ Linux ] fast/workers/shared-worker-constructor.html [ Skip ]
crbug.com/420606 [ Linux ] fast/workers/worker-constructor.html [ Skip ]

# Flaky under MSan (hang forever).
Expand Down
2 changes: 2 additions & 0 deletions third_party/blink/web_tests/external/wpt/lint.whitelist
Original file line number Diff line number Diff line change
Expand Up @@ -801,3 +801,5 @@ CSS-COLLIDING-REF-NAME: css/vendor-imports/mozilla/mozilla-central-reftests/cont
# Signed Exchange files have hard-coded URLs in the certUrl field
WEB-PLATFORM.TEST:signed-exchange/resources/*.sxg
WEB-PLATFORM.TEST:signed-exchange/resources/generate-test-sxgs.sh

WEB-PLATFORM.TEST: workers/Worker-location.any.js
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]);
});
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>
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>
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.");
}
});
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>
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>
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');
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();
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.');
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.');
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.');
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.');
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>
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>
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.");
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);
}
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;
}
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);
}
};
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);
}
}
}
Loading

0 comments on commit 40748e1

Please sign in to comment.