mediasource-worker-handle.js (3165B)
1 importScripts("/resources/testharness.js"); 2 3 test(t => { 4 // The Window test html conditionally fetches and runs these tests only if the 5 // implementation exposes a true-valued static canConstructInDedicatedWorker 6 // attribute on MediaSource in the Window context. So, the implementation must 7 // agree on support here in the dedicated worker context. 8 9 // Ensure we're executing in a dedicated worker context. 10 assert_true(self instanceof DedicatedWorkerGlobalScope, "self instanceof DedicatedWorkerGlobalScope"); 11 assert_true(MediaSource.hasOwnProperty("canConstructInDedicatedWorker", "DedicatedWorker MediaSource hasOwnProperty 'canConstructInDedicatedWorker'")); 12 assert_true(MediaSource.canConstructInDedicatedWorker, "DedicatedWorker MediaSource.canConstructInDedicatedWorker"); 13 }, "MediaSource in DedicatedWorker context must have true-valued canConstructInDedicatedWorker if Window context had it"); 14 15 test(t => { 16 assert_true( 17 'handle' in MediaSource.prototype, 18 'dedicated worker MediaSource must have handle in prototype'); 19 assert_true(self.hasOwnProperty("MediaSourceHandle"), "dedicated worker must have MediaSourceHandle visibility"); 20 }, 'MediaSource prototype in DedicatedWorker context must have \'handle\', and worker must have MediaSourceHandle'); 21 22 test(t => { 23 const ms = new MediaSource(); 24 assert_equals(ms.readyState, "closed"); 25 }, "MediaSource construction succeeds with initial closed readyState in DedicatedWorker"); 26 27 test(t => { 28 const ms = new MediaSource(); 29 const handle = ms.handle; 30 assert_not_equals(handle, null, 'must have a non-null \'handle\' attribute'); 31 assert_true(handle instanceof MediaSourceHandle, "must be a MediaSourceHandle"); 32 }, 'mediaSource.handle in DedicatedWorker returns a MediaSourceHandle'); 33 34 test(t => { 35 const msA = new MediaSource(); 36 const msB = new MediaSource(); 37 const handleA1 = msA.handle; 38 const handleA2 = msA.handle; 39 const handleA3 = msA['handle']; 40 const handleB1 = msB.handle; 41 const handleB2 = msB.handle; 42 assert_true( 43 handleA1 === handleA2 && handleB1 === handleB2 && handleA1 != handleB1, 44 'SameObject is observed for mediaSource.handle, and different MediaSource instances have different handles'); 45 assert_true( 46 handleA1 === handleA3, 47 'SameObject is observed even when accessing handle differently'); 48 assert_true( 49 handleA1 instanceof MediaSourceHandle && 50 handleB1 instanceof MediaSourceHandle, 51 'handle property returns MediaSourceHandles'); 52 }, 'mediaSource.handle observes SameObject property correctly'); 53 54 test(t => { 55 const ms1 = new MediaSource(); 56 const handle1 = ms1.handle; 57 const ms2 = new MediaSource(); 58 const handle2 = ms2.handle; 59 assert_true( 60 handle1 !== handle2, 61 'distinct MediaSource instances must have distinct handles'); 62 63 // Verify attempt to change value of the handle property does not succeed. 64 ms1.handle = handle2; 65 assert_true( 66 ms1.handle === handle1 && ms2.handle === handle2, 67 'MediaSource handle is readonly, so should not have changed'); 68 }, 'Attempt to set MediaSource handle property should fail to change it, since it is readonly'); 69 70 done();