Files
firefox/devtools/client/framework/test/browser_toolbox_watchedByDevTools.js
Alexandre Poirot 6c428aaabd Bug 1866814 - [devtools] Merge all DevTools JS Actors into a single DOM Process JS Actor. r=devtools-reviewers,nchevobbe
* The formers JSWindow Actors used independently to create Target Actor for WindowGlobals, Web workers and Service workers
  are all unified behind a single JSProcess Actor pair which was only used to create target actors for DOM Content Processes.
* The DevToolsProcess JSProcess actor now actively monitor the currently watched target types
  in order to start and stop listeners specific to each target type.
  We no longer rely on JSWindow Actors to observe WindowGlobal instantiations.

* `watchedByDevTools` is now consistantly set from each WindowGlobal's content process, via the WindowGlobalTargetActor.
  With the new setup, the parent process no longer track WindowGlobal/BrowsingContext's and so there is no
  natural place to flag them. While, in the content process, the target actor is an obvious place.
  There is just one trick in window global target watcher in order to also set this flag on initial about blank documents.

* `browser-element-host` Session Data is now slightly more simple. It works like any other similar session data attribute.
  But we have to ignore any pending exception coming up from updateDomainSessionDataForServiceWorkers call as that be still pending
  while the toolbox closes, which make the JS Process Actor be unregistered,
  and ultimately make the underlying sendQuery promise be rejected.
* The `loader` is made specific to each Watcher/connection and put in the connections map,
  so that we can better support content toolbox & browser toolbox usecases
  and we have a unique place to define the loader per watcher/connection.

* browser_target_command_detach.js: detach is no longer enough. It wouldn't stop watching and prevent the re-instantiation
  of the target actor. We now have to stop watching for targets. This actually better match what happens on toolbox closing.
  This test was meant as a unit test for covering remote debugging reusing the same DevToolsClient for debugger the same tab.
* `browser_toolbox_watchedByDevTools`. The management of watchedByDevTools is now driven from the content process.
  And because the DevTools Server and especially the watcher actor is destroyed without an explicit RDP request
  that the toolbox destruction is waiting for, we can't rely on closeToolbox to know
  when the server is fully cleaned up.

Differential Revision: https://phabricator.services.mozilla.com/D203409
2024-04-02 08:54:51 +00:00

78 lines
2.3 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Check that the "watchedByDevTools" flag is properly handled.
*/
const EXAMPLE_HTTP_URI =
"http://mochi.test:8888/document-builder.sjs?html=<div id=http>http";
const EXAMPLE_COM_URI =
"https://example.com/document-builder.sjs?html=<div id=com>com";
const EXAMPLE_ORG_URI =
"https://example.org/document-builder.sjs?headers=Cross-Origin-Opener-Policy:same-origin&html=<div id=org>org</div>";
add_task(async function () {
const tab = await addTab(EXAMPLE_HTTP_URI);
is(
tab.linkedBrowser.browsingContext.watchedByDevTools,
false,
"watchedByDevTools isn't set when DevTools aren't opened"
);
info(
"Open a toolbox for the opened tab and check that watchedByDevTools is set"
);
await gDevTools.showToolboxForTab(tab, { toolId: "options" });
is(
tab.linkedBrowser.browsingContext.watchedByDevTools,
true,
"watchedByDevTools is set after opening a toolbox"
);
info(
"Check that watchedByDevTools persist when the tab navigates to a different origin"
);
await navigateTo(EXAMPLE_COM_URI);
is(
tab.linkedBrowser.browsingContext.watchedByDevTools,
true,
"watchedByDevTools is still set after navigating to a different origin"
);
info(
"Check that watchedByDevTools persist when navigating to a page that creates a new browsing context"
);
const previousBrowsingContextId = tab.linkedBrowser.browsingContext.id;
await navigateTo(EXAMPLE_ORG_URI);
isnot(
tab.linkedBrowser.browsingContext.id,
previousBrowsingContextId,
"A new browsing context was created"
);
is(
tab.linkedBrowser.browsingContext.watchedByDevTools,
true,
"watchedByDevTools is still set after navigating to a new browsing context"
);
info("Check that the flag is reset when the toolbox is closed");
await gDevTools.closeToolboxForTab(tab);
// As the destroy sequence of DevTools server is synchronous and we aren't waiting
// for full completion of server cleanups, we have to wait for its full processing.
await waitFor(() => !tab.linkedBrowser.browsingContext.watchedByDevTools);
is(
tab.linkedBrowser.browsingContext.watchedByDevTools,
false,
"watchedByDevTools is reset after closing the toolbox"
);
});