Skip to content
Permalink
Browse files
[mediacontrols] Improve media controls testing helpers
https://bugs.webkit.org/show_bug.cgi?id=148697
<rdar://problem/22530876>

Reviewed by Eric Carlson.

Implement a more modern-looking testing API for media
controls tests, and update the existing tests to
use the new API.

* media/controls/basic-expected.txt:
* media/controls/basic.html:
* media/controls/controls-test-helpers.js:
(ControlsTest): New class for helping testing.
(statusForControlsElement): Deleted.
* media/controls/showControlsButton-expected.txt:
* media/controls/showControlsButton.html:
* media/controls/statusDisplay-expected.txt:
* media/controls/statusDisplay.html:
* media/controls/statusDisplayBad-expected.txt:
* media/controls/statusDisplayBad.html:

Canonical link: https://commits.webkit.org/166832@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189254 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
grorg committed Sep 2, 2015
1 parent d9f6a6e commit 56e773dd991ee43ea47e7f617308d997e99541cf
Showing 10 changed files with 304 additions and 125 deletions.
@@ -1,3 +1,27 @@
2015-09-01 Dean Jackson <dino@apple.com>

[mediacontrols] Improve media controls testing helpers
https://bugs.webkit.org/show_bug.cgi?id=148697
<rdar://problem/22530876>

Reviewed by Eric Carlson.

Implement a more modern-looking testing API for media
controls tests, and update the existing tests to
use the new API.

* media/controls/basic-expected.txt:
* media/controls/basic.html:
* media/controls/controls-test-helpers.js:
(ControlsTest): New class for helping testing.
(statusForControlsElement): Deleted.
* media/controls/showControlsButton-expected.txt:
* media/controls/showControlsButton.html:
* media/controls/statusDisplay-expected.txt:
* media/controls/statusDisplay.html:
* media/controls/statusDisplayBad-expected.txt:
* media/controls/statusDisplayBad.html:

2015-09-02 Chris Dumez <cdumez@apple.com>

document.createProcessingInstruction() does not behave according to specification
@@ -3,8 +3,8 @@ This is a basic test of the internal controls status API.
This test only runs in DRT!


EVENT(canplaythrough)
TEST(currentStatus != null) OK
EXPECTED (currentStatus.status == 'ok') OK
END OF TEST
EVENT: canplaythrough
PASS: Check that status is ok

Testing finished.

@@ -2,34 +2,24 @@
<html>
<head>
<script src="../media-file.js"></script>
<script src="../video-test.js"></script>
<script src="controls-test-helpers.js"></script>
<script>
var video;
var currentStatus;
var tester = new ControlsTest()
.whenReady(runTests)
.start();

function init()
function runTests()
{
findMediaElement();
video.src = findMediaFile("video", "../content/test");
currentState = tester.currentState;
tester.test("Check that status is ok")
.value(currentState.status)
.isEqualTo("ok");

waitForEvent("canplaythrough", canplaythrough);
waitForEventAndFail("error");
}

