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

Unified Diff: third_party/WebKit/LayoutTests/broadcastchannel/blobs.html

Issue 2004643002: Implement BroadcastChannel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address dcheng's comments Created 4 years, 6 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/broadcastchannel/blobs.html
diff --git a/third_party/WebKit/LayoutTests/broadcastchannel/blobs.html b/third_party/WebKit/LayoutTests/broadcastchannel/blobs.html
new file mode 100644
index 0000000000000000000000000000000000000000..a75be5e0e897501ed0ba2d62b9c54373502dab98
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/broadcastchannel/blobs.html
@@ -0,0 +1,66 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script>
+
+async_test(t => {
+ let c1 = new BroadcastChannel('blob');
+ let c2 = new BroadcastChannel('blob');
+ let c3 = new BroadcastChannel('blob');
+
+ let readCount = 0;
+ c2.onmessage = t.step_func(e => {
+ // check blob
+ assert_true('blob' in e.data);
+ assert_true(e.data.blob instanceof Blob);
+ assert_equals(e.data.blob.size, 6);
+ let reader = new FileReader();
+ reader.onerror = t.unreached_func();
+ reader.onload = t.step_func(() => {
+ assert_equals(reader.result, 'foobar');
+ if (++readCount == 2)
+ t.done();
+ });
+ reader.readAsText(e.data.blob);
+ });
+ c3.onmessage = c2.onmessage;
+ c1.postMessage({blob: new Blob(['foo', 'bar'])});
+ }, 'Blobs work on BroadcastChannel');
+
+async_test(t => {
+ let c1 = new BroadcastChannel('blobworker');
+ let c2 = new BroadcastChannel('blobworker');
+ let events = [];
+
+ c1.onmessage = e => events.push(e.data);
+ c2.onmessage = e => events.push(e.data);
+ c2.addEventListener('message', e => {
+ if (e.data.blob)
+ c1.postMessage('done');
+ });
+
+ let worker = new Worker('resources/worker.js');
+ worker.onmessage = t.step_func(e => {
+ assert_equals(events.length, 5);
+ assert_equals(events[0], 'from worker');
+ assert_equals(events[1], 'from worker');
+ assert_true(events[2].blob instanceof Blob);
+ assert_equals(events[2].blob.size, 11);
+ assert_true(events[3].blob instanceof Blob);
+ assert_equals(events[3].blob.size, 11);
+ assert_equals(events[4], 'done');
+ let reader = new FileReader();
+ reader.onerror = t.unreached_func();
+ reader.onload = t.step_func(() => {
+ assert_equals(reader.result, 'hello-world');
+ t.done();
+ });
+ reader.readAsText(events[3].blob);
+ });
+ worker.postMessage({channel: 'blobworker'});
+ worker.postMessage({blob: ['hello-world']});
+
+ }, 'Blobs work with workers on BroadcastChannel');
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698