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

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

Issue 2685543002: Support data URLs in worker constructors (Closed)
Patch Set: Implemented Pass 2 code review suggestions. Removed external/wpt/workers/data-url.html from the lis… 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..d696e54994a08c618631172f2a8a7ee6725884e1 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,40 @@
<!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")
- })
-})
+function assert_worker_sends_pass(test_desc, mime_type, worker_code, protocol) {
+ if (!protocol) protocol = 'data';
Mike West 2017/02/08 15:18:53 I don't actually think this adds much. That is, it
andypaicu2 2017/02/10 10:25:38 Removed
+ async_test(function(t) {
+ var w = new Worker(`${protocol}:${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"); }`);
+}
+
+//Any MIME type
Mike West 2017/02/08 15:18:53 Nit: Space between "//" and the comment, here and
andypaicu2 2017/02/10 10:25:38 Done
+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")', 'DaTa');
+
+//Communications works both ways
+assert_worker_sends_pass('communication is both ways', 'application/javascript', 'onmessage = function(e) { self.postMessage("PASS"); }');
Mike West 2017/02/08 15:18:53 Nit: "is bidirectional", or "goes both ways".
andypaicu2 2017/02/10 10:25:38 Done
+
+//Protocol is not case sensitive
+assert_worker_sends_pass('protocol is case-insensitive', 'application/javascript', 'self.postMessage("PASS")', 'DaTa');
+
+//'data:' workers are cross-origin
+assert_worker_throws('indexDB inaccessible', 'self.indexedDB.open("bug270979")');
Mike West 2017/02/08 15:18:53 1. Nit: "indexedDB", not "indexDB". 2. Why `bug270
andypaicu2 2017/02/10 10:25:38 Done
+assert_worker_throws('localStorage inaccessible', 'self.localStorage.testItem');
+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");');
</script>

Powered by Google App Engine
This is Rietveld 408576698