From be7d1f2d52dd9474ca2df145190a817614c924e4 Mon Sep 17 00:00:00 2001 From: Daisuke Akatsuka Date: Wed, 8 Jan 2020 04:23:21 +0000 Subject: [PATCH] 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 --- devtools/client/netmonitor/test/browser.ini | 1 + .../test/browser_net_fission_switch_target.js | 63 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 devtools/client/netmonitor/test/browser_net_fission_switch_target.js diff --git a/devtools/client/netmonitor/test/browser.ini b/devtools/client/netmonitor/test/browser.ini index 4e30c0a6de5a..4a394c26d9f3 100644 --- a/devtools/client/netmonitor/test/browser.ini +++ b/devtools/client/netmonitor/test/browser.ini @@ -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] diff --git a/devtools/client/netmonitor/test/browser_net_fission_switch_target.js b/devtools/client/netmonitor/test/browser_net_fission_switch_target.js new file mode 100644 index 000000000000..e967a6813bc6 --- /dev/null +++ b/devtools/client/netmonitor/test/browser_net_fission_switch_target.js @@ -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"); +}