Index: third_party/WebKit/LayoutTests/media/media-fragments/media-fragments.js |
diff --git a/third_party/WebKit/LayoutTests/media/media-fragments/media-fragments.js b/third_party/WebKit/LayoutTests/media/media-fragments/media-fragments.js |
index d3c030215e3df7d560808a184c3896e8ce1332b4..fd6cc1e72d06a12602e2cc2db25aa377784ec474 100644 |
--- a/third_party/WebKit/LayoutTests/media/media-fragments/media-fragments.js |
+++ b/third_party/WebKit/LayoutTests/media/media-fragments/media-fragments.js |
@@ -1,4 +1,5 @@ |
- |
+ var video = null; |
+ var consoleDiv = null; |
var currentTest = null; |
var fragmentEndTime; |
var testData = |
@@ -75,6 +76,126 @@ |
TC0094 : { start: null, end: null, valid: false, description: "Trailing comma", fragment: "t=3,7,", comment: "UA knows that this is an invalid media fragment, so it will play the entire media resource."} |
}; |
+ logConsole(); |
+ if (window.testRunner) { |
+ testRunner.dumpAsText(); |
+ testRunner.waitUntilDone(); |
+ } |
+ |
+ function logConsole() |
+ { |
+ if (!consoleDiv && document.body) { |
+ consoleDiv = document.createElement('div'); |
+ document.body.appendChild(consoleDiv); |
+ } |
+ return consoleDiv; |
+ } |
+ |
+ function testExpected(testFuncString, expected, comparison) |
+ { |
+ try { |
+ var observed = eval(testFuncString); |
+ } catch (ex) { |
+ consoleWrite(ex); |
+ return; |
+ } |
+ |
+ if (comparison === undefined) |
+ comparison = '=='; |
+ |
+ var success = false; |
+ switch (comparison) |
+ { |
+ case '<': success = observed < expected; break; |
+ case '<=': success = observed <= expected; break; |
+ case '>': success = observed > expected; break; |
+ case '>=': success = observed >= expected; break; |
+ case '!=': success = observed != expected; break; |
+ case '==': success = observed == expected; break; |
+ case '===': success = observed === expected; break; |
+ } |
+ |
+ reportExpected(success, testFuncString, comparison, expected, observed) |
+ } |
+ |
+ var testNumber = 0; |
+ |
+ function reportExpected(success, testFuncString, comparison, expected, observed) |
+ { |
+ testNumber++; |
+ |
+ var msg = "Test " + testNumber; |
+ |
+ msg = "EXPECTED (<em>" + testFuncString + " </em>" + comparison + " '<em>" + expected + "</em>')"; |
+ |
+ if (!success) |
+ msg += ", OBSERVED '<em>" + observed + "</em>'"; |
+ |
+ logResult(success, msg); |
+ } |
+ |
+ function run(testFuncString) |
+ { |
+ consoleWrite("RUN(" + testFuncString + ")"); |
+ try { |
+ eval(testFuncString); |
+ } catch (ex) { |
+ consoleWrite(ex); |
+ } |
+ } |
+ |
+ function waitForEventOnce(eventName, func, endit, doNotLog) |
+ { |
+ waitForEvent(eventName, func, endit, true, null, doNotLog) |
+ } |
+ |
+ function waitForEvent(eventName, func, endit, oneTimeOnly, doNotLog) |
+ { |
+ function _eventCallback(event) |
+ { |
+ if (oneTimeOnly) |
+ video.removeEventListener(eventName, _eventCallback, true); |
+ |
+ if (!doNotLog) |
+ consoleWrite("EVENT(" + eventName + ")"); |
+ |
+ if (func) |
+ func(event); |
+ |
+ if (endit) |
+ endTest(); |
+ } |
+ |
+ video.addEventListener(eventName, _eventCallback, true); |
+ } |
+ |
+ var testEnded = false; |
+ |
+ function endTest() |
+ { |
+ consoleWrite("END OF TEST"); |
+ testEnded = true; |
+ if (window.testRunner) |
+ testRunner.notifyDone(); |
+ } |
+ |
+ function logResult(success, text) |
+ { |
+ if (success) |
+ consoleWrite(text + " <span style='color:green'>OK</span>"); |
+ else |
+ consoleWrite(text + " <span style='color:red'>FAIL</span>"); |
+ } |
+ |
+ function consoleWrite(text) |
+ { |
+ if (testEnded) |
+ return; |
+ var span = document.createElement("span"); |
+ logConsole().appendChild(span); |
+ span.innerHTML = text + '<br>'; |
+ } |
+ |
function pause() |
{ |
const maximumStopDelta = 0.5; |
@@ -130,4 +251,4 @@ |
consoleWrite("Comment: <i>" + info.comment + "</i>"); |
url = findMediaFile("video", "../content/counting") + "#" + info.fragment; |
video.src = url; |
- } |
+ } |