Bug 1479746 - (part 2) Add test for routes. r=jdescottes,daisuke
authorBelén Albeza <balbeza@mozilla.com>
Tue, 27 Nov 2018 12:08:04 +0000
changeset 507461 1932b5f4e83771722ac243e4433d16e4d3875859
parent 507460 cc18f53a55f09bbe03416841f4718d8c983f9a35
child 507462 99fb2b79579902eb3365c87202ad3deea9c484af
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes, daisuke
bugs1479746
milestone65.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 1479746 - (part 2) Add test for routes. r=jdescottes,daisuke Differential Revision: https://phabricator.services.mozilla.com/D12316
devtools/client/aboutdebugging-new/test/browser/browser.ini
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_addons_usb_runtime.js
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_debug-target-pane_usb_runtime.js
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_persist_connection.js
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_routes.js
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_usb_runtime_refresh.js
devtools/client/aboutdebugging-new/test/browser/head.js
--- a/devtools/client/aboutdebugging-new/test/browser/browser.ini
+++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini
@@ -23,16 +23,17 @@ support-files =
 skip-if = (os == 'linux' && bits == 32) # ADB start() fails on linux 32, see Bug 1499638
 [browser_aboutdebugging_connection_prompt_setting.js]
 [browser_aboutdebugging_debug-target-pane_collapsibilities_interaction.js]
 [browser_aboutdebugging_debug-target-pane_collapsibilities_preference.js]
 [browser_aboutdebugging_debug-target-pane_empty.js]
 [browser_aboutdebugging_debug-target-pane_usb_runtime.js]
 [browser_aboutdebugging_navigate.js]
 [browser_aboutdebugging_persist_connection.js]
+[browser_aboutdebugging_routes.js]
 [browser_aboutdebugging_sidebar_network_runtimes.js]
 [browser_aboutdebugging_sidebar_usb_runtime.js]
 [browser_aboutdebugging_sidebar_usb_runtime_connect.js]
 [browser_aboutdebugging_sidebar_usb_runtime_refresh.js]
 [browser_aboutdebugging_sidebar_usb_status.js]
 skip-if = (os == 'linux' && bits == 32) # ADB start() fails on linux 32, see Bug 1499638
 [browser_aboutdebugging_system_addons.js]
 [browser_aboutdebugging_tab_favicons.js]
--- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_addons_usb_runtime.js
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_addons_usb_runtime.js
@@ -19,17 +19,18 @@ add_task(async function() {
   const { document, tab } = await openAboutDebugging();
 
   const usbClient = usbMocks.createRuntime(RUNTIME_ID, {
     deviceName: RUNTIME_DEVICE_NAME,
     name: RUNTIME_APP_NAME,
   });
   usbMocks.emitUpdate();
 
-  await connectToRuntime(RUNTIME_DEVICE_NAME, RUNTIME_APP_NAME, document);
+  await connectToRuntime(RUNTIME_DEVICE_NAME, document);
+  await selectRuntime(RUNTIME_DEVICE_NAME, RUNTIME_APP_NAME, document);
 
   const extensionPane = getDebugTargetPane("Extensions", document);
   info("Check an empty target pane message is displayed");
   ok(extensionPane.querySelector(".js-debug-target-list-empty"),
     "Extensions list is empty");
 
   info("Add an extension to the remote client");
   const addon = { name: "Test extension name", debuggable: true };
--- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_debug-target-pane_usb_runtime.js
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_debug-target-pane_usb_runtime.js
@@ -21,17 +21,18 @@ add_task(async function() {
   const { document, tab } = await openAboutDebugging();
 
   usbMocks.createRuntime(RUNTIME_ID, {
     deviceName: RUNTIME_DEVICE_NAME,
     name: RUNTIME_APP_NAME,
   });
   usbMocks.emitUpdate();
 
-  await connectToRuntime(RUNTIME_DEVICE_NAME, RUNTIME_APP_NAME, document);
+  await connectToRuntime(RUNTIME_DEVICE_NAME, document);
+  await selectRuntime(RUNTIME_DEVICE_NAME, RUNTIME_APP_NAME, document);
 
   const SUPPORTED_TARGET_PANES = [
     "Extensions",
     "Tabs",
   ];
 
   for (const { title } of TARGET_PANES) {
     const debugTargetPaneEl = getDebugTargetPane(title, document);
--- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_persist_connection.js
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_persist_connection.js
@@ -19,17 +19,18 @@ add_task(async function() {
   let { document, tab } = await openAboutDebugging();
 
   const usbClient = usbMocks.createRuntime(RUNTIME_ID, {
     name: RUNTIME_APP_NAME,
     deviceName: RUNTIME_DEVICE_NAME,
   });
   usbMocks.emitUpdate();
 
-  await connectToRuntime(RUNTIME_DEVICE_NAME, RUNTIME_APP_NAME, document);
+  await connectToRuntime(RUNTIME_DEVICE_NAME, document);
+  await selectRuntime(RUNTIME_DEVICE_NAME, RUNTIME_APP_NAME, document);
 
   info("Reload about:debugging");
   document = await reloadAboutDebugging(tab);
   usbMocks.emitUpdate();
 
   info("Wait until the remote runtime appears as connected");
   await waitUntil(() => {
     const sidebarItem = findSidebarItemByText(RUNTIME_DEVICE_NAME, document);
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_routes.js
@@ -0,0 +1,78 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from mocks/head-usb-mocks.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "mocks/head-usb-mocks.js", this);
+
+/**
+ * Test that the initial route is /runtime/this-firefox
+ */
+add_task(async function() {
+  info("Check root route redirects to 'This Firefox'");
+  const { document, tab } = await openAboutDebugging();
+  is(document.location.hash, "#/runtime/this-firefox");
+
+  await removeTab(tab);
+});
+
+/**
+ * Test that the routes in about:debugging show the proper views
+ */
+add_task(async function() {
+  // enable USB devices mocks
+  const usbMocks = new UsbMocks();
+  usbMocks.enableMocks();
+  registerCleanupFunction(() => usbMocks.disableMocks());
+
+  const { document, tab } = await openAboutDebugging();
+
+  info("Check 'This Firefox' route");
+  document.location.hash = "#/runtime/this-firefox";
+  await waitUntil(() => document.querySelector(".js-runtime-page"));
+  const infoLabel = document.querySelector(".js-runtime-info").textContent;
+  // NOTE: when using USB Mocks, we see only "Firefox" as the device name
+  ok(infoLabel.includes("Firefox"), "Runtime is displayed as Firefox");
+  ok(!infoLabel.includes(" on "), "Runtime is not associated to any device");
+
+  info("Check 'Connect' page");
+  document.location.hash = "#/connect";
+  await waitUntil(() => document.querySelector(".js-connect-page"));
+  ok(true, "Connect page has been shown");
+
+  info("Check 'USB device runtime' page");
+  // connect to a mocked USB runtime
+  usbMocks.createRuntime("1337id", {
+    deviceName: "Fancy Phone",
+    name: "Lorem ipsum",
+  });
+  usbMocks.emitUpdate();
+  await connectToRuntime("Fancy Phone", document);
+  // navigate to it via URL
+  document.location.hash = "#/runtime/1337id";
+  await waitUntil(() => document.querySelector(".js-runtime-page"));
+  const runtimeLabel = document.querySelector(".js-runtime-info").textContent;
+  ok(runtimeLabel.includes("Lorem ipsum"), "Runtime is displayed with the mocked name");
+
+  await removeTab(tab);
+});
+
+/**
+ * Test that an invalid route redirects to / (currently This Firefox page)
+ */
+add_task(async function() {
+  info("Check an invalid route redirects to root");
+  const { document, tab } = await openAboutDebugging();
+
+  info("Waiting for a non-runtime page to load");
+  document.location.hash = "#/connect";
+  await waitUntil(() => document.querySelector(".js-connect-page"));
+
+  info("Update hash & wait for a redirect to root ('This Firefox')");
+  document.location.hash = "#/lorem-ipsum";
+  await waitUntil(() => document.querySelector(".js-runtime-page"));
+  is(document.location.hash, "#/runtime/this-firefox", "Redirected to root");
+
+  await removeTab(tab);
+});
--- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_usb_runtime_refresh.js
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_usb_runtime_refresh.js
@@ -23,17 +23,18 @@ add_task(async function() {
 
   info("Create a first runtime and connect to it");
   usbMocks.createRuntime(RUNTIME_ID, {
     deviceName: RUNTIME_DEVICE_NAME,
     name: RUNTIME_APP_NAME,
   });
   usbMocks.emitUpdate();
 
-  await connectToRuntime(RUNTIME_DEVICE_NAME, RUNTIME_APP_NAME, document);
+  await connectToRuntime(RUNTIME_DEVICE_NAME, document);
+  await selectRuntime(RUNTIME_DEVICE_NAME, RUNTIME_APP_NAME, document);
 
   info("Create a second runtime and click on Refresh Devices");
   usbMocks.createRuntime(OTHER_RUNTIME_ID, {
     deviceName: OTHER_RUNTIME_APP_NAME,
   });
 
   // Mock the refreshUSBRuntimes to emit an update.
   usbMocks.usbRuntimesMock.refreshUSBRuntimes = () => usbMocks.emitUpdate();
--- a/devtools/client/aboutdebugging-new/test/browser/head.js
+++ b/devtools/client/aboutdebugging-new/test/browser/head.js
@@ -157,26 +157,29 @@ function findDebugTargetByText(text, doc
 
 function findSidebarItemByText(text, document) {
   const sidebarItems = document.querySelectorAll(".js-sidebar-item");
   return [...sidebarItems].find(element => {
     return element.textContent.includes(text);
   });
 }
 
-async function connectToRuntime(deviceName, appName, document) {
+async function connectToRuntime(deviceName, document) {
   info(`Wait until the sidebar item for ${deviceName} appears`);
   await waitUntil(() => findSidebarItemByText(deviceName, document));
   const sidebarItem = findSidebarItemByText(deviceName, document);
   const connectButton = sidebarItem.querySelector(".js-connect-button");
   ok(connectButton, `Connect button is displayed for the runtime ${deviceName}`);
 
   info("Click on the connect button and wait until it disappears");
   connectButton.click();
   await waitUntil(() => !sidebarItem.querySelector(".js-connect-button"));
+}
 
+async function selectRuntime(deviceName, name, document) {
+  const sidebarItem = findSidebarItemByText(deviceName, document);
   sidebarItem.querySelector(".js-sidebar-link").click();
 
   await waitUntil(() => {
     const runtimeInfo = document.querySelector(".js-runtime-info");
-    return runtimeInfo.textContent.includes(appName);
+    return runtimeInfo.textContent.includes(name);
   });
 }