Bug 1578243: Add a test for target switching. r=jdescottes,ochameau

Depends on D57755

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Daisuke Akatsuka 2020-01-08 04:23:21 +00:00
parent fdb3bd4cbe
commit be7d1f2d52
2 changed files with 64 additions and 0 deletions

View File

@ -145,6 +145,7 @@ skip-if = true # Bug 1479782
[browser_net_filter-autocomplete.js]
[browser_net_filter-flags.js]
[browser_net_filter-value-preserved.js]
[browser_net_fission_switch_target.js]
[browser_net_footer-summary.js]
[browser_net_header-ref-policy.js]
[browser_net_decode-url.js]

View File

@ -0,0 +1,63 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test switching for the top-level target.
const PARENT_PROCESS_URI = "about:robots";
const PARENT_PROCESS_URI_NETWORK_COUNT = 0;
const CONTENT_PROCESS_URI = CUSTOM_GET_URL;
const CONTENT_PROCESS_URI_NETWORK_COUNT = 1;
add_task(async function() {
await pushPref("devtools.target-switching.enabled", true);
// We use about:robots, because this page will run in the parent process.
// Navigating from about:robots to a regular content page will always trigger a target
// switch, with or without fission.
info("Open a page that runs on the content process and the net monitor");
const { monitor, tab, toolbox } = await initNetMonitor(CONTENT_PROCESS_URI);
const { store } = monitor.panelWin;
info("Reload the page to show the network event");
const waitForReloading = waitForNetworkEvents(
monitor,
CONTENT_PROCESS_URI_NETWORK_COUNT
);
tab.linkedBrowser.reload();
await waitForReloading;
info("Navigate to a page that runs on parent process");
await navigateTo(PARENT_PROCESS_URI, toolbox, monitor, tab);
is(
store.getState().requests.requests.length,
PARENT_PROCESS_URI_NETWORK_COUNT,
`Request count of ${PARENT_PROCESS_URI} is correct`
);
info("Return to a page that runs on content process again");
await navigateTo(CONTENT_PROCESS_URI, toolbox, monitor, tab);
info(`Execute more requests in ${CONTENT_PROCESS_URI}`);
const currentRequestCount = store.getState().requests.requests.length;
const additionalRequestCount = 3;
await performRequests(monitor, tab, additionalRequestCount);
is(
store.getState().requests.requests.length - currentRequestCount,
additionalRequestCount,
"Additional request count is reflected correctly"
);
await teardown(monitor);
});
async function navigateTo(uri, toolbox, monitor, tab) {
const onSwitched = once(toolbox, "switched-target");
const onReloaded = once(monitor, "reloaded");
BrowserTestUtils.loadURI(tab.linkedBrowser, uri);
await onSwitched;
await onReloaded;
ok(true, "All events we expected were fired");
}