Bug 1497457 - Test runtime is still connected after about:debugging reload;r=daisuke,ladybenko

Depends on D11993

Differential Revision: https://phabricator.services.mozilla.com/D12039

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Julian Descottes 2018-11-27 10:17:55 +00:00
parent 8e5ba0d31f
commit bbe4268927
4 changed files with 79 additions and 4 deletions

View File

@ -27,6 +27,7 @@ skip-if = (os == 'linux' && bits == 32) # ADB start() fails on linux 32, see Bug
[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_sidebar_network_runtimes.js]
[browser_aboutdebugging_sidebar_usb_runtime.js]
[browser_aboutdebugging_sidebar_usb_runtime_connect.js]

View File

@ -0,0 +1,50 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const RUNTIME_ID = "test-runtime-id";
const RUNTIME_DEVICE_NAME = "test device name";
const RUNTIME_APP_NAME = "TestApp";
/* import-globals-from mocks/head-usb-mocks.js */
Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "mocks/head-usb-mocks.js", this);
// Test that remote runtime connections are persisted across about:debugging reloads.
add_task(async function() {
const usbMocks = new UsbMocks();
usbMocks.enableMocks();
registerCleanupFunction(() => usbMocks.disableMocks());
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);
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);
return sidebarItem && !sidebarItem.querySelector(".js-connect-button");
});
// Remove the runtime without emitting an update.
// This is what happens today when we simply close Firefox for Android.
info("Remove the runtime from the list of USB runtimes");
usbMocks.removeRuntime(RUNTIME_ID);
info("Emit 'closed' on the client and wait for the sidebar item to disappear");
usbClient._eventEmitter.emit("closed");
await waitUntil(() => !findSidebarItemByText(RUNTIME_DEVICE_NAME, document));
info("Remove the tab");
await removeTab(tab);
});

View File

@ -46,19 +46,37 @@ async function openAboutDebugging(page, win) {
await enableNewAboutDebugging();
info("opening about:debugging");
const tab = await addTab("about:debugging", { window: win });
const browser = tab.linkedBrowser;
const document = browser.contentDocument;
const window = browser.contentWindow;
const { AboutDebugging } = window;
await waitForInitialDispatch(window);
await Promise.all([
return { tab, document, window };
}
async function reloadAboutDebugging(tab) {
info("reload about:debugging");
await refreshTab(tab);
const browser = tab.linkedBrowser;
const document = browser.contentDocument;
const window = browser.contentWindow;
await waitForInitialDispatch(window);
return document;
}
function waitForInitialDispatch(win) {
info("wait for the initial about debugging actions to be dispatched");
const { AboutDebugging } = win;
return Promise.all([
waitForDispatch(AboutDebugging.store, "REQUEST_EXTENSIONS_SUCCESS"),
waitForDispatch(AboutDebugging.store, "REQUEST_TABS_SUCCESS"),
waitForDispatch(AboutDebugging.store, "REQUEST_WORKERS_SUCCESS"),
]);
return { tab, document, window };
}
/**

View File

@ -28,6 +28,12 @@ class UsbMocks {
return this._runtimes;
};
// refreshUSBRuntimes normally starts scan, which should ultimately fire the
// "runtime-list-updated" event.
this.usbRuntimesMock.refreshUSBRuntimes = () => {
this.emitUpdate();
};
// Prepare a fake observer to be able to emit events from this mock.
this._observerMock = addObserverMock(this.usbRuntimesMock);