Bug 953381 - video discovery tests r=wesj

This commit is contained in:
Mark Finkle 2014-01-20 17:22:05 -05:00
parent 880cbf8cb5
commit 0971eea68b
4 changed files with 155 additions and 0 deletions

View File

@ -79,6 +79,7 @@ skip-if = processor == "x86"
[testSharedPreferences]
[testSimpleDiscovery]
[testUITelemetry]
[testVideoDiscovery]
# Used for Talos, please don't use in mochitest
#[testPan]

View File

@ -0,0 +1,10 @@
package org.mozilla.gecko.tests;
import org.mozilla.gecko.*;
public class testVideoDiscovery extends JavascriptTest {
public testVideoDiscovery() {
super("testVideoDiscovery.js");
}
}

View File

@ -0,0 +1,84 @@
// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
Cu.import("resource://gre/modules/Services.jsm");
function ok(passed, text) {
do_report_result(passed, text, Components.stack.caller, false);
}
// The chrome window
let chromeWin;
// Track the <browser> where the tests are happening
let browser;
function middle(element) {
let rect = element.getBoundingClientRect();
let x = (rect.right - rect.left) / 2 + rect.left;
let y = (rect.bottom - rect.top) / 2 + rect.top;
return [x, y];
}
add_test(function setup_browser() {
chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
let BrowserApp = chromeWin.BrowserApp;
do_register_cleanup(function cleanup() {
BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
});
let url = "http://mochi.test:8888/tests/robocop/video_discovery.html";
browser = BrowserApp.addTab(url, { selected: true, parentId: BrowserApp.selectedTab.id }).browser;
browser.addEventListener("load", function startTests(event) {
browser.removeEventListener("load", startTests, true);
Services.tm.mainThread.dispatch(run_next_test, Ci.nsIThread.DISPATCH_NORMAL);
}, true);
});
let videoDiscoveryTests = [
{ id: "simple-mp4", source: "http://mochi.test:8888/simple.mp4", poster: "http://mochi.test:8888/simple.png", text: "simple video with mp4 src" },
{ id: "simple-fail", pass: false, text: "simple video with no mp4 src" },
{ id: "with-sources-mp4", source: "http://mochi.test:8888/simple.mp4", text: "video with mp4 extension source child" },
{ id: "with-sources-fail", pass: false, text: "video with no mp4 extension source child" },
{ id: "with-sources-mimetype", source: "http://mochi.test:8888/simple-video-mp4", text: "video with mp4 mimetype source child" },
{ id: "video-overlay", source: "http://mochi.test:8888/simple.mp4", text: "div overlay covering a simple video with mp4 src" }
];
function execute_video_test(test) {
let element = browser.contentDocument.getElementById(test.id);
if (element) {
let [x, y] = middle(element);
let video = chromeWin.CastApps.getVideo(element, x, y);
if (video) {
let matchPoster = (test.poster == video.poster);
let matchSource = (test.source == video.source);
ok(matchPoster && matchSource && test.pass, test.text);
} else {
ok(!test.pass, test.text);
}
} else {
ok(false, "test element not found: [" + test.id + "]");
}
run_next_test();
}
let videoTest;
while ((videoTest = videoDiscoveryTests.shift())) {
if (!("poster" in videoTest)) {
videoTest.poster = "";
}
if (!("pass" in videoTest)) {
videoTest.pass = true;
}
add_test(execute_video_test.bind(this, videoTest));
}
run_next_test();

View File

@ -0,0 +1,60 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Video Discovery Test</title>
<style type="text/css">
#video-box {
float: left;
}
#video-overlay, #video-player {
width: 640px;
min-height: 370px;
}
#video-overlay {
position: absolute;
float: left;
background-color:#f00;
z-index:10;
}
</style>
</head>
<body>
<!-- PASS: src uses a mp4 extension -->
<video id="simple-mp4" poster="/simple.png" src="/simple.mp4"></video>
<!-- FAIL: src uses a ogg extension -->
<video id="simple-fail" src="/simple.ogg"></video>
<!-- PASS: source list uses a mp4 extension -->
<video id="with-sources-mp4">
<source src="/simple.ogg">
<source src="/simple.mp4">
</video>
<!-- FAIL: source list uses a mp4 extension -->
<video id="with-sources-fail">
<source src="/simple.ogg">
<source src="/simple.webm">
</video>
<!-- PASS: source list uses a mp4 mimetype -->
<video id="with-sources-mimetype">
<source src="/simple-video-ogg" type="video/ogg">
<source src="/simple-video-mp4" type="video/mp4">
</video>
<!-- PASS: source list uses a mp4 mimetype and extra data -->
<video id="with-sources-mimetype-plus">
<source src="/simple-video-ogg" type="video/ogg">
<source src="/simple-video-mp4" type="video/mp4; codecs='avc1.42E01E, mp4a.40.2'">
</video>
<!-- PASS: div overlay covers a video with mp4 src -->
<div id="video-box">
<div id="video-overlay"></div>
<div>
<video id="video-player" src="/simple.mp4"></video>
</div>
</div>
</body>
</html>