Bug 1216047 - Add tests for BrowserApp.selectOrAddTab r=margaret
authorMark Finkle <mfinkle@mozilla.com>
Tue, 20 Oct 2015 01:09:30 -0400
changeset 268546 a47bbb36dbae9470bd2a390a8e99562d5e7447bd
parent 268545 3caf2963fc0a818798fff7260c5ca7ecc7423a7d
child 268547 ea6053144e51729eeb8fd23a0b88bcb103a3b803
push id29553
push userkwierso@gmail.com
push dateTue, 20 Oct 2015 21:53:11 +0000
treeherdermozilla-central@1b6d33aad425 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs1216047
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1216047 - Add tests for BrowserApp.selectOrAddTab r=margaret
mobile/android/tests/browser/chrome/chrome.ini
mobile/android/tests/browser/chrome/test_selectoraddtab.html
--- a/mobile/android/tests/browser/chrome/chrome.ini
+++ b/mobile/android/tests/browser/chrome/chrome.ini
@@ -22,13 +22,14 @@ support-files =
 [test_java_addons.html]
 [test_jni.html]
 [test_migrate_ui.html]
 [test_network_manager.html]
 [test_offline_page.html]
 [test_reader_view.html]
 [test_resource_substitutions.html]
 [test_restricted_profiles.html]
+[test_selectoraddtab.html]
 [test_session_form_data.html]
 [test_shared_preferences.html]
 [test_simple_discovery.html]
 [test_video_discovery.html]
 [test_web_channel.html]
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/browser/chrome/test_selectoraddtab.html
@@ -0,0 +1,105 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1216047
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1216047</title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="head.js"></script>
+  <script type="application/javascript;version=1.7">
+
+  "use strict";
+
+  const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+
+  Cu.import("resource://gre/modules/Services.jsm");
+  Cu.import("resource://gre/modules/Messaging.jsm");
+  Cu.import("resource://gre/modules/Task.jsm");
+
+  function promiseTabEvent(container, eventType) {
+    return new Promise((resolve) => {
+      function handle(event) {
+        info("Received event " + eventType + " from container");
+        container.removeEventListener(eventType, handle, true);
+        resolve(event);
+      }
+
+      container.addEventListener(eventType, handle, true);
+      info("Now waiting for " + eventType + " event from container");
+    });
+  }
+
+  // The chrome window
+  let chromeWin;
+
+  // Track the <browser>s where the tests are happening
+  let browserBlank;
+  let browserTest;
+
+  const kTestPage = "http://mochi.test:8888/chrome/mobile/android/tests/browser/chrome/basic_article.html";
+
+  add_task(function* test_selectOrAdd() {
+    chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
+    let BrowserApp = chromeWin.BrowserApp;
+
+    SimpleTest.registerCleanupFunction(function() {
+      BrowserApp.closeTab(BrowserApp.getTabForBrowser(browserBlank));
+      BrowserApp.closeTab(BrowserApp.getTabForBrowser(browserTest));
+    });
+
+    // Add a new tab with a blank page
+    browserBlank = BrowserApp.addTab("about:blank", { selected: true, parentId: BrowserApp.selectedTab.id }).browser;
+
+    // Now, let's force the target browser to be added
+    browserTest = BrowserApp.selectOrAddTab(kTestPage, { selected: true, parentId: BrowserApp.selectedTab.id }).browser;
+    yield promiseBrowserEvent(browserTest, "DOMContentLoaded");
+
+    // Check that basic_article is now selected
+    is(BrowserApp.selectedBrowser, browserTest, "Target browser is selected after being added.");
+
+    // Switch back to about:blank
+    BrowserApp.selectTab(BrowserApp.getTabForBrowser(browserBlank));
+    yield promiseTabEvent(BrowserApp.deck, "TabSelect");
+
+    // Check that about:blank is selected
+    is(BrowserApp.selectedBrowser, browserBlank, "about:blank is selected.");
+
+    // Use selectOrAddTab to select the existing tab
+    BrowserApp.selectOrAddTab(kTestPage, { selected: true, parentId: BrowserApp.selectedTab.id }).browser;
+    yield promiseTabEvent(BrowserApp.deck, "TabSelect");
+
+    // Check that basic_article is now selected
+    is(BrowserApp.selectedBrowser, browserTest, "Target browser is selected.");
+
+    // Switch back to about:blank
+    BrowserApp.selectTab(BrowserApp.getTabForBrowser(browserBlank));
+    yield promiseTabEvent(BrowserApp.deck, "TabSelect");
+
+    // Check that about:blank is selected
+    is(BrowserApp.selectedBrowser, browserBlank, "about:blank is selected.");
+
+    // Use selectOrAddTab to select the existing tab using the startsWith flag
+    BrowserApp.selectOrAddTab(kTestPage, { selected: true, parentId: BrowserApp.selectedTab.id }, { startsWith: kTestPage }).browser;
+    yield promiseTabEvent(BrowserApp.deck, "TabSelect");
+
+    // Check that basic_article is now selected
+    is(BrowserApp.selectedBrowser, browserTest, "Target browser is selected.");
+  });
+
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1216047">Mozilla Bug 1216047</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>