function canplaythrough()
{
if (!window.testRunner)
return;

currentStatus = JSON.parse(internals.getCurrentMediaControlsStatusForElement(video));
test("currentStatus != null");
if (currentStatus)
testExpected("currentStatus.status", "ok");
endTest();
tester.end();
}
</script>
</head>
<body onload="init()">
<body>
<p>This is a basic test of the internal controls status API.</p>
<p>This test only runs in DRT!</p>
<video controls></video>
@@ -1,10 +1,170 @@
function statusForControlsElement(statusObject, elementName)
{
if (statusObject.elements && statusObject.elements.length) {
for (var i = 0; i < statusObject.elements.length; i++) {
if (statusObject.elements[i].name == elementName)
return statusObject.elements[i];
ControlsTest = class ControlsTest {
constructor(mediaURL, eventTrigger)
{
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}

this.callback = null;
this.mediaURL = mediaURL || "../content/test";
this.eventTrigger = eventTrigger || "canplaythrough";
this.currentMessage = "";
this.currentValue = null;
}
return null;

whenReady(callback)
{
if (typeof callback == "function")
this.callback = callback;
return this;
}

get currentState()
{
if (!this.media)
return null;

if (window.internals)
return JSON.parse(internals.getCurrentMediaControlsStatusForElement(this.media));

// This is only for fallback testing. Even then it is pretty useless.
return { idiom: "apple", status: "fail" };
}

stateForControlsElement(elementName)
{
var state = this.currentState;
if (state.elements && state.elements.length) {
for (var i = 0; i < state.elements.length; i++) {
if (state.elements[i].name == elementName)
return state.elements[i];
}
}
return null;
}

handleEvent(event)
{
this.logMessage(`EVENT: ${event.type}`);
if (event.type == this.eventTrigger && this.callback)
this.callback();
}

logSuccess(msg)
{
this.logMessage(`PASS: ${msg}`);
}

logFailure(msg)
{
this.logMessage(`FAIL: ${msg}`);
}

logMessage(msg)
{
this.console.appendChild(document.createTextNode(msg));
this.logBlankLine();
}

logBlankLine()
{
this.console.appendChild(document.createElement("br"));
}

startNewSection(msg)
{
this.logBlankLine();
this.logMessage(msg);
this.logBlankLine();
}

setup()
{
if (!window.testRunner) {
this.logFailure("Test requires DRT.");
return false;
}

this.console = document.createElement("div");
this.console.className = "console";
document.body.appendChild(this.console);

this.media = document.querySelector("video");

if (!this.media) {
this.logFailure("Unable to find media element");
this.end();
return false;
}

this.media.addEventListener(this.eventTrigger, this, false);
this.media.src = findMediaFile("video", this.mediaURL);

return true;
}

start(msg)
{
window.addEventListener("load", function () {
this.setup();
if (msg)
this.startNewSection(msg);
}.bind(this), false);
return this;
}

end()
{
this.logMessage("");
this.logMessage("Testing finished.");
if (window.testRunner)
testRunner.notifyDone();
return this;
}

test(message)
{
this.currentMessage = message;
return this;
}

value(newValue)
{
this.currentValue = newValue;
return this;
}

isEqualTo(value)
{
if (this.currentValue == value)
this.logSuccess(this.currentMessage);
else
this.logFailure(`${this.currentMessage} Expected: "${value}". Actual: "${this.currentValue}"`);
}

isEmptyString()
{
if (!this.currentValue && typeof this.currentValue == "string")
this.logSuccess(this.currentMessage);
else
this.logFailure(`${this.currentMessage} Expected an empty string. Actual: "${this.currentValue}"`);
}

isTrue()
{
if (this.currentValue)
this.logSuccess(this.currentMessage);
else
this.logFailure(`${this.currentMessage} Expected a true value. Actual: "${this.currentValue}"`);
}

isFalse()
{
if (!this.currentValue)
this.logSuccess(this.currentMessage);
else
this.logFailure(`${this.currentMessage} Expected a false value. Actual: "${this.currentValue}"`);
}

}
@@ -3,8 +3,16 @@ This tests for the existence of a hidden Show Controls button.
This test only runs in DRT!


EVENT(canplaythrough)
EXPECTED (showControlsButtonInfo.name == 'Show Controls') OK
EXPECTED (showControlsButtonInfo.hidden == 'true') OK
END OF TEST

Test for Show Controls button

EVENT: canplaythrough
PASS: We are using the apple idiom

Get the button that shows controls while in Voice Over

PASS: Name is 'Show Controls'
PASS: Is hidden

Testing finished.

@@ -2,42 +2,35 @@
<html>
<head>
<script src="../media-file.js"></script>
<script src="../video-test.js"></script>
<script src="controls-test-helpers.js"></script>
<script>
var video;
var currentStatus;
var showControlsButtonInfo;
var tester = new ControlsTest()
.whenReady(runTests)
.start("Test for Show Controls button");

function init()
function runTests()
{
findMediaElement();
video.src = findMediaFile("video", "../content/test");
currentState = tester.currentState;
tester.test("We are using the apple idiom")
.value(currentState.idiom)
.isEqualTo("apple");

waitForEvent("canplaythrough", canplaythrough);
waitForEventAndFail("error");
}
tester.startNewSection("Get the button that shows controls while in Voice Over");
var controlsButtonState = tester.stateForControlsElement("Show Controls");

function canplaythrough()
{
if (!window.testRunner)
return;
tester.test("Name is 'Show Controls'")
.value(controlsButtonState.name)
.isEqualTo("Show Controls");

tester.test("Is hidden")
.value(controlsButtonState.hidden)
.isTrue();

currentStatus = JSON.parse(internals.getCurrentMediaControlsStatusForElement(video));
if (currentStatus) {
if (currentStatus.idiom == "apple") {
showControlsButtonInfo = statusForControlsElement(currentStatus, "Show Controls");
if (showControlsButtonInfo) {
testExpected("showControlsButtonInfo.name", "Show Controls");
testExpected("showControlsButtonInfo.hidden", true);
}
}
}
endTest();
tester.end();
}
</script>
</head>
<body onload="init()">
<body>
<p>This tests for the existence of a hidden Show Controls button.</p>
<p>This test only runs in DRT!</p>
<video controls></video>
@@ -3,9 +3,14 @@ This tests for the content in the status display.
This test only runs in DRT!


EVENT(canplaythrough)
EXPECTED (statusDisplayInfo.name == 'Status Display') OK
EXPECTED (statusDisplayInfo.className == 'hidden') OK
EXPECTED (statusDisplayInfo.content == '') OK
END OF TEST
EVENT: canplaythrough
PASS: We are using the apple idiom

Get the status label state

PASS: Name is 'Status Display'
PASS: Has hidden class
PASS: Content is Empty

Testing finished.

0 comments on commit 56e773d

Please sign in to comment.