Bug 2064655 - Add test coverage for live policies that simplify debugging - #1302
Bug 2064655 - Add test coverage for live policies that simplify debugging#13021rneh wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
This file should get feedback from devtools people IMHO
There was a problem hiding this comment.
Good idea! I just asked for a review in the devtools channel on slack.
| info("Removing BlockAboutConfig"); | ||
| await waitForLivePolicyUpdate({}); | ||
| await checkBlockedPage(ABOUT_CONFIG_PAGE, false); |
There was a problem hiding this comment.
For what it is worth https://searchfox.org/enterprise-main/rev/0e9eb88ea8645c4e0d00cdcbe9b561131f41b8d3/testing/enterprise/test_felt_browser_about_config_blocked.py#22-47 we have more transitions in this test because I remember finding issues transitionning from arbitrary states to others.
Things have moved on the engine so maybe this is not relevant anymore, but maybe we want extra coverage here?
There was a problem hiding this comment.
Ah, I didn't see test_felt_browser_about_config_blocked.py. I'd like to replace it with this one (but I'll wait until we have browser tests enabled) as I think the new browser test covers everything:
- no policy
- update to true (block)
- update to false = explicit allow (no block)
- remove
What the marionette tests additionally, is covering the reverse order - running step 3 followed by step 2 in the beginning.
One thing that has changed in the policy engine is that on a policy update we'll clear the previous state by running the onRemove callback first followed by the activation callback. So reversing the update order has no effect, as each update step starts with clearing any previous state.
| // The policy locks the pref to true and disables every entry point: | ||
| // checkDevToolsState asserting the keyset is removed, the menu items are | ||
| // hidden, and the feature is disallowed is what deterministically proves | ||
| // DevTools can no longer be opened. | ||
| await checkDevToolsState(browser, { locked: true, disabled: true }); | ||
| await checkDevToolsAboutPages(true); |
There was a problem hiding this comment.
why do not we test await checkCanOpenDevTools(browser); here? Well a variant "cannot" but we should verify it no?
There was a problem hiding this comment.
I tend also to remember some discussion with devtools folks around the fact that setting the policy may (or should?) close any opened devtool window, is this something we should test maybe?
(from my memory it was left "for the future" because of limitations in the devtools code handling, but I think it is part of what you change)
There was a problem hiding this comment.
Good idea! A live policy update to DisableDeveloperTools:true should close any open devtool windows!
There was a problem hiding this comment.
why do not we test await checkCanOpenDevTools(browser); here? Well a variant "cannot" but we should verify it no?
I don't know how to verify the absence of the devtools without a timeout. And I'd like to avoid introducing timeout flakiness.
lissyx
left a comment
There was a problem hiding this comment.
I have had a look at the copilot comment on gBrowser and I see similar code to yours accross the codebase so I'm not sure how much it's correct ...
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Suppressed comments (2)
toolkit/components/enterprisepolicies/tests/browser/live/head.js:69
- Consider awaiting tab removal here (i.e., wait for the tab close to complete) to avoid test interference from a still-tearing-down tab/session history load, especially since this helper is intended for reuse across many tests.
BrowserTestUtils.removeTab(newTab);
devtools/startup/DevToolsStartup.sys.mjs:401
- A new pref observer is added here. To keep observer lifecycles balanced and prevent duplicate notifications/leaks across shutdown/reload paths, please add the matching
Services.prefs.removeObserver(DEVTOOLS_POLICY_DISABLED_PREF, this.onDisabledByPolicyChanged)in the existing cleanup/uninit path forDevToolsStartup(where other observers are removed).
if (AppConstants.MOZ_ENTERPRISE) {
// React to the DisableDeveloperTools enterprise policy updates
Services.prefs.addObserver(
DEVTOOLS_POLICY_DISABLED_PREF,
this.onDisabledByPolicyChanged
);
}
85f1eac to
1b5b41a
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.
Suppressed comments (2)
toolkit/components/enterprisepolicies/tests/browser/live/head.js:42
- The comment says the blocked page is replaced with
about:neterror?e=blockedByPolicy, but this helper asserts onblockedByPolicyEnterprise. Keeping the comment in sync with the actual enterprise neterror code will avoid confusion when debugging failures.
// Navigate to `url` in a new tab and assert whether it was blocked by policy
// (replaced with about:neterror?e=blockedByPolicy) or loaded normally.
devtools/client/framework/browser-toolbox/Launcher.sys.mjs:90
BrowserToolboxLauncher.closeAll()calls the asynclauncher.close()without awaiting or handling rejections. Ifclose()throws (e.g. process already exited), this can surface as an unhandled promise rejection when the policy toggles live. Consider catching/logging errors for each close attempt.
static closeAll() {
if (!AppConstants.MOZ_ENTERPRISE) {
return;
}
for (const launcher of [...processes]) {
launcher.close();
}
}
Observe devtools.policy.disabled at runtime so the policy no longer needs a restart. On change, DevToolsStartup removes/restores the key shortcuts, closes open in-window toolboxes and any Browser Toolbox (closeAll), and devtools-browser hides/shows the Tools-menu items. gDevTools.showToolbox also refuses to open while disabled, so the policy holds via any entry point. Differential Revision: https://phabricator.services.mozilla.com/D320404
1b5b41a to
70cb372
Compare
| // Navigate to `url` in a new tab and assert whether it was blocked by policy | ||
| // (replaced with about:neterror?e=blockedByPolicy) or loaded normally. |
| static closeAll() { | ||
| for (const launcher of [...processes]) { | ||
| launcher.close(); | ||
| } | ||
| } |
Description
Bugzilla: Bug-2064655
waitForLivePolicyUpdateand refactors existing live tests to use it.BlockAboutConfigandBlockAboutSupport,DisableDeveloperToolsDependencies
Testing