11cb0ef41Sopenharmony_ci<!DOCTYPE html> 21cb0ef41Sopenharmony_ci<meta charset=utf-8> 31cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script> 41cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script> 51cb0ef41Sopenharmony_ci<script> 61cb0ef41Sopenharmony_ciasync_test(t => { 71cb0ef41Sopenharmony_ci const c1 = new BroadcastChannel('blob'); 81cb0ef41Sopenharmony_ci const c2 = new BroadcastChannel('blob'); 91cb0ef41Sopenharmony_ci const c3 = new BroadcastChannel('blob'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci let readCount = 0; 121cb0ef41Sopenharmony_ci c2.onmessage = t.step_func(e => { 131cb0ef41Sopenharmony_ci // check blob 141cb0ef41Sopenharmony_ci assert_true('blob' in e.data); 151cb0ef41Sopenharmony_ci assert_true(e.data.blob instanceof Blob); 161cb0ef41Sopenharmony_ci assert_equals(e.data.blob.size, 6); 171cb0ef41Sopenharmony_ci const reader = new FileReader(); 181cb0ef41Sopenharmony_ci reader.onerror = t.unreached_func(); 191cb0ef41Sopenharmony_ci reader.onload = t.step_func(() => { 201cb0ef41Sopenharmony_ci assert_equals(reader.result, 'foobar'); 211cb0ef41Sopenharmony_ci if (++readCount == 2) 221cb0ef41Sopenharmony_ci t.done(); 231cb0ef41Sopenharmony_ci }); 241cb0ef41Sopenharmony_ci reader.readAsText(e.data.blob); 251cb0ef41Sopenharmony_ci }); 261cb0ef41Sopenharmony_ci c3.onmessage = c2.onmessage; 271cb0ef41Sopenharmony_ci (() => { 281cb0ef41Sopenharmony_ci c1.postMessage({blob: new Blob(['foo', 'bar'])}); 291cb0ef41Sopenharmony_ci })(); 301cb0ef41Sopenharmony_ci // TODO(https://github.com/web-platform-tests/wpt/issues/7899): Change to 311cb0ef41Sopenharmony_ci // some sort of cross-browser GC trigger. 321cb0ef41Sopenharmony_ci if (self.gc) self.gc(); 331cb0ef41Sopenharmony_ci }, 'Blobs work on BroadcastChannel'); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ciasync_test(t => { 361cb0ef41Sopenharmony_ci const c1 = new BroadcastChannel('blobworker'); 371cb0ef41Sopenharmony_ci const c2 = new BroadcastChannel('blobworker'); 381cb0ef41Sopenharmony_ci const events = []; 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci const verifyEvents = function() { 411cb0ef41Sopenharmony_ci assert_equals(events.length, 5); 421cb0ef41Sopenharmony_ci assert_equals(events[0], 'from worker'); 431cb0ef41Sopenharmony_ci assert_equals(events[1], 'from worker'); 441cb0ef41Sopenharmony_ci assert_true(events[2].blob instanceof Blob); 451cb0ef41Sopenharmony_ci assert_equals(events[2].blob.size, 11); 461cb0ef41Sopenharmony_ci assert_true(events[3].blob instanceof Blob); 471cb0ef41Sopenharmony_ci assert_equals(events[3].blob.size, 11); 481cb0ef41Sopenharmony_ci assert_equals(events[4], 'done'); 491cb0ef41Sopenharmony_ci const reader = new FileReader(); 501cb0ef41Sopenharmony_ci reader.onerror = t.unreached_func(); 511cb0ef41Sopenharmony_ci reader.onload = t.step_func(() => { 521cb0ef41Sopenharmony_ci assert_equals(reader.result, 'hello-world'); 531cb0ef41Sopenharmony_ci t.done(); 541cb0ef41Sopenharmony_ci }); 551cb0ef41Sopenharmony_ci reader.readAsText(events[3].blob); 561cb0ef41Sopenharmony_ci }; 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci let receivedDone = false; 591cb0ef41Sopenharmony_ci let receivedWorkerDone = false; 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ci c1.onmessage = e => events.push(e.data); 621cb0ef41Sopenharmony_ci c2.onmessage = e => events.push(e.data); 631cb0ef41Sopenharmony_ci c2.addEventListener('message', t.step_func(e => { 641cb0ef41Sopenharmony_ci if (e.data.blob) 651cb0ef41Sopenharmony_ci c1.postMessage('done'); 661cb0ef41Sopenharmony_ci if (e.data === 'done') 671cb0ef41Sopenharmony_ci receivedDone = true; 681cb0ef41Sopenharmony_ci if (receivedDone && receivedWorkerDone) 691cb0ef41Sopenharmony_ci verifyEvents(); 701cb0ef41Sopenharmony_ci })); 711cb0ef41Sopenharmony_ci 721cb0ef41Sopenharmony_ci const worker = new Worker('resources/worker.js'); 731cb0ef41Sopenharmony_ci worker.onmessage = t.step_func(e => { 741cb0ef41Sopenharmony_ci receivedWorkerDone = true; 751cb0ef41Sopenharmony_ci if (receivedDone && receivedWorkerDone) 761cb0ef41Sopenharmony_ci verifyEvents(); 771cb0ef41Sopenharmony_ci }); 781cb0ef41Sopenharmony_ci worker.postMessage({channel: 'blobworker'}); 791cb0ef41Sopenharmony_ci worker.postMessage({blob: ['hello-world']}); 801cb0ef41Sopenharmony_ci 811cb0ef41Sopenharmony_ci }, 'Blobs work with workers on BroadcastChannel'); 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci</script> 84