From 41fcd603751cfe6a089d141a053ae4df0c4389d8 Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Tue, 18 Feb 2020 08:02:42 +0000 Subject: [PATCH] Bug 1615418 - Use a real client in disconnect aboutdebugging test r=daisuke Depends on D62894 Using a real local client allows to cover more codepaths than using a complete mock here. Differential Revision: https://phabricator.services.mozilla.com/D62891 --HG-- extra : moz-landing-system : lando --- ...er_aboutdebugging_fenix_runtime_display.js | 27 +--------------- ...gging_runtime_disconnect_remote_runtime.js | 14 +++++++++ .../test/browser/helper-mocks.js | 31 ++++++++++++++++++- 3 files changed, 45 insertions(+), 27 deletions(-) diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_fenix_runtime_display.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_fenix_runtime_display.js index c68b9e4945e8..ae922d8b9d3c 100644 --- a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_fenix_runtime_display.js +++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_fenix_runtime_display.js @@ -77,17 +77,9 @@ add_task(async function() { // about:devtools-toolbox on a real target. const clientWrapper = await createLocalClientWrapper(); - // Mock getDeviceDescription() to force the local client to return "nightly" as the - // channel. Otherwise the value of the icon source would depend on the current channel. - const deviceDescription = await clientWrapper.getDeviceDescription(); - clientWrapper.getDeviceDescription = function() { - return Object.assign({}, deviceDescription, { - channel: "nightly", - }); - }; - const mocks = new Mocks(); mocks.createUSBRuntime(RUNTIME_ID, { + channel: "nightly", clientWrapper: clientWrapper, deviceName: DEVICE_NAME, isFenix: true, @@ -106,7 +98,6 @@ add_task(async function() { const onRequestSuccess = waitForRequestsSuccess(window.AboutDebugging.store); await connectToRuntime(DEVICE_NAME, document); await selectRuntime(DEVICE_NAME, ADB_RUNTIME_NAME, document); - info( "Wait for requests to finish the USB runtime is backed by a real local client" ); @@ -148,19 +139,3 @@ add_task(async function() { await removeTab(tab); await clientWrapper.close(); }); - -async function createLocalClientWrapper() { - info("Create a local DevToolsClient"); - const { DevToolsServer } = require("devtools/server/devtools-server"); - const { DevToolsClient } = require("devtools/shared/client/devtools-client"); - const { - ClientWrapper, - } = require("devtools/client/aboutdebugging/src/modules/client-wrapper"); - - DevToolsServer.init(); - DevToolsServer.registerAllActors(); - const client = new DevToolsClient(DevToolsServer.connectPipe()); - - await client.connect(); - return new ClientWrapper(client); -} diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_disconnect_remote_runtime.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_disconnect_remote_runtime.js index 5695daccc03b..d9c545d9669b 100644 --- a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_disconnect_remote_runtime.js +++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_disconnect_remote_runtime.js @@ -14,9 +14,14 @@ const DEFAULT_PAGE = "#/runtime/this-firefox"; * and redirects to the default page. */ add_task(async function() { + // Create a real local client and use it as the remote USB client for this + // test. + const clientWrapper = await createLocalClientWrapper(); + // enable USB devices mocks const mocks = new Mocks(); mocks.createUSBRuntime(USB_RUNTIME_ID, { + clientWrapper, deviceName: USB_DEVICE_NAME, name: USB_APP_NAME, }); @@ -25,8 +30,11 @@ add_task(async function() { await selectThisFirefoxPage(document, window.AboutDebugging.store); mocks.emitUSBUpdate(); + + const onRequestSuccess = waitForRequestsSuccess(window.AboutDebugging.store); await connectToRuntime(USB_DEVICE_NAME, document); await selectRuntime(USB_DEVICE_NAME, USB_APP_NAME, document); + await onRequestSuccess; const disconnectRemoteRuntimeButton = document.querySelector( ".qa-runtime-info__action" @@ -47,5 +55,11 @@ add_task(async function() { "Redirection to the default page (this-firefox)" ); + info("Wait until the Runtime name is displayed"); + await waitUntil(() => { + const runtimeInfo = document.querySelector(".qa-runtime-name"); + return runtimeInfo && runtimeInfo.textContent.includes("Firefox"); + }); + await removeTab(tab); }); diff --git a/devtools/client/aboutdebugging/test/browser/helper-mocks.js b/devtools/client/aboutdebugging/test/browser/helper-mocks.js index 3a71e0ff257c..e53dfa498faa 100644 --- a/devtools/client/aboutdebugging/test/browser/helper-mocks.js +++ b/devtools/client/aboutdebugging/test/browser/helper-mocks.js @@ -161,7 +161,19 @@ class Mocks { // Add a valid client that can be returned for this particular runtime id. let mockUsbClient = runtimeInfo.clientWrapper; - if (!mockUsbClient) { + if (mockUsbClient) { + const originalGetDeviceDescription = mockUsbClient.getDeviceDescription.bind( + mockUsbClient + ); + mockUsbClient.getDeviceDescription = async () => { + const deviceDescription = await originalGetDeviceDescription(); + return { + channel: runtimeInfo.channel || deviceDescription.channel, + name: runtimeInfo.name || deviceDescription.name, + version: runtimeInfo.version || deviceDescription.version, + }; + }; + } else { // If no clientWrapper was provided, create a mock client here. mockUsbClient = createClientMock(); mockUsbClient.getDeviceDescription = () => { @@ -227,3 +239,20 @@ const silenceWorkerUpdates = function() { }); }; /* exported silenceWorkerUpdates */ + +async function createLocalClientWrapper() { + info("Create a local DevToolsClient"); + const { DevToolsServer } = require("devtools/server/devtools-server"); + const { DevToolsClient } = require("devtools/shared/client/devtools-client"); + const { + ClientWrapper, + } = require("devtools/client/aboutdebugging/src/modules/client-wrapper"); + + DevToolsServer.init(); + DevToolsServer.registerAllActors(); + const client = new DevToolsClient(DevToolsServer.connectPipe()); + + await client.connect(); + return new ClientWrapper(client); +} +/* exported createLocalClientWrapper */