mobile/android/base/tests/testVideoDiscovery.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/tests/testVideoDiscovery.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     1.4 +// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +"use strict";
    1.10 +
    1.11 +const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
    1.12 +
    1.13 +Cu.import("resource://gre/modules/Services.jsm");
    1.14 +
    1.15 +function ok(passed, text) {
    1.16 +  do_report_result(passed, text, Components.stack.caller, false);
    1.17 +}
    1.18 +
    1.19 +// The chrome window
    1.20 +let chromeWin;
    1.21 +
    1.22 +// Track the <browser> where the tests are happening
    1.23 +let browser;
    1.24 +
    1.25 +function middle(element) {
    1.26 +  let rect = element.getBoundingClientRect();
    1.27 +  let x = (rect.right - rect.left) / 2 + rect.left;
    1.28 +  let y = (rect.bottom - rect.top) / 2 + rect.top;
    1.29 +  return [x, y];
    1.30 +}
    1.31 +
    1.32 +add_test(function setup_browser() {
    1.33 +  chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
    1.34 +  let BrowserApp = chromeWin.BrowserApp;
    1.35 +
    1.36 +  do_register_cleanup(function cleanup() {
    1.37 +    BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
    1.38 +  });
    1.39 +
    1.40 +  let url = "http://mochi.test:8888/tests/robocop/video_discovery.html";
    1.41 +  browser = BrowserApp.addTab(url, { selected: true, parentId: BrowserApp.selectedTab.id }).browser;
    1.42 +  browser.addEventListener("load", function startTests(event) {
    1.43 +    browser.removeEventListener("load", startTests, true);
    1.44 +    Services.tm.mainThread.dispatch(run_next_test, Ci.nsIThread.DISPATCH_NORMAL);
    1.45 +  }, true);
    1.46 +});
    1.47 +
    1.48 +let videoDiscoveryTests = [
    1.49 +  { id: "simple-mp4", source: "http://mochi.test:8888/simple.mp4", poster: "http://mochi.test:8888/simple.png", text: "simple video with mp4 src" },
    1.50 +  { id: "simple-fail", pass: false, text: "simple video with no mp4 src" },
    1.51 +  { id: "with-sources-mp4", source: "http://mochi.test:8888/simple.mp4", text: "video with mp4 extension source child" },
    1.52 +  { id: "with-sources-fail", pass: false, text: "video with no mp4 extension source child" },
    1.53 +  { id: "with-sources-mimetype", source: "http://mochi.test:8888/simple-video-mp4", text: "video with mp4 mimetype source child" },
    1.54 +  { id: "video-overlay", source: "http://mochi.test:8888/simple.mp4", text: "div overlay covering a simple video with mp4 src" }
    1.55 +];
    1.56 +
    1.57 +function execute_video_test(test) {
    1.58 +  let element = browser.contentDocument.getElementById(test.id);
    1.59 +  if (element) {
    1.60 +    let [x, y] = middle(element);
    1.61 +    let video = chromeWin.CastingApps.getVideo(element, x, y);
    1.62 +    if (video) {
    1.63 +      let matchPoster = (test.poster == video.poster);
    1.64 +      let matchSource = (test.source == video.source);
    1.65 +      ok(matchPoster && matchSource && test.pass, test.text);
    1.66 +    } else {
    1.67 +      ok(!test.pass, test.text);
    1.68 +    }
    1.69 +  } else {
    1.70 +    ok(false, "test element not found: [" + test.id + "]");
    1.71 +  }
    1.72 +  run_next_test();
    1.73 +}
    1.74 +
    1.75 +let videoTest;
    1.76 +while ((videoTest = videoDiscoveryTests.shift())) {
    1.77 +  if (!("poster" in videoTest)) {
    1.78 +    videoTest.poster = "";
    1.79 +  }
    1.80 +  if (!("pass" in videoTest)) {
    1.81 +    videoTest.pass = true;
    1.82 +  }
    1.83 +
    1.84 +  add_test(execute_video_test.bind(this, videoTest));
    1.85 +}
    1.86 +
    1.87 +run_next_test();

mercurial