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

Side by Side 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 unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <title>data URL worker</title> 2 <title>Test workers can be started with a data URL</title>
3 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharness.js"></script>
4 <script src="/resources/testharnessreport.js"></script> 4 <script src="/resources/testharnessreport.js"></script>
5 <div id=log></div> 5 <div id="log"></div>
6 <script> 6 <script>
7 async_test(t => { 7 // Helper assert functions -START-
8 var worker = new Worker("data:,fetch('/').then(() => self.postMessage('fail'), () => self.postMessage('pass'))") // not same-origin 8 function assert_worker_sends_pass(test_desc, mime_type, worker_code) {
9 worker.onmessage = t.step_func_done(e => { 9 async_test(function(t) {
10 assert_equals(e.data, "pass") 10 var w = new Worker(`data:${mime_type},${worker_code}`);
11 }) 11 w.onmessage = t.step_func_done(function(e) {
12 }) 12 assert_equals(e.data, 'PASS');
13 });
14 w.postMessage('SEND_PASS');
15 }, test_desc);
16 }
17
18 function assert_worker_throws(test_desc, worker_code) {
19 assert_worker_sends_pass(test_desc, '', `try { ${worker_code}; self.postMessag e("FAIL"); } catch (e) { self.postMessage("PASS"); }`);
20 }
21
22 function assert_worker_construction_fails(test_desc, mime_type, worker_code) {
23 async_test(function(t) {
24 var w = new Worker(`data:${mime_type},${worker_code};postMessage("PASS")`);
25 w.onmessage = t.step_func_done(function(e) {
26 assert_unreached('Should not receive any message back.');
27 });
28 w.onerror = t.step_func_done(function() {
29 });
30 }, test_desc);
31 }
32 // Helper assert functions -END-
33
34 // Actual tests -START-
35
36 // Any MIME type
37 assert_worker_sends_pass('application/javascript MIME allowed', 'application/jav ascript', 'self.postMessage("PASS")');
38 assert_worker_sends_pass('text/plain MIME allowed', 'text/plain', 'self.postMess age("PASS")');
39 assert_worker_sends_pass('empty MIME allowed', '', 'self.postMessage("PASS")');
40
41 // Communications goes both ways
42 assert_worker_sends_pass('communication goes both ways', 'application/javascript ', 'onmessage = function(e) { self.postMessage("PASS"); }');
43
44 // 'data:' workers are cross-origin
45 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
46 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
47 assert_worker_sends_pass('cross-origin worker', '', 'fetch("/").then(() => self. postMessage("FAIL"), () => self.postMessage("PASS"))');
48
49 // 'data:' workers have opaque origin
50 assert_worker_sends_pass('worker has opaque origin', 'application/javascript', ' if (self.location.origin == "null") postMessage("PASS"); else postMessage("FAIL" );');
51
52 // invalid javascript will trigger an ErrorEvent
53 assert_worker_construction_fails('invalid javascript produces error', 'applicati on/javascript', '}x=3');
54
55 // Actual tests -END-
13 </script> 56 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698