Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 function assert_worker_sends_pass(test_desc, mime_type, worker_code, protocol) { |
| 8 var worker = new Worker("data:,fetch('/').then(() => self.postMessage('fail'), () => self.postMessage('pass'))") // not same-origin | 8 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
| |
| 9 worker.onmessage = t.step_func_done(e => { | 9 async_test(function(t) { |
| 10 assert_equals(e.data, "pass") | 10 var w = new Worker(`${protocol}:${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 //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
| |
| 23 assert_worker_sends_pass('application/javascript MIME allowed', 'application/jav ascript', 'self.postMessage("PASS")'); | |
| 24 assert_worker_sends_pass('text/plain MIME allowed', 'text/plain', 'self.postMess age("PASS")'); | |
| 25 assert_worker_sends_pass('empty MIME allowed', '', 'self.postMessage("PASS")', ' DaTa'); | |
| 26 | |
| 27 //Communications works both ways | |
| 28 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
| |
| 29 | |
| 30 //Protocol is not case sensitive | |
| 31 assert_worker_sends_pass('protocol is case-insensitive', 'application/javascript ', 'self.postMessage("PASS")', 'DaTa'); | |
| 32 | |
| 33 //'data:' workers are cross-origin | |
| 34 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
| |
| 35 assert_worker_throws('localStorage inaccessible', 'self.localStorage.testItem'); | |
| 36 assert_worker_sends_pass('cross-origin worker', '', 'fetch("/").then(() => self. postMessage("FAIL"), () => self.postMessage("PASS"))'); | |
| 37 | |
| 38 //'data:' workers have opaque origin | |
| 39 assert_worker_sends_pass('worker has opaque origin', 'application/javascript', ' if (self.location.origin == "null") postMessage("PASS"); else postMessage("FAIL" );'); | |
| 13 </script> | 40 </script> |
| OLD | NEW |