load-events-networkState.html (2811B)
1 <!doctype html> 2 <title>load() fires abort/emptied events when networkState is not NETWORK_EMPTY</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="/common/media.js"></script> 6 <div id=log></div> 7 <script> 8 // Load media resource 9 // https://html.spec.whatwg.org/multipage/media.html#loading-the-media-resource 10 function load_test(t, v) { 11 assert_not_equals(v.networkState, v.NETWORK_EMPTY); 12 13 var expected_events = []; 14 if (v.networkState == v.NETWORK_LOADING || v.networkState == v.NETWORK_IDLE) { 15 expected_events.push('abort'); 16 } 17 18 if (v.networkState != v.NETWORK_EMPTY) { 19 expected_events.push('emptied'); 20 } 21 22 if (v.currentTime != 0.0) { 23 expected_events.push('timeupdate'); 24 } 25 26 var actual_events = []; 27 v.onabort = v.onemptied = v.ontimeupdate = t.step_func(function(e) { 28 actual_events.push(e.type); 29 }); 30 31 v.onloadstart = t.step_func(function() { 32 assert_array_equals(actual_events, expected_events); 33 t.done(); 34 }); 35 36 v.load(); 37 38 assert_array_equals(actual_events, [], 'events should be fired in queued tasks'); 39 } 40 41 async_test(function(t) { 42 var v = document.createElement('video'); 43 // suspend is fired optionally "if the user agent intends to not attempt to 44 // fetch the resource" or "once the entire media resource has been fetched" 45 v.preload = 'none'; 46 v.src = getAudioURI('/media/sound_5'); 47 v.onerror = t.unreached_func(); 48 v.onsuspend = t.step_func(function() { 49 v.onsuspend = null; 50 assert_equals(v.networkState, v.NETWORK_IDLE); 51 load_test(t, v); 52 }); 53 }, 'NETWORK_IDLE'); 54 55 // Test if media element receives `emptied` before `timeupdate` 56 async_test(function(t) { 57 var v = document.createElement('video'); 58 v.src = getAudioURI('/media/sound_5'); 59 v.onerror = t.unreached_func(); 60 v.onloadeddata = t.step_func(function() { 61 v.onloadeddata = null; 62 assert_not_equals(v.networkState, v.NETWORK_EMPTY); 63 // Modify current time to ensure that loading would trigger `timeupdate` by 64 // resetting the current time. 65 v.currentTime = 1.0; 66 load_test(t, v); 67 }); 68 }, 'NETWORK_DISPATCH_EMPTIED_BEFORE_TIMEUPDATE'); 69 70 async_test(function(t) { 71 var v = document.createElement('video'); 72 v.src = 'resources/delayed-broken-video.py'; 73 v.onerror = t.unreached_func(); 74 v.onloadstart = t.step_func(function() { 75 v.onloadstart = null; 76 assert_equals(v.networkState, v.NETWORK_LOADING); 77 load_test(t, v); 78 }); 79 }, 'NETWORK_LOADING'); 80 81 async_test(function(t) { 82 var v = document.createElement('video'); 83 v.src = 'data:,'; 84 v.onerror = t.step_func(function() { 85 v.onerror = null; 86 assert_equals(v.networkState, v.NETWORK_NO_SOURCE); 87 load_test(t, v); 88 }); 89 assert_equals(v.networkState, v.NETWORK_NO_SOURCE); 90 }, 'NETWORK_NO_SOURCE'); 91 </script>