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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/webmessaging/broadcastchannel/blobs.html

Issue 2558423002: Import wpt/webmessaging tests (Closed)
Patch Set: rebase again Created 3 years, 11 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
(Empty)
1 <!DOCTYPE html>
2 <meta charset=utf-8>
3 <script src="/resources/testharness.js"></script>
4 <script src="/resources/testharnessreport.js"></script>
5 <script>
6
7 async_test(t => {
8 const c1 = new BroadcastChannel('blob');
9 const c2 = new BroadcastChannel('blob');
10 const c3 = new BroadcastChannel('blob');
11
12 let readCount = 0;
13 c2.onmessage = t.step_func(e => {
14 // check blob
15 assert_true('blob' in e.data);
16 assert_true(e.data.blob instanceof Blob);
17 assert_equals(e.data.blob.size, 6);
18 const reader = new FileReader();
19 reader.onerror = t.unreached_func();
20 reader.onload = t.step_func(() => {
21 assert_equals(reader.result, 'foobar');
22 if (++readCount == 2)
23 t.done();
24 });
25 reader.readAsText(e.data.blob);
26 });
27 c3.onmessage = c2.onmessage;
28 c1.postMessage({blob: new Blob(['foo', 'bar'])});
29 }, 'Blobs work on BroadcastChannel');
30
31 async_test(t => {
32 const c1 = new BroadcastChannel('blobworker');
33 const c2 = new BroadcastChannel('blobworker');
34 const events = [];
35
36 const verifyEvents = function() {
37 assert_equals(events.length, 5);
38 assert_equals(events[0], 'from worker');
39 assert_equals(events[1], 'from worker');
40 assert_true(events[2].blob instanceof Blob);
41 assert_equals(events[2].blob.size, 11);
42 assert_true(events[3].blob instanceof Blob);
43 assert_equals(events[3].blob.size, 11);
44 assert_equals(events[4], 'done');
45 const reader = new FileReader();
46 reader.onerror = t.unreached_func();
47 reader.onload = t.step_func(() => {
48 assert_equals(reader.result, 'hello-world');
49 t.done();
50 });
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();
73 });
74 worker.postMessage({channel: 'blobworker'});
75 worker.postMessage({blob: ['hello-world']});
76
77 }, 'Blobs work with workers on BroadcastChannel');
78
79 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698