Add support to clear ActionRegistry and ActionRegistration in one call
It's probable that when ActionRegistry.removeInstance is called, one
would also like to remove all the registered actions at that point. This
is specially probable in unit-test scenarios. For this reason, a new
`reset` function is added to action registry that achieves both things.
As a drive-by fix, the actions added in the action_registration test are
removed so that they don't pollute other tests.
Bug: none
Change-Id: Iaf49c53e61b3f9159a48b369693e5a40fcef44f7
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/4274349
Auto-Submit: Andres Olivares <[email protected]>
Reviewed-by: Jack Franklin <[email protected]>
Commit-Queue: Jack Franklin <[email protected]>
diff --git a/front_end/ui/legacy/ActionRegistration.ts b/front_end/ui/legacy/ActionRegistration.ts
index da133b4..c7cb955 100644
--- a/front_end/ui/legacy/ActionRegistration.ts
+++ b/front_end/ui/legacy/ActionRegistration.ts
@@ -151,6 +151,11 @@
registeredActionExtensions.push(new Action(registration));
}
+export function reset(): void {
+ actionIdSet.clear();
+ registeredActionExtensions.length = 0;
+}
+
export function getRegisteredActionExtensions(): Array<Action> {
return registeredActionExtensions
.filter(
diff --git a/front_end/ui/legacy/ActionRegistry.ts b/front_end/ui/legacy/ActionRegistry.ts
index 7c48789..458cb76 100644
--- a/front_end/ui/legacy/ActionRegistry.ts
+++ b/front_end/ui/legacy/ActionRegistry.ts
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import {getRegisteredActionExtensions, type Action} from './ActionRegistration.js';
+import {getRegisteredActionExtensions, type Action, reset as resetActionRegistrations} from './ActionRegistration.js';
import {Context} from './Context.js';
let actionRegistryInstance: ActionRegistry|undefined;
@@ -29,6 +29,11 @@
actionRegistryInstance = undefined;
}
+ static reset(): void {
+ ActionRegistry.removeInstance();
+ resetActionRegistrations();
+ }
+
private registerActions(): void {
for (const action of getRegisteredActionExtensions()) {
this.actionsById.set(action.id(), action);