5 video { background-color: yellow; width: 320px; height: 240px;}
7 <script src=media-file.js></script>
8 <script src=video-test.js></script>
11 <video controls ></video>
12 <p>Test to ensure that a media file blocked by a beforeload handler generates an error
13 and does not block the document's 'load' event.</p>
16 if (window.testRunner)
17 testRunner.dumpAsText();
22 var loadedmetadataFired = false;
23 var loadedFired = false;
25 function logEvent(evt)
27 consoleWrite("<br>EVENT('" + evt.type + "')");
30 function loadedmetadata(evt)
34 loadedmetadataFired = true;
38 function setupSourceTest()
40 consoleWrite("<br>*** Test using the <source> element ***");
41 blockedURL = relativeURL(video.src);
42 allowedURL = findMediaFile("audio", "content/test");
44 // Remove 'src' attribute so <source> will be used when we force a reload
45 video.removeAttribute('src');
47 var blockedSource = document.createElement('source');
48 blockedSource.src = blockedURL;
49 blockedSource.type = mimeTypeForExtension(blockedSource.src.split('.').pop());
50 video.appendChild(blockedSource);
52 var allowedSource = document.createElement('source');
53 allowedSource.src = allowedURL;
54 allowedSource.type = mimeTypeForExtension(allowedSource.src.split('.').pop());
55 video.appendChild(allowedSource);
67 testExpected("event.target.tagName", "VIDEO");
68 testExpected("video.error", null, "!=");
69 testExpected("video.error.code", MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED);
70 testExpected("video.networkState", HTMLMediaElement.NETWORK_NO_SOURCE);
75 // The error should have been fired at the <source> and the media element should
76 // not be in an error state.
77 testExpected("event.target.tagName", "SOURCE");
78 testExpected("video.error", null);
81 failTest("Unexpected 'error' event fired!");
86 function beforeload(evt)
89 testExpected("event.target.tagName", "VIDEO");
93 consoleWrite("blocking load of 'src'");
98 if (relativeURL(evt.url) == blockedURL) {
99 consoleWrite("blocking load of first <source> element");
100 evt.preventDefault();
102 consoleWrite("allowing load of second <source> element");
114 function checkEndTest()
116 if (loadedmetadataFired && loadedFired)
122 video.addEventListener('loadstart', logEvent, true);
123 video.addEventListener('loadedmetadata', loadedmetadata, true);
124 video.addEventListener('beforeload', beforeload, true);
125 video.addEventListener('error', error, true);
126 window.addEventListener('load', loaded, true);
128 consoleWrite("*** Test initial state ***");
129 testExpected("video.networkState", HTMLMediaElement.NETWORK_EMPTY);
130 testExpected("video.error", null);
132 consoleWrite("<br>*** Test blocking the 'src' attribute ***");
134 var mediaFile = findMediaFile("video", "content/test");
135 video.src = mediaFile;