Update WPT tests for embedded content
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / html / semantics / embedded-content / media-elements / loading-the-media-resource / resource-selection-invoke-insert-source-networkState.html
1 <!doctype html>
2 <title>NOT invoking resource selection by inserting &lt;source> when networkState is not NETWORK_EMPTY</title>
3 <script src="/resources/testharness.js"></script>
4 <script src="/resources/testharnessreport.js"></script>
5 <div id=log></div>
6 <script>
7 var loadstartCount = 0;
8 var s1ErrorCount = 0;
9 var s2ErrorCount = 0;
10 var v;
11 var t = async_test(function(t) {
12   v = document.createElement('video');
13   v.onloadstart = function() { loadstartCount++; };
14   var s1 = document.createElement('source');
15   s1.src = 'resources/delayed-broken-video.py';
16   s1.onerror = function() { s1ErrorCount++; };
17   v.appendChild(s1); // invokes resource selection
18   assert_equals(v.networkState, v.NETWORK_NO_SOURCE, 'networkState in first script');
19 });
20 </script>
21 <script>
22 t.step(function() {
23   assert_equals(v.networkState, v.NETWORK_LOADING, 'networkState in second script');
24   assert_equals(s1ErrorCount, 0, 's1ErrorCount in second script');
25   var s2 = document.createElement('source');
26   s2.onerror = t.step_func(function() {
27     s2ErrorCount++;
28     assert_equals(s1ErrorCount, 1, 's1ErrorCount in s2.onerror');
29   });
30   v.appendChild(s2);
31   onload = t.step_func(function() {
32     assert_equals(s2ErrorCount, 1, 's2ErrorCount in window.onload');
33     assert_equals(loadstartCount, 1, 'loadstartCount in window.onload'); // reliable if https://www.w3.org/Bugs/Public/show_bug.cgi?id=24353 is fixed
34     assert_equals(v.networkState, v.NETWORK_NO_SOURCE, 'networkState in window.onload'); // See Waiting step
35     t.done();
36   });
37 });
38 </script>