Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: third_party/WebKit/LayoutTests/external/wpt/workers/data-url.html

Issue 2685543002: Support data URLs in worker constructors (Closed)
Patch Set: Added additional test for invalid javascript data: worker Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/external/wpt/workers/data-url.html
diff --git a/third_party/WebKit/LayoutTests/external/wpt/workers/data-url.html b/third_party/WebKit/LayoutTests/external/wpt/workers/data-url.html
index c212a699ec60f542d0775d38645c1124699ee3d1..da468e79742d630515e05c41f0f893161c0213ea 100644
--- a/third_party/WebKit/LayoutTests/external/wpt/workers/data-url.html
+++ b/third_party/WebKit/LayoutTests/external/wpt/workers/data-url.html
@@ -1,13 +1,56 @@
<!DOCTYPE html>
-<title>data URL worker</title>
+<title>Test workers can be started with a data URL</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
-<div id=log></div>
+<div id="log"></div>
<script>
-async_test(t => {
- var worker = new Worker("data:,fetch('/').then(() => self.postMessage('fail'), () => self.postMessage('pass'))") // not same-origin
- worker.onmessage = t.step_func_done(e => {
- assert_equals(e.data, "pass")
- })
-})
+// Helper assert functions -START-
+function assert_worker_sends_pass(test_desc, mime_type, worker_code) {
+ async_test(function(t) {
+ var w = new Worker(`data:${mime_type},${worker_code}`);
+ w.onmessage = t.step_func_done(function(e) {
+ assert_equals(e.data, 'PASS');
+ });
+ w.postMessage('SEND_PASS');
+ }, test_desc);
+}
+
+function assert_worker_throws(test_desc, worker_code) {
+ assert_worker_sends_pass(test_desc, '', `try { ${worker_code}; self.postMessage("FAIL"); } catch (e) { self.postMessage("PASS"); }`);
+}
+
+function assert_worker_construction_fails(test_desc, mime_type, worker_code) {
+ async_test(function(t) {
+ var w = new Worker(`data:${mime_type},${worker_code};postMessage("PASS")`);
+ w.onmessage = t.step_func_done(function(e) {
+ assert_unreached('Should not receive any message back.');
+ });
+ w.onerror = t.step_func_done(function() {
+ });
+ }, test_desc);
+}
+// Helper assert functions -END-
+
+// Actual tests -START-
+
+// Any MIME type
+assert_worker_sends_pass('application/javascript MIME allowed', 'application/javascript', 'self.postMessage("PASS")');
+assert_worker_sends_pass('text/plain MIME allowed', 'text/plain', 'self.postMessage("PASS")');
+assert_worker_sends_pass('empty MIME allowed', '', 'self.postMessage("PASS")');
+
+// Communications goes both ways
+assert_worker_sends_pass('communication goes both ways', 'application/javascript', 'onmessage = function(e) { self.postMessage("PASS"); }');
+
+// 'data:' workers are cross-origin
+assert_worker_throws('indexedDB inaccessible', 'self.indexedDB.open("someDBName")');
Marijn Kruisselbrink 2017/02/14 18:38:10 I'm not convinced that this is actually spec compl
jochen (gone - plz use gerrit) 2017/02/14 19:19:27 interesting. I filed https://github.com/w3c/Indexe
+assert_worker_throws('localStorage inaccessible', 'self.localStorage.testItem');
Marijn Kruisselbrink 2017/02/14 18:38:10 This test makes no sense. Workers don't have local
+assert_worker_sends_pass('cross-origin worker', '', 'fetch("/").then(() => self.postMessage("FAIL"), () => self.postMessage("PASS"))');
+
+// 'data:' workers have opaque origin
+assert_worker_sends_pass('worker has opaque origin', 'application/javascript', 'if (self.location.origin == "null") postMessage("PASS"); else postMessage("FAIL");');
+
+// invalid javascript will trigger an ErrorEvent
+assert_worker_construction_fails('invalid javascript produces error', 'application/javascript', '}x=3');
+
+// Actual tests -END-
</script>

Powered by Google App Engine
This is Rietveld 408576698