mediasource-worker-handle.html (2739B)
1 <!DOCTYPE html> 2 <html> 3 <title>Test MediaSource object and handle creation, with MediaSource in dedicated worker</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="mediasource-message-util.js"></script> 7 <script> 8 9 async_test(t => { 10 // Fail fast if MSE-in-Workers is not supported. 11 assert_true(MediaSource.hasOwnProperty("canConstructInDedicatedWorker"), "MediaSource hasOwnProperty 'canConstructInDedicatedWorker'"); 12 assert_true(MediaSource.canConstructInDedicatedWorker, "MediaSource.canConstructInDedicatedWorker"); 13 assert_true(window.hasOwnProperty("MediaSourceHandle"), "window must have MediaSourceHandle visibility"); 14 15 let worker = new Worker("mediasource-worker-play.js"); 16 worker.onmessage = t.step_func(e => { 17 let subject = e.data.subject; 18 assert_true(subject != undefined, "message must have a subject field"); 19 switch (subject) { 20 case messageSubject.ERROR: 21 assert_unreached("Worker error: " + e.data.info); 22 break; 23 case messageSubject.HANDLE: 24 const handle = e.data.info; 25 assert_not_equals(handle, null, "must have a non-null MediaSourceHandle"); 26 assert_true(handle instanceof MediaSourceHandle, "must be a MediaSourceHandle"); 27 t.done(); 28 break; 29 default: 30 assert_unreached("Unexpected message subject: " + subject); 31 32 } 33 }); 34 }, "Test main context receipt of postMessage'd MediaSourceHandle from DedicatedWorker MediaSource"); 35 36 test(t => { 37 assert_true(window.hasOwnProperty("MediaSourceHandle"), "window must have MediaSourceHandle"); 38 }, "Test main-thread has MediaSourceHandle defined"); 39 40 test(t => { 41 // Note, MSE spec may eventually describe how a main-thread MediaSource can 42 // attach to an HTMLMediaElement using a MediaSourceHandle. For now, we 43 // ensure that the implementation of this is not available per current spec. 44 assert_false( 45 "handle" in MediaSource.prototype, 46 "window MediaSource must not have handle in prototype"); 47 }, "Test main-thread MediaSource does not have handle getter"); 48 49 if (MediaSource.hasOwnProperty("canConstructInDedicatedWorker") && MediaSource.canConstructInDedicatedWorker === true) { 50 // If implementation claims support for MSE-in-Workers, then fetch and run 51 // some tests directly in another dedicated worker and get their results 52 // merged into those from this page. 53 fetch_tests_from_worker(new Worker("mediasource-worker-handle.js")); 54 } else { 55 // Otherwise, fetch and run a test that verifies lack of support of 56 // MediaSource construction in another dedicated worker. 57 fetch_tests_from_worker(new Worker("mediasource-worker-must-fail-if-unsupported.js")); 58 } 59 60 </script> 61 </html>