Bug 1446508 - Rewrite test browser_policy_disable_fxscreenshots.js to make it more stable. r=MattN
MozReview-Commit-ID: BZi6XyacQpT
--- a/browser/components/enterprisepolicies/tests/browser/browser.ini
+++ b/browser/components/enterprisepolicies/tests/browser/browser.ini
@@ -22,17 +22,16 @@ support-files =
[browser_policy_block_about_support.js]
[browser_policy_block_set_desktop_background.js]
[browser_policy_bookmarks.js]
[browser_policy_clear_blocked_cookies.js]
[browser_policy_default_browser_check.js]
[browser_policy_disable_feedback_commands.js]
[browser_policy_disable_formhistory.js]
[browser_policy_disable_fxaccounts.js]
-[browser_policy_disable_fxscreenshots.js]
[browser_policy_disable_masterpassword.js]
[browser_policy_disable_pdfjs.js]
[browser_policy_disable_pocket.js]
[browser_policy_disable_privatebrowsing.js]
[browser_policy_disable_safemode.js]
[browser_policy_disable_shield.js]
[browser_policy_display_bookmarks.js]
[browser_policy_display_menu.js]
copy from browser/components/enterprisepolicies/tests/browser/disable_developer_tools/browser.ini
copy to browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/browser.ini
--- a/browser/components/enterprisepolicies/tests/browser/disable_developer_tools/browser.ini
+++ b/browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/browser.ini
@@ -1,8 +1,9 @@
[DEFAULT]
prefs =
browser.policies.enabled=true
- browser.policies.alternatePath='<test-root>/browser/components/enterprisepolicies/tests/browser/disable_developer_tools/config_disable_developer_tools.json'
+ browser.policies.alternatePath='<test-root>/browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/config_disable_fxscreenshots.json'
+ extensions.screenshots.disabled=false
support-files =
- config_disable_developer_tools.json
+ config_disable_fxscreenshots.json
-[browser_policy_disable_developer_tools.js]
+[browser_policy_disable_fxscreenshots.js]
rename from browser/components/enterprisepolicies/tests/browser/browser_policy_disable_fxscreenshots.js
rename to browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/browser_policy_disable_fxscreenshots.js
--- a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_fxscreenshots.js
+++ b/browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/browser_policy_disable_fxscreenshots.js
@@ -7,32 +7,23 @@ const PREF_DISABLE_FX_SCREENSHOTS = "ext
async function checkScreenshots(shouldBeEnabled) {
return BrowserTestUtils.waitForCondition(() => {
return !!PageActions.actionForID("screenshots") == shouldBeEnabled;
}, "Expecting screenshots to be " + shouldBeEnabled);
}
add_task(async function test_disable_firefox_screenshots() {
- await BrowserTestUtils.withNewTab("data:text/html,Test", async function() {
- // Firefox Screenshots are disabled in tests, so make sure we enable
- // it first to ensure that the test is valid.
- Services.prefs.setBoolPref(PREF_DISABLE_FX_SCREENSHOTS, false);
- await checkScreenshots(true);
+ // Dynamically toggling the PREF_DISABLE_FX_SCREENSHOTS is very finicky, because
+ // that pref is being watched, and it makes the Firefox Screenshots system add-on
+ // to start or stop, causing intermittency.
+ //
+ // Firefox Screenshots is disabled by default on tests (in prefs_general.js).
+ // What we do here to test this policy is to set the to false on this specific
+ // test folder (through browser.ini) and then we let the policy engine be responsible
+ // for disabling Firefox Screenshots in this case.
- await setupPolicyEngineWithJson({
- "policies": {
- "DisableFirefoxScreenshots": true
- }
- });
+ is(Services.prefs.getBoolPref(PREF_DISABLE_FX_SCREENSHOTS), true, "Screenshots pref is disabled");
- is(Services.policies.status, Services.policies.ACTIVE, "Policy engine is active");
- await checkScreenshots(false);
-
- // Clear the change we made and make sure it remains disabled.
- await setupPolicyEngineWithJson("");
-
- Services.prefs.unlockPref(PREF_DISABLE_FX_SCREENSHOTS);
- Services.prefs.clearUserPref(PREF_DISABLE_FX_SCREENSHOTS);
-
+ await BrowserTestUtils.withNewTab("data:text/html,Test", async function() {
await checkScreenshots(false);
});
});
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/config_disable_fxscreenshots.json
@@ -0,0 +1,5 @@
+{
+ "policies": {
+ "DisableFirefoxScreenshots": true
+ }
+}
--- a/browser/components/enterprisepolicies/tests/moz.build
+++ b/browser/components/enterprisepolicies/tests/moz.build
@@ -7,13 +7,14 @@
with Files("**"):
BUG_COMPONENT = ("Firefox", "General")
BROWSER_CHROME_MANIFESTS += [
'browser/browser.ini',
'browser/disable_app_update/browser.ini',
'browser/disable_default_bookmarks/browser.ini',
'browser/disable_developer_tools/browser.ini',
+ 'browser/disable_fxscreenshots/browser.ini',
]
TESTING_JS_MODULES += [
'EnterprisePolicyTesting.jsm',
]