| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <meta charset=utf-8> | 2 <meta charset=utf-8> |
| 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 <script> | 5 <script> |
| 6 | 6 |
| 7 async_test(t => { | 7 async_test(t => { |
| 8 let c1 = new BroadcastChannel('blob'); | 8 const c1 = new BroadcastChannel('blob'); |
| 9 let c2 = new BroadcastChannel('blob'); | 9 const c2 = new BroadcastChannel('blob'); |
| 10 let c3 = new BroadcastChannel('blob'); | 10 const c3 = new BroadcastChannel('blob'); |
| 11 | 11 |
| 12 let readCount = 0; | 12 let readCount = 0; |
| 13 c2.onmessage = t.step_func(e => { | 13 c2.onmessage = t.step_func(e => { |
| 14 // check blob | 14 // check blob |
| 15 assert_true('blob' in e.data); | 15 assert_true('blob' in e.data); |
| 16 assert_true(e.data.blob instanceof Blob); | 16 assert_true(e.data.blob instanceof Blob); |
| 17 assert_equals(e.data.blob.size, 6); | 17 assert_equals(e.data.blob.size, 6); |
| 18 let reader = new FileReader(); | 18 const reader = new FileReader(); |
| 19 reader.onerror = t.unreached_func(); | 19 reader.onerror = t.unreached_func(); |
| 20 reader.onload = t.step_func(() => { | 20 reader.onload = t.step_func(() => { |
| 21 assert_equals(reader.result, 'foobar'); | 21 assert_equals(reader.result, 'foobar'); |
| 22 if (++readCount == 2) | 22 if (++readCount == 2) |
| 23 t.done(); | 23 t.done(); |
| 24 }); | 24 }); |
| 25 reader.readAsText(e.data.blob); | 25 reader.readAsText(e.data.blob); |
| 26 }); | 26 }); |
| 27 c3.onmessage = c2.onmessage; | 27 c3.onmessage = c2.onmessage; |
| 28 c1.postMessage({blob: new Blob(['foo', 'bar'])}); | 28 c1.postMessage({blob: new Blob(['foo', 'bar'])}); |
| 29 }, 'Blobs work on BroadcastChannel'); | 29 }, 'Blobs work on BroadcastChannel'); |
| 30 | 30 |
| 31 async_test(t => { | 31 async_test(t => { |
| 32 let c1 = new BroadcastChannel('blobworker'); | 32 const c1 = new BroadcastChannel('blobworker'); |
| 33 let c2 = new BroadcastChannel('blobworker'); | 33 const c2 = new BroadcastChannel('blobworker'); |
| 34 let events = []; | 34 const events = []; |
| 35 | 35 |
| 36 c1.onmessage = e => events.push(e.data); | 36 const verifyEvents = function() { |
| 37 c2.onmessage = e => events.push(e.data); | |
| 38 c2.addEventListener('message', e => { | |
| 39 if (e.data.blob) | |
| 40 c1.postMessage('done'); | |
| 41 }); | |
| 42 | |
| 43 let worker = new Worker('resources/worker.js'); | |
| 44 worker.onmessage = t.step_func(e => { | |
| 45 assert_equals(events.length, 5); | 37 assert_equals(events.length, 5); |
| 46 assert_equals(events[0], 'from worker'); | 38 assert_equals(events[0], 'from worker'); |
| 47 assert_equals(events[1], 'from worker'); | 39 assert_equals(events[1], 'from worker'); |
| 48 assert_true(events[2].blob instanceof Blob); | 40 assert_true(events[2].blob instanceof Blob); |
| 49 assert_equals(events[2].blob.size, 11); | 41 assert_equals(events[2].blob.size, 11); |
| 50 assert_true(events[3].blob instanceof Blob); | 42 assert_true(events[3].blob instanceof Blob); |
| 51 assert_equals(events[3].blob.size, 11); | 43 assert_equals(events[3].blob.size, 11); |
| 52 assert_equals(events[4], 'done'); | 44 assert_equals(events[4], 'done'); |
| 53 let reader = new FileReader(); | 45 const reader = new FileReader(); |
| 54 reader.onerror = t.unreached_func(); | 46 reader.onerror = t.unreached_func(); |
| 55 reader.onload = t.step_func(() => { | 47 reader.onload = t.step_func(() => { |
| 56 assert_equals(reader.result, 'hello-world'); | 48 assert_equals(reader.result, 'hello-world'); |
| 57 t.done(); | 49 t.done(); |
| 58 }); | 50 }); |
| 59 reader.readAsText(events[3].blob); | 51 reader.readAsText(events[3].blob); |
| 52 }; |
| 53 |
| 54 let receivedDone = false; |
| 55 let receivedWorkerDone = false; |
| 56 |
| 57 c1.onmessage = e => events.push(e.data); |
| 58 c2.onmessage = e => events.push(e.data); |
| 59 c2.addEventListener('message', t.step_func(e => { |
| 60 if (e.data.blob) |
| 61 c1.postMessage('done'); |
| 62 if (e.data === 'done') |
| 63 receivedDone = true; |
| 64 if (receivedDone && receivedWorkerDone) |
| 65 verifyEvents(); |
| 66 })); |
| 67 |
| 68 const worker = new Worker('resources/worker.js'); |
| 69 worker.onmessage = t.step_func(e => { |
| 70 receivedWorkerDone = true; |
| 71 if (receivedDone && receivedWorkerDone) |
| 72 verifyEvents(); |
| 60 }); | 73 }); |
| 61 worker.postMessage({channel: 'blobworker'}); | 74 worker.postMessage({channel: 'blobworker'}); |
| 62 worker.postMessage({blob: ['hello-world']}); | 75 worker.postMessage({blob: ['hello-world']}); |
| 63 | 76 |
| 64 }, 'Blobs work with workers on BroadcastChannel'); | 77 }, 'Blobs work with workers on BroadcastChannel'); |
| 65 | 78 |
| 66 </script> | 79 </script> |
| OLD | NEW |