Index: third_party/WebKit/LayoutTests/media/video-src-change.html |
diff --git a/third_party/WebKit/LayoutTests/media/video-src-change.html b/third_party/WebKit/LayoutTests/media/video-src-change.html |
index 1b0f82eab1602ece2f9fa653388e12ec96ddde6b..5cd6604b92c41defcfe80e7e64729898ab42f003 100644 |
--- a/third_party/WebKit/LayoutTests/media/video-src-change.html |
+++ b/third_party/WebKit/LayoutTests/media/video-src-change.html |
@@ -1,71 +1,43 @@ |
-<html> |
- <head> |
- <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 |
- (Please avoid writing new tests using video-test.js) --> |
- <script src=video-test.js></script> |
- <script src=media-file.js></script> |
- <script> |
- var mediaFile; |
- var loadedCount = 0; |
- var errorCount = 0; |
- |
- function errorEvent() |
- { |
- testExpected("relativeURL(video.currentSrc)", "bogus"); |
- testExpected("video.networkState", HTMLMediaElement.NETWORK_NO_SOURCE); |
- testExpected("video.error.code", MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED); |
- consoleWrite(""); |
- |
- // Prevent runaway tests when unexpected errors happen. |
- if (++errorCount > 1) |
- endTest(); |
- |
- setSrcAttribure(findMediaFile("video", "content/test")); |
- consoleWrite(""); |
- } |
- |
- function loadedmetadata() |
- { |
- testExpected("stripExtension(relativeURL(video.currentSrc))", stripExtension(mediaFile)); |
- testExpected("isNaN(video.duration)", false); |
- consoleWrite(""); |
- |
- if (++loadedCount >= 2) { |
- mediaElement.removeEventListener('loadedmetadata', loadedmetadata); |
- endTest(); |
- return; |
- } |
- |
- setSrcAttribure(findMediaFile("video", "content/counting")); |
- consoleWrite(""); |
- } |
- |
- function setSrcAttribure(src) |
- { |
- mediaFile = src; |
- video.setAttribute('src', src); |
- } |
- |
- function setup() |
- { |
- findMediaElement(); |
- waitForEvent('loadedmetadata', loadedmetadata); |
- waitForEvent('error', errorEvent); |
- setSrcAttribure("bogus"); |
- consoleWrite(""); |
- } |
- </script> |
- </head> |
- |
-<body onload="setup()"> |
- |
- <video controls" ></video> |
- |
- <p> |
- 1. Test that an invalid src attribute fires an error when the file fails to load.<br> |
- 2. Test that changing src attribute triggers load after a load fails.<br> |
- 3. Test that changing src triggers load once a file is known to be valid. |
- </p> |
- |
-</body> |
-</html> |
+<!DOCTYPE html> |
+<title>Test that an invalid "src" fires an error event and changing "src" to a valid one triggers media load.</title> |
+<script src="../resources/testharness.js"></script> |
+<script src="../resources/testharnessreport.js"></script> |
+<script src="media-file.js"></script> |
+<video></video> |
+<script> |
+// 1. Test that an invalid src attribute fires an error when the file fails to load. |
+// 2. Test that changing src attribute triggers load after a load fails. |
+// 3. Test that changing src triggers load once a file is known to be valid. |
+async_test(function(t) { |
+ var mediaFile; |
+ var loadedCount = 0; |
+ var video = document.querySelector("video"); |
+ |
+ video.onloadedmetadata = t.step_func(function() { |
+ var url = video.currentSrc; |
+ assert_equals(url.substr(url.lastIndexOf("/media/")+7), mediaFile); |
+ assert_false(isNaN(video.duration)); |
+ |
+ if (++loadedCount == 2) { |
+ t.done(); |
+ return; |
+ } |
+ |
+ mediaFile = findMediaFile("video", "content/counting"); |
+ video.src = mediaFile; |
+ }); |
+ |
+ video.onerror = t.step_func(function() { |
+ assert_equals(loadedCount, 0); |
+ var url = video.currentSrc; |
+ assert_equals(url.substr(url.lastIndexOf("/media/")+7), "bogus"); |
+ assert_equals(video.networkState, HTMLMediaElement.NETWORK_NO_SOURCE); |
+ assert_equals(video.error.code, MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED); |
+ mediaFile = findMediaFile("video", "content/test"); |
+ video.src = mediaFile; |
+ }); |
+ |
+ mediaFile = "bogus"; |
+ video.src = mediaFile; |
+}); |
+</script> |