mobile/android/base/tests/testVideoDiscovery.js

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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

mercurial