mobile/android/base/tests/testVideoDiscovery.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 "use strict";
michael@0 7
michael@0 8 const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
michael@0 9
michael@0 10 Cu.import("resource://gre/modules/Services.jsm");
michael@0 11
michael@0 12 function ok(passed, text) {
michael@0 13 do_report_result(passed, text, Components.stack.caller, false);
michael@0 14 }
michael@0 15
michael@0 16 // The chrome window
michael@0 17 let chromeWin;
michael@0 18
michael@0 19 // Track the <browser> where the tests are happening
michael@0 20 let browser;
michael@0 21
michael@0 22 function middle(element) {
michael@0 23 let rect = element.getBoundingClientRect();
michael@0 24 let x = (rect.right - rect.left) / 2 + rect.left;
michael@0 25 let y = (rect.bottom - rect.top) / 2 + rect.top;
michael@0 26 return [x, y];
michael@0 27 }
michael@0 28
michael@0 29 add_test(function setup_browser() {
michael@0 30 chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
michael@0 31 let BrowserApp = chromeWin.BrowserApp;
michael@0 32
michael@0 33 do_register_cleanup(function cleanup() {
michael@0 34 BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
michael@0 35 });
michael@0 36
michael@0 37 let url = "http://mochi.test:8888/tests/robocop/video_discovery.html";
michael@0 38 browser = BrowserApp.addTab(url, { selected: true, parentId: BrowserApp.selectedTab.id }).browser;
michael@0 39 browser.addEventListener("load", function startTests(event) {
michael@0 40 browser.removeEventListener("load", startTests, true);
michael@0 41 Services.tm.mainThread.dispatch(run_next_test, Ci.nsIThread.DISPATCH_NORMAL);
michael@0 42 }, true);
michael@0 43 });
michael@0 44
michael@0 45 let videoDiscoveryTests = [
michael@0 46 { id: "simple-mp4", source: "http://mochi.test:8888/simple.mp4", poster: "http://mochi.test:8888/simple.png", text: "simple video with mp4 src" },
michael@0 47 { id: "simple-fail", pass: false, text: "simple video with no mp4 src" },
michael@0 48 { id: "with-sources-mp4", source: "http://mochi.test:8888/simple.mp4", text: "video with mp4 extension source child" },
michael@0 49 { id: "with-sources-fail", pass: false, text: "video with no mp4 extension source child" },
michael@0 50 { id: "with-sources-mimetype", source: "http://mochi.test:8888/simple-video-mp4", text: "video with mp4 mimetype source child" },
michael@0 51 { id: "video-overlay", source: "http://mochi.test:8888/simple.mp4", text: "div overlay covering a simple video with mp4 src" }
michael@0 52 ];
michael@0 53
michael@0 54 function execute_video_test(test) {
michael@0 55 let element = browser.contentDocument.getElementById(test.id);
michael@0 56 if (element) {
michael@0 57 let [x, y] = middle(element);
michael@0 58 let video = chromeWin.CastingApps.getVideo(element, x, y);
michael@0 59 if (video) {
michael@0 60 let matchPoster = (test.poster == video.poster);
michael@0 61 let matchSource = (test.source == video.source);
michael@0 62 ok(matchPoster && matchSource && test.pass, test.text);
michael@0 63 } else {
michael@0 64 ok(!test.pass, test.text);
michael@0 65 }
michael@0 66 } else {
michael@0 67 ok(false, "test element not found: [" + test.id + "]");
michael@0 68 }
michael@0 69 run_next_test();
michael@0 70 }
michael@0 71
michael@0 72 let videoTest;
michael@0 73 while ((videoTest = videoDiscoveryTests.shift())) {
michael@0 74 if (!("poster" in videoTest)) {
michael@0 75 videoTest.poster = "";
michael@0 76 }
michael@0 77 if (!("pass" in videoTest)) {
michael@0 78 videoTest.pass = true;
michael@0 79 }
michael@0 80
michael@0 81 add_test(execute_video_test.bind(this, videoTest));
michael@0 82 }
michael@0 83
michael@0 84 run_next_test();

mercurial