From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../enterprisepolicies/tests/browser/301.sjs | 8 + .../enterprisepolicies/tests/browser/302.sjs | 8 + .../enterprisepolicies/tests/browser/404.sjs | 3 + .../enterprisepolicies/tests/browser/browser.ini | 73 ++++ .../browser/browser_policies_getActivePolicies.js | 52 +++ .../browser_policies_notice_in_aboutpreferences.js | 19 ++ .../browser/browser_policies_setAndLockPref_API.js | 179 ++++++++++ .../browser/browser_policy_app_auto_update.js | 77 +++++ .../tests/browser/browser_policy_app_update.js | 41 +++ .../browser_policy_background_app_update.js | 99 ++++++ .../tests/browser/browser_policy_block_about.js | 50 +++ .../browser/browser_policy_block_about_support.js | 41 +++ .../browser/browser_policy_cookie_settings.js | 367 +++++++++++++++++++++ .../browser_policy_disable_feedback_commands.js | 63 ++++ .../browser/browser_policy_disable_fxaccounts.js | 16 + .../browser_policy_disable_masterpassword.js | 90 +++++ .../browser_policy_disable_password_reveal.js | 43 +++ .../tests/browser/browser_policy_disable_pocket.js | 29 ++ .../browser_policy_disable_popup_blocker.js | 149 +++++++++ .../browser_policy_disable_privatebrowsing.js | 32 ++ .../browser_policy_disable_profile_import.js | 100 ++++++ .../browser_policy_disable_profile_reset.js | 80 +++++ .../browser/browser_policy_disable_safemode.js | 57 ++++ .../tests/browser/browser_policy_disable_shield.js | 68 ++++ .../browser/browser_policy_disable_telemetry.js | 28 ++ .../browser/browser_policy_display_bookmarks.js | 86 +++++ .../tests/browser/browser_policy_display_menu.js | 84 +++++ .../tests/browser/browser_policy_downloads.js | 147 +++++++++ .../tests/browser/browser_policy_extensions.js | 117 +++++++ .../browser/browser_policy_extensionsettings.js | 261 +++++++++++++++ .../browser/browser_policy_extensionsettings2.js | 71 ++++ .../tests/browser/browser_policy_firefoxhome.js | 132 ++++++++ .../tests/browser/browser_policy_firefoxsuggest.js | 63 ++++ .../tests/browser/browser_policy_handlers.js | 183 ++++++++++ .../tests/browser/browser_policy_masterpassword.js | 95 ++++++ .../browser_policy_masterpassword_aboutlogins.js | 76 +++++ .../browser_policy_masterpassword_doorhanger.js | 76 +++++ .../browser/browser_policy_offertosavelogins.js | 23 ++ .../browser_policy_override_postupdatepage.js | 132 ++++++++ .../browser/browser_policy_pageinfo_permissions.js | 76 +++++ .../browser/browser_policy_passwordmanager.js | 25 ++ .../tests/browser/browser_policy_search_engine.js | 109 ++++++ .../tests/browser/browser_policy_searchbar.js | 36 ++ .../tests/browser/browser_policy_set_homepage.js | 115 +++++++ .../tests/browser/browser_policy_set_startpage.js | 68 ++++ .../tests/browser/browser_policy_support_menu.js | 68 ++++ .../tests/browser/browser_policy_usermessaging.js | 21 ++ .../tests/browser/browser_policy_websitefilter.js | 186 +++++++++++ .../tests/browser/disable_app_update/browser.ini | 9 + .../browser_policy_disable_app_update.js | 121 +++++++ .../config_disable_app_update.json | 5 + .../bookmarks_policies.json | 5 + .../browser/disable_default_bookmarks/browser.ini | 7 + .../browser_policy_no_default_bookmarks.js | 24 ++ .../browser/disable_developer_tools/browser.ini | 7 + .../browser_policy_disable_developer_tools.js | 87 +++++ .../config_disable_developer_tools.json | 5 + .../browser/disable_forget_button/browser.ini | 7 + .../browser_policy_disable_forgetbutton.js | 9 + .../disable_forget_button/forget_button.json | 5 + .../browser/disable_fxscreenshots/browser.ini | 8 + .../browser_policy_disable_fxscreenshots.js | 35 ++ .../config_disable_fxscreenshots.json | 5 + .../tests/browser/extensionsettings.html | 28 ++ .../browser/hardware_acceleration/browser.ini | 7 + .../browser_policy_hardware_acceleration.js | 13 + .../disable_hardware_acceleration.json | 5 + .../enterprisepolicies/tests/browser/head.js | 253 ++++++++++++++ .../tests/browser/homepage_button/browser.ini | 7 + ...rowser_show_home_button_with_homepage_policy.js | 9 + .../browser/homepage_button/homepage_policies.json | 7 + .../tests/browser/managedbookmarks/browser.ini | 8 + .../browser_policy_managedbookmarks.js | 210 ++++++++++++ .../browser/managedbookmarks/managedbookmarks.json | 44 +++ .../tests/browser/opensearch.html | 8 + .../tests/browser/opensearchEngine.xml | 12 + .../tests/browser/policy_websitefilter_block.html | 10 + .../browser/policy_websitefilter_exception.html | 10 + .../browser/policy_websitefilter_savelink.html | 11 + .../tests/browser/policytest_v0.1.xpi | Bin 0 -> 305 bytes .../tests/browser/policytest_v0.2.xpi | Bin 0 -> 297 bytes .../tests/browser/show_home_button/browser.ini | 5 + .../browser_policy_show_home_button.js | 38 +++ .../show_home_button_policies.json | 7 + 84 files changed, 5053 insertions(+) create mode 100644 browser/components/enterprisepolicies/tests/browser/301.sjs create mode 100644 browser/components/enterprisepolicies/tests/browser/302.sjs create mode 100644 browser/components/enterprisepolicies/tests/browser/404.sjs create mode 100644 browser/components/enterprisepolicies/tests/browser/browser.ini create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policies_getActivePolicies.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policies_notice_in_aboutpreferences.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policies_setAndLockPref_API.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_app_auto_update.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_app_update.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_background_app_update.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_block_about.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_block_about_support.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_cookie_settings.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_disable_feedback_commands.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_disable_fxaccounts.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_disable_masterpassword.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_disable_password_reveal.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_disable_pocket.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_disable_popup_blocker.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_disable_privatebrowsing.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_disable_profile_import.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_disable_profile_reset.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_disable_safemode.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_disable_shield.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_disable_telemetry.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_display_bookmarks.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_display_menu.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_downloads.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_extensions.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_extensionsettings.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_extensionsettings2.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_firefoxhome.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_firefoxsuggest.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_handlers.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_masterpassword.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_masterpassword_aboutlogins.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_masterpassword_doorhanger.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_offertosavelogins.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_override_postupdatepage.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_pageinfo_permissions.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_passwordmanager.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_search_engine.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_searchbar.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_set_homepage.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_set_startpage.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_support_menu.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_usermessaging.js create mode 100644 browser/components/enterprisepolicies/tests/browser/browser_policy_websitefilter.js create mode 100644 browser/components/enterprisepolicies/tests/browser/disable_app_update/browser.ini create mode 100644 browser/components/enterprisepolicies/tests/browser/disable_app_update/browser_policy_disable_app_update.js create mode 100644 browser/components/enterprisepolicies/tests/browser/disable_app_update/config_disable_app_update.json create mode 100644 browser/components/enterprisepolicies/tests/browser/disable_default_bookmarks/bookmarks_policies.json create mode 100644 browser/components/enterprisepolicies/tests/browser/disable_default_bookmarks/browser.ini create mode 100644 browser/components/enterprisepolicies/tests/browser/disable_default_bookmarks/browser_policy_no_default_bookmarks.js create mode 100644 browser/components/enterprisepolicies/tests/browser/disable_developer_tools/browser.ini create mode 100644 browser/components/enterprisepolicies/tests/browser/disable_developer_tools/browser_policy_disable_developer_tools.js create mode 100644 browser/components/enterprisepolicies/tests/browser/disable_developer_tools/config_disable_developer_tools.json create mode 100644 browser/components/enterprisepolicies/tests/browser/disable_forget_button/browser.ini create mode 100644 browser/components/enterprisepolicies/tests/browser/disable_forget_button/browser_policy_disable_forgetbutton.js create mode 100644 browser/components/enterprisepolicies/tests/browser/disable_forget_button/forget_button.json create mode 100644 browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/browser.ini create mode 100644 browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/browser_policy_disable_fxscreenshots.js create mode 100644 browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/config_disable_fxscreenshots.json create mode 100644 browser/components/enterprisepolicies/tests/browser/extensionsettings.html create mode 100644 browser/components/enterprisepolicies/tests/browser/hardware_acceleration/browser.ini create mode 100644 browser/components/enterprisepolicies/tests/browser/hardware_acceleration/browser_policy_hardware_acceleration.js create mode 100644 browser/components/enterprisepolicies/tests/browser/hardware_acceleration/disable_hardware_acceleration.json create mode 100644 browser/components/enterprisepolicies/tests/browser/head.js create mode 100644 browser/components/enterprisepolicies/tests/browser/homepage_button/browser.ini create mode 100644 browser/components/enterprisepolicies/tests/browser/homepage_button/browser_show_home_button_with_homepage_policy.js create mode 100644 browser/components/enterprisepolicies/tests/browser/homepage_button/homepage_policies.json create mode 100644 browser/components/enterprisepolicies/tests/browser/managedbookmarks/browser.ini create mode 100644 browser/components/enterprisepolicies/tests/browser/managedbookmarks/browser_policy_managedbookmarks.js create mode 100644 browser/components/enterprisepolicies/tests/browser/managedbookmarks/managedbookmarks.json create mode 100644 browser/components/enterprisepolicies/tests/browser/opensearch.html create mode 100644 browser/components/enterprisepolicies/tests/browser/opensearchEngine.xml create mode 100644 browser/components/enterprisepolicies/tests/browser/policy_websitefilter_block.html create mode 100644 browser/components/enterprisepolicies/tests/browser/policy_websitefilter_exception.html create mode 100644 browser/components/enterprisepolicies/tests/browser/policy_websitefilter_savelink.html create mode 100644 browser/components/enterprisepolicies/tests/browser/policytest_v0.1.xpi create mode 100644 browser/components/enterprisepolicies/tests/browser/policytest_v0.2.xpi create mode 100644 browser/components/enterprisepolicies/tests/browser/show_home_button/browser.ini create mode 100644 browser/components/enterprisepolicies/tests/browser/show_home_button/browser_policy_show_home_button.js create mode 100644 browser/components/enterprisepolicies/tests/browser/show_home_button/show_home_button_policies.json (limited to 'browser/components/enterprisepolicies/tests/browser') diff --git a/browser/components/enterprisepolicies/tests/browser/301.sjs b/browser/components/enterprisepolicies/tests/browser/301.sjs new file mode 100644 index 0000000000..adf0f0891d --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/301.sjs @@ -0,0 +1,8 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +function handleRequest(request, response) { + response.setStatusLine(request.httpVersion, 301, "Moved Permanently"); + response.setHeader("Location", "policy_websitefilter_block.html"); +} diff --git a/browser/components/enterprisepolicies/tests/browser/302.sjs b/browser/components/enterprisepolicies/tests/browser/302.sjs new file mode 100644 index 0000000000..4aee85baac --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/302.sjs @@ -0,0 +1,8 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +function handleRequest(request, response) { + response.setStatusLine(request.httpVersion, 302, "Moved Temporarily"); + response.setHeader("Location", "policy_websitefilter_block.html"); +} diff --git a/browser/components/enterprisepolicies/tests/browser/404.sjs b/browser/components/enterprisepolicies/tests/browser/404.sjs new file mode 100644 index 0000000000..923e8082b1 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/404.sjs @@ -0,0 +1,3 @@ +function handleRequest(request, response) { + response.setStatusLine(request.httpVersion, 404, "Not Found"); +} diff --git a/browser/components/enterprisepolicies/tests/browser/browser.ini b/browser/components/enterprisepolicies/tests/browser/browser.ini new file mode 100644 index 0000000000..baba782d11 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser.ini @@ -0,0 +1,73 @@ +[DEFAULT] +support-files = + head.js + opensearch.html + opensearchEngine.xml + policytest_v0.1.xpi + policytest_v0.2.xpi + policy_websitefilter_block.html + policy_websitefilter_exception.html + policy_websitefilter_savelink.html + ../../../../../toolkit/components/antitracking/test/browser/page.html + ../../../../../toolkit/components/antitracking/test/browser/subResources.sjs + extensionsettings.html + 301.sjs + 302.sjs + 404.sjs + +[browser_policies_getActivePolicies.js] +skip-if = os != 'mac' +[browser_policies_notice_in_aboutpreferences.js] +[browser_policies_setAndLockPref_API.js] +[browser_policy_app_auto_update.js] +skip-if = os == 'win' && msix # Updater is disabled in MSIX builds +[browser_policy_app_update.js] +skip-if = os == 'win' && msix # Updater is disabled in MSIX builds +[browser_policy_background_app_update.js] +skip-if = os == 'win' && msix # Updater is disabled in MSIX builds +[browser_policy_block_about.js] +[browser_policy_block_about_support.js] +[browser_policy_block_set_desktop_background.js] +[browser_policy_bookmarks.js] +[browser_policy_cookie_settings.js] +https_first_disabled = true +[browser_policy_disable_feedback_commands.js] +[browser_policy_disable_fxaccounts.js] +skip-if = (verify && debug && (os == 'mac')) +[browser_policy_disable_masterpassword.js] +[browser_policy_disable_password_reveal.js] +[browser_policy_disable_pocket.js] +[browser_policy_disable_popup_blocker.js] +[browser_policy_disable_privatebrowsing.js] +[browser_policy_disable_profile_import.js] +[browser_policy_disable_profile_reset.js] +[browser_policy_disable_safemode.js] +[browser_policy_disable_shield.js] +[browser_policy_disable_telemetry.js] +[browser_policy_display_bookmarks.js] +[browser_policy_display_menu.js] +[browser_policy_downloads.js] +support-files = + !/browser/components/downloads/test/browser/foo.txt + !/browser/components/downloads/test/browser/foo.txt^headers^ +[browser_policy_extensions.js] +[browser_policy_extensionsettings.js] +https_first_disabled = true +[browser_policy_extensionsettings2.js] +[browser_policy_firefoxhome.js] +[browser_policy_firefoxsuggest.js] +[browser_policy_handlers.js] +[browser_policy_masterpassword.js] +[browser_policy_masterpassword_aboutlogins.js] +[browser_policy_masterpassword_doorhanger.js] +[browser_policy_offertosavelogins.js] +[browser_policy_override_postupdatepage.js] +[browser_policy_pageinfo_permissions.js] +[browser_policy_passwordmanager.js] +[browser_policy_search_engine.js] +[browser_policy_searchbar.js] +[browser_policy_set_homepage.js] +[browser_policy_set_startpage.js] +[browser_policy_support_menu.js] +[browser_policy_usermessaging.js] +[browser_policy_websitefilter.js] diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policies_getActivePolicies.js b/browser/components/enterprisepolicies/tests/browser/browser_policies_getActivePolicies.js new file mode 100644 index 0000000000..547f5e7598 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policies_getActivePolicies.js @@ -0,0 +1,52 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_active_policies() { + await setupPolicyEngineWithJson({ + policies: { + DisablePrivateBrowsing: true, + }, + }); + + let expected = { + DisablePrivateBrowsing: true, + }; + + Assert.deepEqual( + await Services.policies.getActivePolicies(), + expected, + "Active policies parsed correctly" + ); +}); + +add_task(async function test_wrong_policies() { + await setupPolicyEngineWithJson({ + policies: { + BlockAboutSupport: [true], + }, + }); + + let expected = {}; + + Assert.deepEqual( + await Services.policies.getActivePolicies(), + expected, + "Wrong policies ignored" + ); +}); + +add_task(async function test_content_process() { + await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { + try { + Services.policies.getActivePolicies(); + } catch (ex) { + is( + ex.result, + Cr.NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED, + "Function getActivePolicies() doesn't have a valid definition in the content process" + ); + } + }); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policies_notice_in_aboutpreferences.js b/browser/components/enterprisepolicies/tests/browser/browser_policies_notice_in_aboutpreferences.js new file mode 100644 index 0000000000..75c17ddf36 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policies_notice_in_aboutpreferences.js @@ -0,0 +1,19 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_notice_in_aboutprefences() { + await setupPolicyEngineWithJson({ + policies: { + DummyPolicy: true, + }, + }); + + await BrowserTestUtils.withNewTab("about:preferences", async browser => { + ok( + !browser.contentDocument.getElementById("policies-container").hidden, + "The Policies notice was made visible in about:preferences" + ); + }); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policies_setAndLockPref_API.js b/browser/components/enterprisepolicies/tests/browser/browser_policies_setAndLockPref_API.js new file mode 100644 index 0000000000..0cad8e5aa3 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policies_setAndLockPref_API.js @@ -0,0 +1,179 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +let { Policies, setAndLockPref, PoliciesUtils } = ChromeUtils.importESModule( + "resource:///modules/policies/Policies.sys.mjs" +); + +add_task(async function test_API_directly() { + await setupPolicyEngineWithJson(""); + setAndLockPref("policies.test.boolPref", true); + checkLockedPref("policies.test.boolPref", true); + + // Check that a previously-locked pref can be changed + // (it will be unlocked first). + setAndLockPref("policies.test.boolPref", false); + checkLockedPref("policies.test.boolPref", false); + + setAndLockPref("policies.test.intPref", 2); + checkLockedPref("policies.test.intPref", 2); + + setAndLockPref("policies.test.stringPref", "policies test"); + checkLockedPref("policies.test.stringPref", "policies test"); + + PoliciesUtils.setDefaultPref( + "policies.test.lockedPref", + "policies test", + true + ); + checkLockedPref("policies.test.lockedPref", "policies test"); + + // Test that user values do not override the prefs, and the get*Pref call + // still return the value set through setAndLockPref + Services.prefs.setBoolPref("policies.test.boolPref", true); + checkLockedPref("policies.test.boolPref", false); + + Services.prefs.setIntPref("policies.test.intPref", 10); + checkLockedPref("policies.test.intPref", 2); + + Services.prefs.setStringPref("policies.test.stringPref", "policies test"); + checkLockedPref("policies.test.stringPref", "policies test"); + + try { + // Test that a non-integer value is correctly rejected, even though + // typeof(val) == "number" + setAndLockPref("policies.test.intPref", 1.5); + ok(false, "Integer value should be rejected"); + } catch (ex) { + ok(true, "Integer value was rejected"); + } +}); + +add_task(async function test_API_through_policies() { + // Ensure that the values received by the policies have the correct + // type to make sure things are properly working. + + // Implement functions to handle the three simple policies + // that will be added to the schema. + Policies.bool_policy = { + onBeforeUIStartup(manager, param) { + setAndLockPref("policies.test2.boolPref", param); + }, + }; + + Policies.int_policy = { + onBeforeUIStartup(manager, param) { + setAndLockPref("policies.test2.intPref", param); + }, + }; + + Policies.string_policy = { + onBeforeUIStartup(manager, param) { + setAndLockPref("policies.test2.stringPref", param); + }, + }; + + await setupPolicyEngineWithJson( + // policies.json + { + policies: { + bool_policy: true, + int_policy: 42, + string_policy: "policies test 2", + }, + }, + + // custom schema + { + properties: { + bool_policy: { + type: "boolean", + }, + + int_policy: { + type: "integer", + }, + + string_policy: { + type: "string", + }, + }, + } + ); + + is( + Services.policies.status, + Ci.nsIEnterprisePolicies.ACTIVE, + "Engine is active" + ); + + // The expected values come from config_setAndLockPref.json + checkLockedPref("policies.test2.boolPref", true); + checkLockedPref("policies.test2.intPref", 42); + checkLockedPref("policies.test2.stringPref", "policies test 2"); + + delete Policies.bool_policy; + delete Policies.int_policy; + delete Policies.string_policy; +}); + +add_task(async function test_pref_tracker() { + // Tests the test harness functionality that tracks usage of + // the setAndLockPref and setDefualtPref APIs. + + let defaults = Services.prefs.getDefaultBranch(""); + + // Test prefs that had a default value and got changed to another + defaults.setIntPref("test1.pref1", 10); + defaults.setStringPref("test1.pref2", "test"); + + setAndLockPref("test1.pref1", 20); + PoliciesUtils.setDefaultPref("test1.pref2", "NEW VALUE"); + setAndLockPref("test1.pref3", "NEW VALUE"); + PoliciesUtils.setDefaultPref("test1.pref4", 20); + + PoliciesPrefTracker.restoreDefaultValues(); + + is( + Services.prefs.getIntPref("test1.pref1"), + 10, + "Expected value for test1.pref1" + ); + is( + Services.prefs.getStringPref("test1.pref2"), + "test", + "Expected value for test1.pref2" + ); + is( + Services.prefs.prefIsLocked("test1.pref1"), + false, + "test1.pref1 got unlocked" + ); + ok( + !Services.prefs.getStringPref("test1.pref3", undefined), + "test1.pref3 should have had its value unset" + ); + is( + Services.prefs.getIntPref("test1.pref4", -1), + -1, + "test1.pref4 should have had its value unset" + ); + + // Test a pref that had a default value and a user value + defaults.setIntPref("test2.pref1", 10); + Services.prefs.setIntPref("test2.pref1", 20); + + setAndLockPref("test2.pref1", 20); + + PoliciesPrefTracker.restoreDefaultValues(); + + is(Services.prefs.getIntPref("test2.pref1"), 20, "Correct user value"); + is(defaults.getIntPref("test2.pref1"), 10, "Correct default value"); + is( + Services.prefs.prefIsLocked("test2.pref1"), + false, + "felipe pref is not locked" + ); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_app_auto_update.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_app_auto_update.js new file mode 100644 index 0000000000..0cae8369e4 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_app_auto_update.js @@ -0,0 +1,77 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; +ChromeUtils.defineESModuleGetters(this, { + UpdateUtils: "resource://gre/modules/UpdateUtils.sys.mjs", +}); + +async function test_app_update_auto(expectedEnabled, expectedLocked) { + let actualEnabled = await UpdateUtils.getAppUpdateAutoEnabled(); + is( + actualEnabled, + expectedEnabled, + `Actual auto update enabled setting should match the expected value of ${expectedEnabled}` + ); + + let actualLocked = UpdateUtils.appUpdateAutoSettingIsLocked(); + is( + actualLocked, + expectedLocked, + `Auto update enabled setting ${ + expectedLocked ? "should" : "should not" + } be locked` + ); + + let setSuccess = true; + try { + await UpdateUtils.setAppUpdateAutoEnabled(actualEnabled); + } catch (error) { + setSuccess = false; + } + is( + setSuccess, + !expectedLocked, + `Setting auto update ${expectedLocked ? "should" : "should not"} fail` + ); + + await BrowserTestUtils.withNewTab("about:preferences", browser => { + is( + browser.contentDocument.getElementById("updateSettingsContainer").hidden, + expectedLocked, + `When auto update ${ + expectedLocked ? "is" : "isn't" + } locked, the corresponding preferences entry ${ + expectedLocked ? "should" : "shouldn't" + } be hidden` + ); + }); +} + +add_task(async function test_app_auto_update_policy() { + let originalUpdateAutoValue = await UpdateUtils.getAppUpdateAutoEnabled(); + registerCleanupFunction(async () => { + await UpdateUtils.setAppUpdateAutoEnabled(originalUpdateAutoValue); + }); + + await UpdateUtils.setAppUpdateAutoEnabled(true); + await test_app_update_auto(true, false); + + await setupPolicyEngineWithJson({ + policies: { + AppAutoUpdate: false, + }, + }); + await test_app_update_auto(false, true); + + await setupPolicyEngineWithJson({}); + await UpdateUtils.setAppUpdateAutoEnabled(false); + await test_app_update_auto(false, false); + + await setupPolicyEngineWithJson({ + policies: { + AppAutoUpdate: true, + }, + }); + await test_app_update_auto(true, true); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_app_update.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_app_update.js new file mode 100644 index 0000000000..14a9c92bc5 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_app_update.js @@ -0,0 +1,41 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; +ChromeUtils.defineESModuleGetters(this, { + UpdateUtils: "resource://gre/modules/UpdateUtils.sys.mjs", +}); +var updateService = Cc["@mozilla.org/updates/update-service;1"].getService( + Ci.nsIApplicationUpdateService +); + +// This test is intended to ensure that nsIUpdateService::canCheckForUpdates +// is true before the "DisableAppUpdate" policy is applied. Testing that +// nsIUpdateService::canCheckForUpdates is false after the "DisableAppUpdate" +// policy is applied needs to occur in a different test since the policy does +// not properly take effect unless it is applied during application startup. +add_task(async function test_updates_pre_policy() { + // Turn off automatic update before we set app.update.disabledForTesting to + // false so that we don't cause an actual update. + let originalUpdateAutoValue = await UpdateUtils.getAppUpdateAutoEnabled(); + await UpdateUtils.setAppUpdateAutoEnabled(false); + registerCleanupFunction(async () => { + await UpdateUtils.setAppUpdateAutoEnabled(originalUpdateAutoValue); + }); + + await SpecialPowers.pushPrefEnv({ + set: [["app.update.disabledForTesting", false]], + }); + + is( + Services.policies.isAllowed("appUpdate"), + true, + "Since no policies have been set, appUpdate should be allowed by default" + ); + + is( + updateService.canCheckForUpdates, + true, + "Should be able to check for updates before any policies are in effect." + ); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_background_app_update.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_background_app_update.js new file mode 100644 index 0000000000..a529e79be7 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_background_app_update.js @@ -0,0 +1,99 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +ChromeUtils.defineESModuleGetters(this, { + UpdateUtils: "resource://gre/modules/UpdateUtils.sys.mjs", +}); + +const PREF_NAME = "app.update.background.enabled"; + +async function test_background_update_pref(expectedEnabled, expectedLocked) { + let actualEnabled = await UpdateUtils.readUpdateConfigSetting(PREF_NAME); + is( + actualEnabled, + expectedEnabled, + `Actual background update enabled setting should be ${expectedEnabled}` + ); + + let actualLocked = UpdateUtils.appUpdateSettingIsLocked(PREF_NAME); + is( + actualLocked, + expectedLocked, + `Background update enabled setting ${ + expectedLocked ? "should" : "should not" + } be locked` + ); + + let setSuccess = true; + try { + await UpdateUtils.writeUpdateConfigSetting(PREF_NAME, actualEnabled); + } catch (error) { + setSuccess = false; + } + is( + setSuccess, + !expectedLocked, + `Setting background update pref ${ + expectedLocked ? "should" : "should not" + } fail` + ); + + if (AppConstants.MOZ_UPDATE_AGENT) { + let shouldShowUI = + !expectedLocked && UpdateUtils.PER_INSTALLATION_PREFS_SUPPORTED; + await BrowserTestUtils.withNewTab("about:preferences", browser => { + is( + browser.contentDocument.getElementById("backgroundUpdate").hidden, + !shouldShowUI, + `When background update ${ + expectedLocked ? "is" : "isn't" + } locked, and per-installation prefs ${ + UpdateUtils.PER_INSTALLATION_PREFS_SUPPORTED ? "are" : "aren't" + } supported, the corresponding preferences entry ${ + shouldShowUI ? "shouldn't" : "should" + } be hidden` + ); + }); + } else { + // The backgroundUpdate element is #ifdef'ed out if MOZ_UPDATER and + // MOZ_UPDATE_AGENT are not both defined. + info( + "Warning: UI testing skipped because support for background update is " + + "not present" + ); + } +} + +add_task(async function test_background_app_update_policy() { + const origBackgroundUpdateVal = await UpdateUtils.readUpdateConfigSetting( + PREF_NAME + ); + registerCleanupFunction(async () => { + await UpdateUtils.writeUpdateConfigSetting( + PREF_NAME, + origBackgroundUpdateVal + ); + }); + + await UpdateUtils.writeUpdateConfigSetting(PREF_NAME, true); + await test_background_update_pref(true, false); + + await setupPolicyEngineWithJson({ + policies: { + BackgroundAppUpdate: false, + }, + }); + await test_background_update_pref(false, true); + + await setupPolicyEngineWithJson({}); + await UpdateUtils.writeUpdateConfigSetting(PREF_NAME, false); + await test_background_update_pref(false, false); + + await setupPolicyEngineWithJson({ + policies: { + BackgroundAppUpdate: true, + }, + }); + await test_background_update_pref(true, true); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_block_about.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_block_about.js new file mode 100644 index 0000000000..1c8956356f --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_block_about.js @@ -0,0 +1,50 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +const ABOUT_CONTRACT = "@mozilla.org/network/protocol/about;1?what="; + +const policiesToTest = [ + { + policies: { + BlockAboutAddons: true, + }, + urls: ["about:addons", "about:ADDONS"], + }, + { + policies: { + BlockAboutConfig: true, + }, + urls: ["about:config", "about:Config"], + }, + { + policies: { + BlockAboutProfiles: true, + }, + urls: ["about:profiles", "about:pRofiles"], + }, + { + policies: { + BlockAboutSupport: true, + }, + urls: ["about:support", "about:suPPort"], + }, +]; + +add_task(async function testAboutTask() { + for (let policyToTest of policiesToTest) { + let policyJSON = { policies: {} }; + policyJSON.policies = policyToTest.policies; + for (let url of policyToTest.urls) { + if (url.startsWith("about")) { + let feature = url.split(":")[1].toLowerCase(); + let aboutModule = Cc[ABOUT_CONTRACT + feature].getService( + Ci.nsIAboutModule + ); + let chromeURL = aboutModule.getChromeURI(Services.io.newURI(url)).spec; + await testPageBlockedByPolicy(chromeURL, policyJSON); + } + await testPageBlockedByPolicy(url, policyJSON); + } + } +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_block_about_support.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_block_about_support.js new file mode 100644 index 0000000000..925aa0cdfd --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_block_about_support.js @@ -0,0 +1,41 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +add_setup(async function () { + await setupPolicyEngineWithJson({ + policies: { + BlockAboutSupport: true, + }, + }); +}); + +add_task(async function test_help_menu() { + buildHelpMenu(); + let troubleshootingInfoMenu = document.getElementById("troubleShooting"); + is( + troubleshootingInfoMenu.getAttribute("disabled"), + "true", + "The `More Troubleshooting Information` item should be disabled" + ); +}); + +add_task(async function test_about_memory() { + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + "about:memory" + ); + + await SpecialPowers.spawn(tab.linkedBrowser, [], async function () { + let aboutSupportLink = content.document.querySelector( + "a[href='about:support']" + ); + + Assert.ok( + !aboutSupportLink, + "The link to about:support at the bottom of the page should not exist" + ); + }); + + await BrowserTestUtils.removeTab(tab); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_cookie_settings.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_cookie_settings.js new file mode 100644 index 0000000000..b928e8c93b --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_cookie_settings.js @@ -0,0 +1,367 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +const { UrlClassifierTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/UrlClassifierTestUtils.sys.mjs" +); +Services.cookies.QueryInterface(Ci.nsICookieService); + +function restore_prefs() { + Services.prefs.clearUserPref("network.cookie.cookieBehavior"); + Services.prefs.clearUserPref( + "network.cookieJarSettings.unblocked_for_testing" + ); + Services.prefs.clearUserPref( + "network.cookie.rejectForeignWithExceptions.enabled" + ); +} + +registerCleanupFunction(restore_prefs); + +async function fake_profile_change() { + await new Promise(resolve => { + Services.obs.addObserver(function waitForDBClose() { + Services.obs.removeObserver(waitForDBClose, "cookie-db-closed"); + resolve(); + }, "cookie-db-closed"); + Services.cookies + .QueryInterface(Ci.nsIObserver) + .observe(null, "profile-before-change", null); + }); + await new Promise(resolve => { + Services.obs.addObserver(function waitForDBOpen() { + Services.obs.removeObserver(waitForDBOpen, "cookie-db-read"); + resolve(); + }, "cookie-db-read"); + Services.cookies + .QueryInterface(Ci.nsIObserver) + .observe(null, "profile-do-change", ""); + }); +} + +async function test_cookie_settings({ + cookiesEnabled, + thirdPartyCookiesEnabled, + rejectTrackers, + cookieJarSettingsLocked, +}) { + let firstPartyURI = NetUtil.newURI("https://example.com/"); + let thirdPartyURI = NetUtil.newURI("https://example.org/"); + let channel = NetUtil.newChannel({ + uri: firstPartyURI, + loadUsingSystemPrincipal: true, + }); + channel.QueryInterface( + Ci.nsIHttpChannelInternal + ).forceAllowThirdPartyCookie = true; + Services.cookies.removeAll(); + Services.cookies.setCookieStringFromHttp( + firstPartyURI, + "key=value; SameSite=None; Secure;", + channel + ); + Services.cookies.setCookieStringFromHttp( + thirdPartyURI, + "key=value; SameSite=None; Secure;", + channel + ); + + let expectedFirstPartyCookies = 1; + let expectedThirdPartyCookies = 1; + if (!cookiesEnabled) { + expectedFirstPartyCookies = 0; + } + if (!cookiesEnabled || !thirdPartyCookiesEnabled) { + expectedThirdPartyCookies = 0; + } + is( + Services.cookies.countCookiesFromHost(firstPartyURI.host), + expectedFirstPartyCookies, + "Number of first-party cookies should match expected" + ); + is( + Services.cookies.countCookiesFromHost(thirdPartyURI.host), + expectedThirdPartyCookies, + "Number of third-party cookies should match expected" + ); + + // Add a cookie so we can check if it persists past the end of the session + // but, first remove existing cookies set by this host to put us in a known state + Services.cookies.removeAll(); + Services.cookies.setCookieStringFromHttp( + firstPartyURI, + "key=value; max-age=1000; SameSite=None; Secure;", + channel + ); + + await fake_profile_change(); + + // Now check if the cookie persisted or not + let expectedCookieCount = 1; + if (!cookiesEnabled) { + expectedCookieCount = 0; + } + is( + Services.cookies.countCookiesFromHost(firstPartyURI.host), + expectedCookieCount, + "Number of cookies was not what expected after restarting session" + ); + + is( + Services.prefs.prefIsLocked("network.cookie.cookieBehavior"), + cookieJarSettingsLocked, + "Cookie behavior pref lock status should be what is expected" + ); + + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + "about:preferences" + ); + + BrowserTestUtils.removeTab(tab); + + if (rejectTrackers) { + tab = await BrowserTestUtils.addTab( + gBrowser, + "http://example.net/browser/browser/components/enterprisepolicies/tests/browser/page.html" + ); + let browser = gBrowser.getBrowserForTab(tab); + await BrowserTestUtils.browserLoaded(browser); + await SpecialPowers.spawn(tab.linkedBrowser, [], async function () { + // Load the script twice + { + let src = content.document.createElement("script"); + let p = new content.Promise((resolve, reject) => { + src.onload = resolve; + src.onerror = reject; + }); + content.document.body.appendChild(src); + src.src = + "https://tracking.example.org/browser/browser/components/enterprisepolicies/tests/browser/subResources.sjs?what=script"; + await p; + } + { + let src = content.document.createElement("script"); + let p = new content.Promise(resolve => { + src.onload = resolve; + }); + content.document.body.appendChild(src); + src.src = + "https://tracking.example.org/browser/browser/components/enterprisepolicies/tests/browser/subResources.sjs?what=script"; + await p; + } + }); + BrowserTestUtils.removeTab(tab); + await fetch( + "https://tracking.example.org/browser/browser/components/enterprisepolicies/tests/browser/subResources.sjs?result&what=script" + ) + .then(r => r.text()) + .then(text => { + is(text, "0", '"Reject Tracker" pref should match what is expected'); + }); + } +} + +add_task(async function prepare_tracker_tables() { + await UrlClassifierTestUtils.addTestTrackers(); +}); + +add_task(async function test_initial_state() { + Services.prefs.setBoolPref( + "network.cookieJarSettings.unblocked_for_testing", + true + ); + Services.prefs.setBoolPref( + "network.cookie.rejectForeignWithExceptions.enabled", + false + ); + + await test_cookie_settings({ + cookiesEnabled: true, + thirdPartyCookiesEnabled: true, + cookieJarSettingsLocked: false, + }); + restore_prefs(); +}); + +add_task(async function test_undefined_unlocked() { + Services.prefs.setIntPref("network.cookie.cookieBehavior", 3); + Services.prefs.setBoolPref( + "network.cookieJarSettings.unblocked_for_testing", + true + ); + Services.prefs.setBoolPref( + "network.cookie.rejectForeignWithExceptions.enabled", + false + ); + await setupPolicyEngineWithJson({ + policies: { + Cookies: {}, + }, + }); + is( + Services.prefs.getIntPref("network.cookie.cookieBehavior", undefined), + 3, + "An empty cookie policy should not have changed the cookieBehavior preference" + ); + restore_prefs(); +}); + +add_task(async function test_disabled() { + Services.prefs.setBoolPref( + "network.cookieJarSettings.unblocked_for_testing", + true + ); + Services.prefs.setBoolPref( + "network.cookie.rejectForeignWithExceptions.enabled", + false + ); + await setupPolicyEngineWithJson({ + policies: { + Cookies: { + Default: false, + }, + }, + }); + + await test_cookie_settings({ + cookiesEnabled: false, + thirdPartyCookiesEnabled: true, + cookieJarSettingsLocked: false, + }); + restore_prefs(); +}); + +add_task(async function test_third_party_disabled() { + Services.prefs.setBoolPref( + "network.cookieJarSettings.unblocked_for_testing", + true + ); + Services.prefs.setBoolPref( + "network.cookie.rejectForeignWithExceptions.enabled", + false + ); + await setupPolicyEngineWithJson({ + policies: { + Cookies: { + AcceptThirdParty: "never", + }, + }, + }); + + await test_cookie_settings({ + cookiesEnabled: true, + thirdPartyCookiesEnabled: false, + cookieJarSettingsLocked: false, + }); + restore_prefs(); +}); + +add_task(async function test_disabled_and_third_party_disabled() { + Services.prefs.setBoolPref( + "network.cookieJarSettings.unblocked_for_testing", + true + ); + Services.prefs.setBoolPref( + "network.cookie.rejectForeignWithExceptions.enabled", + false + ); + await setupPolicyEngineWithJson({ + policies: { + Cookies: { + Default: false, + AcceptThirdParty: "never", + }, + }, + }); + + await test_cookie_settings({ + cookiesEnabled: false, + thirdPartyCookiesEnabled: false, + cookieJarSettingsLocked: false, + }); + restore_prefs(); +}); + +add_task(async function test_disabled_and_third_party_disabled_locked() { + Services.prefs.setBoolPref( + "network.cookieJarSettings.unblocked_for_testing", + true + ); + Services.prefs.setBoolPref( + "network.cookie.rejectForeignWithExceptions.enabled", + false + ); + await setupPolicyEngineWithJson({ + policies: { + Cookies: { + Default: false, + AcceptThirdParty: "never", + Locked: true, + }, + }, + }); + + await test_cookie_settings({ + cookiesEnabled: false, + thirdPartyCookiesEnabled: false, + cookieJarSettingsLocked: true, + }); + restore_prefs(); +}); + +add_task(async function test_undefined_locked() { + Services.prefs.setBoolPref( + "network.cookieJarSettings.unblocked_for_testing", + true + ); + Services.prefs.setBoolPref( + "network.cookie.rejectForeignWithExceptions.enabled", + false + ); + await setupPolicyEngineWithJson({ + policies: { + Cookies: { + Locked: true, + }, + }, + }); + + await test_cookie_settings({ + cookiesEnabled: true, + thirdPartyCookiesEnabled: true, + cookieJarSettingsLocked: true, + }); + restore_prefs(); +}); + +add_task(async function test_cookie_reject_trackers() { + Services.prefs.setBoolPref( + "network.cookieJarSettings.unblocked_for_testing", + true + ); + Services.prefs.setBoolPref( + "network.cookie.rejectForeignWithExceptions.enabled", + false + ); + await setupPolicyEngineWithJson({ + policies: { + Cookies: { + RejectTracker: true, + }, + }, + }); + + await test_cookie_settings({ + cookiesEnabled: true, + thirdPartyCookiesEnabled: true, + rejectTrackers: true, + cookieJarSettingsLocked: false, + }); + restore_prefs(); +}); + +add_task(async function prepare_tracker_tables() { + await UrlClassifierTestUtils.cleanupTestTrackers(); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_feedback_commands.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_feedback_commands.js new file mode 100644 index 0000000000..b89788e1cf --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_feedback_commands.js @@ -0,0 +1,63 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/* the buidHelpMenu() function comes from browser/base/content/utilityOverlay.js */ + +const NORMAL_PAGE = "http://example.com"; +const PHISH_PAGE = "http://www.itisatrap.org/firefox/its-a-trap.html"; + +async function checkItemsAreDisabled(url) { + await BrowserTestUtils.withNewTab( + { + gBrowser, + url, + // The phishing page doesn't send a load notification + waitForLoad: false, + waitForStateStop: true, + }, + async function checkItems() { + buildHelpMenu(); + + let reportMenu = document.getElementById( + "menu_HelpPopup_reportPhishingtoolmenu" + ); + is( + reportMenu.getAttribute("disabled"), + "true", + "The `Report Deceptive Site` item should be disabled" + ); + + let errorMenu = document.getElementById( + "menu_HelpPopup_reportPhishingErrortoolmenu" + ); + is( + errorMenu.getAttribute("disabled"), + "true", + "The `This isn’t a deceptive site` item should be disabled" + ); + } + ); +} + +add_task(async function test_policy_feedback_commands() { + await setupPolicyEngineWithJson({ + policies: { + DisableFeedbackCommands: true, + }, + }); + + /* from browser/base/content/utilityOverlay.js */ + buildHelpMenu(); + + let feedbackPageMenu = document.getElementById("feedbackPage"); + is( + feedbackPageMenu.getAttribute("disabled"), + "true", + "The `Submit Feedback...` item should be disabled" + ); + + await checkItemsAreDisabled(NORMAL_PAGE); + await checkItemsAreDisabled(PHISH_PAGE); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_fxaccounts.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_fxaccounts.js new file mode 100644 index 0000000000..7872647042 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_fxaccounts.js @@ -0,0 +1,16 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_policy_disable_fxaccounts() { + is(gSync.FXA_ENABLED, true, "Sync is enabled before setting the policy."); + + await setupPolicyEngineWithJson({ + policies: { + DisableFirefoxAccounts: true, + }, + }); + + is(gSync.FXA_ENABLED, false, "Sync is disabled after setting the policy."); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_masterpassword.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_masterpassword.js new file mode 100644 index 0000000000..7f3748fdc5 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_masterpassword.js @@ -0,0 +1,90 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const MASTER_PASSWORD = "omgsecret!"; +const mpToken = Cc["@mozilla.org/security/pk11tokendb;1"] + .getService(Ci.nsIPK11TokenDB) + .getInternalKeyToken(); + +async function checkDeviceManager({ buttonIsDisabled }) { + let deviceManagerWindow = window.openDialog( + "chrome://pippki/content/device_manager.xhtml", + "", + "" + ); + await BrowserTestUtils.waitForEvent(deviceManagerWindow, "load"); + + let tree = deviceManagerWindow.document.getElementById("device_tree"); + ok(tree, "The device tree exists"); + + // Find and select the item related to the internal key token + for (let i = 0; i < tree.view.rowCount; i++) { + tree.view.selection.select(i); + + try { + let selected_token = deviceManagerWindow.selected_slot.getToken(); + if (selected_token.isInternalKeyToken) { + break; + } + } catch (e) {} + } + + // Check to see if the button was updated correctly + let changePwButton = + deviceManagerWindow.document.getElementById("change_pw_button"); + is( + changePwButton.getAttribute("disabled") == "true", + buttonIsDisabled, + "Change Password button is in the correct state: " + buttonIsDisabled + ); + + await BrowserTestUtils.closeWindow(deviceManagerWindow); +} + +async function checkAboutPreferences({ checkboxIsDisabled }) { + await BrowserTestUtils.withNewTab( + "about:preferences#privacy", + async browser => { + is( + browser.contentDocument.getElementById("useMasterPassword").disabled, + checkboxIsDisabled, + "Master Password checkbox is in the correct state: " + + checkboxIsDisabled + ); + } + ); +} + +add_task(async function test_policy_disable_masterpassword() { + ok(!mpToken.hasPassword, "Starting the test with no password"); + + // No password and no policy: access to setting a primary password + // should be enabled. + await checkDeviceManager({ buttonIsDisabled: false }); + await checkAboutPreferences({ checkboxIsDisabled: false }); + + await setupPolicyEngineWithJson({ + policies: { + DisableMasterPasswordCreation: true, + }, + }); + + // With the `DisableMasterPasswordCreation: true` policy active, the + // UI entry points for creating a Primary Password should be disabled. + await checkDeviceManager({ buttonIsDisabled: true }); + await checkAboutPreferences({ checkboxIsDisabled: true }); + + mpToken.changePassword("", MASTER_PASSWORD); + ok(mpToken.hasPassword, "Master password was set"); + + // If a Primary Password is already set, there's no point in disabling + // the + await checkDeviceManager({ buttonIsDisabled: false }); + await checkAboutPreferences({ checkboxIsDisabled: false }); + + // Clean up + mpToken.changePassword(MASTER_PASSWORD, ""); + ok(!mpToken.hasPassword, "Master password was cleaned up"); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_password_reveal.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_password_reveal.js new file mode 100644 index 0000000000..503d421da7 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_password_reveal.js @@ -0,0 +1,43 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_hidden_reveal_password() { + await setupPolicyEngineWithJson({ + policies: { + DisablePasswordReveal: true, + }, + }); + + let aboutLoginsTab = await BrowserTestUtils.openNewForegroundTab({ + gBrowser, + url: "about:logins", + }); + + let browser = gBrowser.selectedBrowser; + + await SpecialPowers.spawn(browser, [], () => { + let loginList = Cu.waiveXrays(content.document.querySelector("login-list")); + let createButton = loginList._createLoginButton; + ok( + !createButton.disabled, + "Create button should not be disabled initially" + ); + let loginItem = Cu.waiveXrays(content.document.querySelector("login-item")); + + createButton.click(); + + let passwordReveal = loginItem.shadowRoot.querySelector( + ".reveal-password-checkbox" + ); + is(passwordReveal.hidden, true, "Password reveal button should be hidden"); + + // Bug 1696948 + let passwordInput = loginItem.shadowRoot.querySelector( + "input[name='password']" + ); + isnot(passwordInput, null, "Password field should be in the DOM"); + }); + BrowserTestUtils.removeTab(aboutLoginsTab); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_pocket.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_pocket.js new file mode 100644 index 0000000000..414b855f8c --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_pocket.js @@ -0,0 +1,29 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const PREF_POCKET = "extensions.pocket.enabled"; + +async function checkPocket(shouldBeEnabled) { + return BrowserTestUtils.waitForCondition(() => { + return ( + !!CustomizableUI.getWidget("save-to-pocket-button") == shouldBeEnabled + ); + }, "Expecting Pocket to be " + shouldBeEnabled); +} + +add_task(async function test_disable_firefox_screenshots() { + await BrowserTestUtils.withNewTab("data:text/html,Test", async function () { + // Sanity check to make sure Pocket is enabled on tests + await checkPocket(true); + + await setupPolicyEngineWithJson({ + policies: { + DisablePocket: true, + }, + }); + + await checkPocket(false); + }); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_popup_blocker.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_popup_blocker.js new file mode 100644 index 0000000000..b9573c7614 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_popup_blocker.js @@ -0,0 +1,149 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +function restore_prefs() { + Services.prefs.clearUserPref("dom.disable_open_during_load"); +} + +let ORIGINAL_PREF_VALUE = undefined; +add_setup(async function () { + // It seems that this pref is given a special testing value for some reason. + // Unset that value for this test, but save the old value + if (Services.prefs.prefHasUserValue("dom.disable_open_during_load")) { + ORIGINAL_PREF_VALUE = Services.prefs.getBoolPref( + "dom.disable_open_during_load" + ); + Services.prefs.clearUserPref("dom.disable_open_during_load"); + } +}); +registerCleanupFunction(async function cleanup_prefs() { + if (ORIGINAL_PREF_VALUE === undefined) { + Services.prefs.clearUserPref("dom.disable_open_during_load"); + } else { + Services.prefs.setBoolPref( + "dom.disable_open_during_load", + ORIGINAL_PREF_VALUE + ); + } +}); + +async function test_popup_blocker_disabled({ disabled, locked }) { + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + "about:preferences#privacy" + ); + await SpecialPowers.spawn( + tab.linkedBrowser, + [{ disabled, locked }], + // eslint-disable-next-line no-shadow + async function ({ disabled, locked }) { + let checkbox = content.document.getElementById("popupPolicy"); + is( + checkbox.checked, + !disabled, + "Checkbox checked state should match policy's Block status" + ); + is( + checkbox.disabled, + locked, + "Checkbox disabled state should match policy's Locked status" + ); + } + ); + BrowserTestUtils.removeTab(tab); + + is( + Services.prefs.prefIsLocked("dom.disable_open_during_load"), + locked, + "Flash pref lock state should match policy lock state" + ); +} + +add_task(async function test_initial_state() { + await test_popup_blocker_disabled({ disabled: false, locked: false }); +}); + +add_task(async function test_empty_policy() { + await setupPolicyEngineWithJson({ + policies: { + PopupBlocking: {}, + }, + }); + + await test_popup_blocker_disabled({ disabled: false, locked: false }); + + restore_prefs(); +}); + +add_task(async function test_block() { + await setupPolicyEngineWithJson({ + policies: { + PopupBlocking: { + Default: true, + }, + }, + }); + + await test_popup_blocker_disabled({ disabled: false, locked: false }); + + restore_prefs(); +}); + +add_task(async function test_block_locked() { + await setupPolicyEngineWithJson({ + policies: { + PopupBlocking: { + Default: true, + Locked: true, + }, + }, + }); + + await test_popup_blocker_disabled({ disabled: false, locked: true }); + + restore_prefs(); +}); + +add_task(async function test_locked() { + await setupPolicyEngineWithJson({ + policies: { + PopupBlocking: { + Locked: true, + }, + }, + }); + + await test_popup_blocker_disabled({ disabled: false, locked: true }); + + restore_prefs(); +}); + +add_task(async function test_disabled() { + await setupPolicyEngineWithJson({ + policies: { + PopupBlocking: { + Default: false, + }, + }, + }); + + await test_popup_blocker_disabled({ disabled: true, locked: false }); + + restore_prefs(); +}); + +add_task(async function test_disabled_locked() { + await setupPolicyEngineWithJson({ + policies: { + PopupBlocking: { + Default: false, + Locked: true, + }, + }, + }); + + await test_popup_blocker_disabled({ disabled: true, locked: true }); + + restore_prefs(); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_privatebrowsing.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_privatebrowsing.js new file mode 100644 index 0000000000..044282f473 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_privatebrowsing.js @@ -0,0 +1,32 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_setup(async function () { + await setupPolicyEngineWithJson({ + policies: { + DisablePrivateBrowsing: true, + }, + }); +}); + +add_task(async function test_privatebrowsing_disabled() { + is( + PrivateBrowsingUtils.enabled, + false, + "Private browsing should be disabled" + ); + let newWin = await BrowserTestUtils.openNewBrowserWindow(); + let privateBrowsingCommand = newWin.document.getElementById( + "Tools:PrivateBrowsing" + ); + is( + privateBrowsingCommand.hidden, + true, + "The private browsing command should be hidden" + ); + await BrowserTestUtils.closeWindow(newWin); + + await testPageBlockedByPolicy("about:privatebrowsing"); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_profile_import.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_profile_import.js new file mode 100644 index 0000000000..9993e578e0 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_profile_import.js @@ -0,0 +1,100 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +async function openLibrary() { + return new Promise(resolve => { + let library = window.openDialog( + "chrome://browser/content/places/places.xhtml", + "", + "chrome,toolbar=yes,dialog=no,resizable" + ); + waitForFocus(() => resolve(library), library); + }); +} + +add_task(async function test_disable_profile_import() { + await setupPolicyEngineWithJson({ + policies: { + DisableProfileImport: true, + }, + }); + let library = await openLibrary(); + + let menu = library.document.getElementById("maintenanceButtonPopup"); + let promisePopupShown = BrowserTestUtils.waitForEvent(menu, "popupshown"); + menu.openPopup(); + await promisePopupShown; + + let profileImportButton = library.document.getElementById("browserImport"); + is( + profileImportButton.disabled, + true, + "Profile Import button should be disabled" + ); + + let promisePopupHidden = BrowserTestUtils.waitForEvent(menu, "popuphidden"); + menu.hidePopup(); + await promisePopupHidden; + + await BrowserTestUtils.closeWindow(library); + + checkLockedPref("browser.newtabpage.activity-stream.migrationExpired", true); +}); + +add_task(async function test_file_menu() { + gFileMenu.updateImportCommandEnabledState(); + + let command = document.getElementById("cmd_file_importFromAnotherBrowser"); + ok( + command.getAttribute("disabled"), + "The `Import from Another Browser…` File menu item command should be disabled" + ); + + if (Services.appinfo.OS == "Darwin") { + // We would need to have a lot of boilerplate to open the menus on Windows + // and Linux to test this there. + let menuitem = document.getElementById("menu_importFromAnotherBrowser"); + ok( + menuitem.disabled, + "The `Import from Another Browser…` File menu item should be disabled" + ); + } +}); + +add_task(async function test_import_button() { + await PlacesUIUtils.maybeAddImportButton(); + ok( + !document.getElementById("import-button"), + "Import button should be hidden." + ); +}); + +add_task(async function test_prefs_entrypoint() { + await SpecialPowers.pushPrefEnv({ + set: [["browser.migrate.preferences-entrypoint.enabled", true]], + }); + + let finalPaneEvent = Services.prefs.getBoolPref("identity.fxaccounts.enabled") + ? "sync-pane-loaded" + : "privacy-pane-loaded"; + let finalPrefPaneLoaded = TestUtils.topicObserved(finalPaneEvent, () => true); + await BrowserTestUtils.withNewTab( + "about:preferences#general-migrate", + async browser => { + await finalPrefPaneLoaded; + await browser.contentWindow.customElements.whenDefined( + "migration-wizard" + ); + let doc = browser.contentDocument; + ok( + !doc.getElementById("dataMigrationGroup"), + "Should remove import entrypoint in prefs if disabled via policy." + ); + ok( + !doc.getElementById("migrationWizardDialog").open, + "Should not have opened the migration wizard." + ); + } + ); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_profile_reset.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_profile_reset.js new file mode 100644 index 0000000000..09bcdb2d85 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_profile_reset.js @@ -0,0 +1,80 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +let { ResetProfile } = ChromeUtils.importESModule( + "resource://gre/modules/ResetProfile.sys.mjs" +); + +// For this test to work properly, this profile actually needs to be +// "reset-able", which requires that it be recognized by the profile service +add_setup(async function () { + let profileDirectory = Services.dirsvc.get("ProfD", Ci.nsIFile); + let profileName = profileDirectory.leafName; + let profileService = Cc["@mozilla.org/toolkit/profile-service;1"].getService( + Ci.nsIToolkitProfileService + ); + let createdProfile = profileService.createProfile( + profileDirectory, + profileName + ); + profileService.flush(); + registerCleanupFunction(async function cleanup() { + // Pass false to remove it from the profile service without deleting files. + createdProfile.remove(false); + }); +}); + +async function test_reset_disabled({ disabled }) { + is( + ResetProfile.resetSupported(), + !disabled, + "Reset should only be supported if policy has not been applied" + ); + is( + Services.prefs.getBoolPref("browser.disableResetPrompt", undefined), + disabled, + "Reset prompt should only be shown if policy has not been applied" + ); + is( + Services.prefs.prefIsLocked("browser.disableResetPrompt"), + disabled, + "Reset prompt pref should be locked if the policy has been applied" + ); + + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + "about:support" + ); + await SpecialPowers.spawn( + tab.linkedBrowser, + [{ disabled }], + async function ({ + // eslint-disable-next-line no-shadow + disabled, + }) { + let resetBox = content.document.getElementById("reset-box"); + let elementStyle = content.window.getComputedStyle(resetBox); + let expectedDisplayValue = disabled ? "none" : "block"; + is( + elementStyle.display, + expectedDisplayValue, + "about:support Reset button box should be hidden" + ); + } + ); + await BrowserTestUtils.removeTab(tab); +} + +add_task(async function test_initial_conditions() { + await test_reset_disabled({ disabled: false }); +}); + +add_task(async function test_policy_disable_reset() { + await setupPolicyEngineWithJson({ + policies: { + DisableProfileRefresh: true, + }, + }); + await test_reset_disabled({ disabled: true }); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_safemode.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_safemode.js new file mode 100644 index 0000000000..a2787079d0 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_safemode.js @@ -0,0 +1,57 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +add_setup(async function () { + await setupPolicyEngineWithJson({ + policies: { + DisableSafeMode: true, + }, + }); +}); + +add_task(async function test_help_menu() { + buildHelpMenu(); + let safeModeMenu = document.getElementById("helpSafeMode"); + is( + safeModeMenu.getAttribute("disabled"), + "true", + "The `Restart with Add-ons Disabled...` item should be disabled" + ); +}); + +add_task(async function test_safemode_from_about_support() { + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + "about:support" + ); + + await SpecialPowers.spawn(tab.linkedBrowser, [], async function () { + let button = content.document.getElementById("restart-in-safe-mode-button"); + is( + button.getAttribute("disabled"), + "true", + "The `Restart with Add-ons Disabled...` button should be disabled" + ); + }); + + await BrowserTestUtils.removeTab(tab); +}); + +add_task(async function test_safemode_from_about_profiles() { + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + "about:profiles" + ); + + await SpecialPowers.spawn(tab.linkedBrowser, [], async function () { + let button = content.document.getElementById("restart-in-safe-mode-button"); + is( + button.getAttribute("disabled"), + "true", + "The `Restart with Add-ons Disabled...` button should be disabled" + ); + }); + + await BrowserTestUtils.removeTab(tab); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_shield.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_shield.js new file mode 100644 index 0000000000..ef36a0d36c --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_shield.js @@ -0,0 +1,68 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_policy_disable_shield() { + const { RecipeRunner } = ChromeUtils.importESModule( + "resource://normandy/lib/RecipeRunner.sys.mjs" + ); + const { BaseAction } = ChromeUtils.importESModule( + "resource://normandy/actions/BaseAction.sys.mjs" + ); + const { BaseStudyAction } = ChromeUtils.importESModule( + "resource://normandy/actions/BaseStudyAction.sys.mjs" + ); + + const baseAction = new BaseAction(); + const baseStudyAction = new BaseStudyAction(); + + await SpecialPowers.pushPrefEnv({ + set: [ + ["app.normandy.api_url", "https://localhost/selfsupport-dummy/"], + ["app.shield.optoutstudies.enabled", true], + ], + }); + + ok(RecipeRunner, "RecipeRunner exists"); + + RecipeRunner.checkPrefs(); + ok(RecipeRunner.enabled, "RecipeRunner is enabled"); + + baseAction._preExecution(); + is( + baseAction.state, + BaseAction.STATE_PREPARING, + "Base action is not disabled" + ); + + baseStudyAction._preExecution(); + is( + baseStudyAction.state, + BaseAction.STATE_PREPARING, + "Base study action is not disabled" + ); + + await setupPolicyEngineWithJson({ + policies: { + DisableFirefoxStudies: true, + }, + }); + + RecipeRunner.checkPrefs(); + ok(RecipeRunner.enabled, "RecipeRunner is still enabled"); + + baseAction._preExecution(); + is( + baseAction.state, + BaseAction.STATE_PREPARING, + "Base action is not disabled" + ); + + baseStudyAction._preExecution(); + is( + baseStudyAction.state, + BaseAction.STATE_DISABLED, + "Base study action is disabled" + ); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_telemetry.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_telemetry.js new file mode 100644 index 0000000000..3070df0d88 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_telemetry.js @@ -0,0 +1,28 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_policy_disable_telemetry() { + const { TelemetryReportingPolicy } = ChromeUtils.importESModule( + "resource://gre/modules/TelemetryReportingPolicy.sys.mjs" + ); + + ok(TelemetryReportingPolicy, "TelemetryReportingPolicy exists"); + is(TelemetryReportingPolicy.canUpload(), true, "Telemetry is enabled"); + + await setupPolicyEngineWithJson({ + policies: { + DisableTelemetry: true, + }, + }); + + is(TelemetryReportingPolicy.canUpload(), false, "Telemetry is disabled"); + is( + Services.prefs.getBoolPref("toolkit.telemetry.archive.enabled"), + false, + "Telemetry archive should be disabled." + ); + + await testPageBlockedByPolicy("about:telemetry"); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_display_bookmarks.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_display_bookmarks.js new file mode 100644 index 0000000000..8c43cbc8e1 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_display_bookmarks.js @@ -0,0 +1,86 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Since testing will apply the policy after the browser has already started, +// we will need to open a new window to actually see the toolbar + +add_task(async function test_personaltoolbar_shown_old() { + await setupPolicyEngineWithJson({ + policies: { + DisplayBookmarksToolbar: true, + }, + }); + let newWin = await BrowserTestUtils.openNewBrowserWindow(); + let menuBar = newWin.document.getElementById("PersonalToolbar"); + is( + menuBar.getAttribute("collapsed"), + "false", + "The bookmarks toolbar should not be hidden" + ); + + await BrowserTestUtils.closeWindow(newWin); +}); + +add_task(async function test_personaltoolbar_shown() { + await setupPolicyEngineWithJson({ + policies: { + DisplayBookmarksToolbar: "always", + }, + }); + + let newWin = await BrowserTestUtils.openNewBrowserWindow(); + let menuBar = newWin.document.getElementById("PersonalToolbar"); + is( + menuBar.getAttribute("collapsed"), + "false", + "The bookmarks toolbar should not be hidden" + ); + + await BrowserTestUtils.closeWindow(newWin); +}); + +add_task(async function test_personaltoolbar_hidden() { + await setupPolicyEngineWithJson({ + policies: { + DisplayBookmarksToolbar: "never", + }, + }); + + let newWin = await BrowserTestUtils.openNewBrowserWindow(); + let menuBar = newWin.document.getElementById("PersonalToolbar"); + is( + menuBar.getAttribute("collapsed"), + "true", + "The bookmarks toolbar should be hidden" + ); + + await BrowserTestUtils.closeWindow(newWin); +}); + +add_task(async function test_personaltoolbar_newtabonly() { + await setupPolicyEngineWithJson({ + policies: { + DisplayBookmarksToolbar: "newtab", + }, + }); + + let newWin = await BrowserTestUtils.openNewBrowserWindow(); + let menuBar = newWin.document.getElementById("PersonalToolbar"); + is( + menuBar.getAttribute("collapsed"), + "true", + "The bookmarks toolbar should be hidden" + ); + + await BrowserTestUtils.openNewForegroundTab(newWin.gBrowser, "about:newtab"); + menuBar = newWin.document.getElementById("PersonalToolbar"); + is( + menuBar.getAttribute("collapsed"), + "false", + "The bookmarks toolbar should not be hidden" + ); + + await BrowserTestUtils.closeWindow(newWin); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_display_menu.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_display_menu.js new file mode 100644 index 0000000000..9560a1aaf1 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_display_menu.js @@ -0,0 +1,84 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_menu_shown_boolean() { + await setupPolicyEngineWithJson({ + policies: { + DisplayMenuBar: true, + }, + }); + + // Since testing will apply the policy after the browser has already started, + // we will need to open a new window to actually see the menu bar + let newWin = await BrowserTestUtils.openNewBrowserWindow(); + let menubar = newWin.document.getElementById("toolbar-menubar"); + is( + menubar.getAttribute("autohide"), + "false", + "The menu bar should not be hidden" + ); + + await BrowserTestUtils.closeWindow(newWin); +}); + +add_task(async function test_menu_shown_string() { + await setupPolicyEngineWithJson({ + policies: { + DisplayMenuBar: "default-on", + }, + }); + + // Since testing will apply the policy after the browser has already started, + // we will need to open a new window to actually see the menu bar + let newWin = await BrowserTestUtils.openNewBrowserWindow(); + let menubar = newWin.document.getElementById("toolbar-menubar"); + is( + menubar.getAttribute("autohide"), + "false", + "The menu bar should not be hidden" + ); + + await BrowserTestUtils.closeWindow(newWin); +}); + +add_task(async function test_menubar_on() { + await setupPolicyEngineWithJson({ + policies: { + DisplayMenuBar: "always", + }, + }); + + let newWin = await BrowserTestUtils.openNewBrowserWindow(); + let menubar = newWin.document.getElementById("toolbar-menubar"); + is( + menubar.hasAttribute("inactive"), + false, + "Menu bar should not have inactive" + ); + is( + menubar.hasAttribute("toolbarname"), + false, + "Menu bar should not have a toolbarname" + ); + await BrowserTestUtils.closeWindow(newWin); +}); + +add_task(async function test_menubar_off() { + await setupPolicyEngineWithJson({ + policies: { + DisplayMenuBar: "never", + }, + }); + + let newWin = await BrowserTestUtils.openNewBrowserWindow(); + let menubar = newWin.document.getElementById("toolbar-menubar"); + is(menubar.hasAttribute("inactive"), true, "Menu bar should have inactive"); + is( + menubar.hasAttribute("toolbarname"), + false, + "Menu bar should not have a toolbarname" + ); + await BrowserTestUtils.closeWindow(newWin); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_downloads.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_downloads.js new file mode 100644 index 0000000000..163745aaaf --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_downloads.js @@ -0,0 +1,147 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const UCT_URI = "chrome://mozapps/content/downloads/unknownContentType.xhtml"; + +add_task(async function test_defaultdownload() { + await setupPolicyEngineWithJson({ + policies: { + DefaultDownloadDirectory: "${home}/Downloads", + PromptForDownloadLocation: false, + }, + }); + + await BrowserTestUtils.withNewTab("about:preferences", async browser => { + is( + browser.contentDocument.getElementById("alwaysAsk").disabled, + true, + "alwaysAsk should be disabled." + ); + let home = Services.dirsvc.get("Home", Ci.nsIFile).path; + is( + Services.prefs.getStringPref("browser.download.dir"), + home + "/Downloads", + "browser.download.dir should be ${home}/Downloads." + ); + is( + Services.prefs.getBoolPref("browser.download.useDownloadDir"), + true, + "browser.download.useDownloadDir should be true." + ); + is( + Services.prefs.prefIsLocked("browser.download.useDownloadDir"), + true, + "browser.download.useDownloadDir should be locked." + ); + }); +}); + +add_task(async function test_download() { + await setupPolicyEngineWithJson({ + policies: { + DownloadDirectory: "${home}/Documents", + }, + }); + + await BrowserTestUtils.withNewTab("about:preferences", async browser => { + is( + browser.contentDocument.getElementById("alwaysAsk").disabled, + true, + "alwaysAsk should be disabled." + ); + is( + browser.contentDocument.getElementById("downloadFolder").disabled, + true, + "downloadFolder should be disabled." + ); + is( + browser.contentDocument.getElementById("chooseFolder").disabled, + true, + "chooseFolder should be disabled." + ); + let home = Services.dirsvc.get("Home", Ci.nsIFile).path; + is( + Services.prefs.getStringPref("browser.download.dir"), + home + "/Documents", + "browser.download.dir should be ${home}/Documents." + ); + is( + Services.prefs.getBoolPref("browser.download.useDownloadDir"), + true, + "browser.download.useDownloadDir should be true." + ); + is( + Services.prefs.prefIsLocked("browser.download.useDownloadDir"), + true, + "browser.download.useDownloadDir should be locked." + ); + }); +}); + +async function setDownloadDir() { + let tmpDir = PathUtils.join( + PathUtils.tempDir, + "testsavedir" + Math.floor(Math.random() * 2 ** 32) + ); + // Create this dir if it doesn't exist (ignores existing dirs) + await IOUtils.makeDirectory(tmpDir); + registerCleanupFunction(async function () { + try { + await IOUtils.remove(tmpDir, { recursive: true }); + } catch (e) { + console.error(e); + } + }); + Services.prefs.setIntPref("browser.download.folderList", 2); + Services.prefs.setCharPref("browser.download.dir", tmpDir); + return tmpDir; +} + +add_task(async function test_tmpdir_download() { + await setupPolicyEngineWithJson({ + policies: { + StartDownloadsInTempDirectory: true, + }, + }); + + await SpecialPowers.pushPrefEnv({ + set: [ + ["browser.download.always_ask_before_handling_new_types", true], + ["browser.helperApps.deleteTempFileOnExit", true], + ], + }); + + let dlDir = new FileUtils.File(await setDownloadDir()); + registerCleanupFunction(() => { + Services.prefs.clearUserPref("browser.download.dir"); + Services.prefs.clearUserPref("browser.download.folderList"); + }); + + // Wait for the download prompting dialog + let dialogPromise = BrowserTestUtils.domWindowOpenedAndLoaded( + null, + win => win.document.documentURI == UCT_URI + ); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: "https://example.com/browser/browser/components/downloads/test/browser/foo.txt", + waitForLoad: false, + waitForStop: true, + }, + async function () { + let dialogWin = await dialogPromise; + let tempFile = dialogWin.dialog.mLauncher.targetFile; + isnot( + tempFile.parent.path, + dlDir.path, + "Should not have put temp file in the downloads dir." + ); + + dialogWin.close(); + } + ); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_extensions.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_extensions.js new file mode 100644 index 0000000000..7d1313548b --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_extensions.js @@ -0,0 +1,117 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +const ADDON_ID = "policytest@mozilla.com"; +const BASE_URL = + "http://mochi.test:8888/browser/browser/components/enterprisepolicies/tests/browser"; + +async function isExtensionLocked(win, addonID) { + let addonCard = await TestUtils.waitForCondition(() => { + return win.document.querySelector(`addon-card[addon-id="${addonID}"]`); + }, `Get addon-card for "${addonID}"`); + let disableBtn = addonCard.querySelector('[action="toggle-disabled"]'); + let removeBtn = addonCard.querySelector('panel-item[action="remove"]'); + ok(removeBtn.disabled, "Remove button should be disabled"); + ok(disableBtn.hidden, "Disable button should be hidden"); +} + +add_task(async function test_addon_install() { + let installPromise = waitForAddonInstall(ADDON_ID); + await setupPolicyEngineWithJson({ + policies: { + Extensions: { + Install: [`${BASE_URL}/policytest_v0.1.xpi`], + Locked: [ADDON_ID], + }, + }, + }); + await installPromise; + let addon = await AddonManager.getAddonByID(ADDON_ID); + isnot(addon, null, "Addon not installed."); + is(addon.version, "0.1", "Addon version is correct"); + + Assert.deepEqual( + addon.installTelemetryInfo, + { source: "enterprise-policy" }, + "Got the expected addon.installTelemetryInfo" + ); +}); + +add_task(async function test_addon_locked() { + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser); + const win = await BrowserOpenAddonsMgr("addons://list/extension"); + + await isExtensionLocked(win, ADDON_ID); + + BrowserTestUtils.removeTab(tab); +}); + +add_task(async function test_addon_reinstall() { + // Test that uninstalling and reinstalling the same addon ID works as expected. + // This can be used to update an addon. + + let uninstallPromise = waitForAddonUninstall(ADDON_ID); + let installPromise = waitForAddonInstall(ADDON_ID); + await setupPolicyEngineWithJson({ + policies: { + Extensions: { + Uninstall: [ADDON_ID], + Install: [`${BASE_URL}/policytest_v0.2.xpi`], + }, + }, + }); + + // Older version was uninstalled + await uninstallPromise; + + // New version was installed + await installPromise; + + let addon = await AddonManager.getAddonByID(ADDON_ID); + isnot( + addon, + null, + "Addon still exists because the policy was used to update it." + ); + is(addon.version, "0.2", "New version is correct"); +}); + +add_task(async function test_addon_uninstall() { + EnterprisePolicyTesting.resetRunOnceState(); + + let uninstallPromise = waitForAddonUninstall(ADDON_ID); + await setupPolicyEngineWithJson({ + policies: { + Extensions: { + Uninstall: [ADDON_ID], + }, + }, + }); + await uninstallPromise; + let addon = await AddonManager.getAddonByID(ADDON_ID); + is(addon, null, "Addon should be uninstalled."); +}); + +add_task(async function test_addon_download_failure() { + // Test that if the download fails, the runOnce pref + // is cleared so that the download will happen again. + + let installPromise = waitForAddonInstall(ADDON_ID); + await setupPolicyEngineWithJson({ + policies: { + Extensions: { + Install: [`${BASE_URL}/policytest_invalid.xpi`], + }, + }, + }); + + await installPromise; + is( + Services.prefs.prefHasUserValue( + "browser.policies.runOncePerModification.extensionsInstall" + ), + false, + "runOnce pref should be unset" + ); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_extensionsettings.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_extensionsettings.js new file mode 100644 index 0000000000..08dbcff6e2 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_extensionsettings.js @@ -0,0 +1,261 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +const BASE_URL = + "http://mochi.test:8888/browser/browser/components/enterprisepolicies/tests/browser/"; + +/** + * Wait for the given PopupNotification to display + * + * @param {string} name + * The name of the notification to wait for. + * + * @returns {Promise} + * Resolves with the notification window. + */ +function promisePopupNotificationShown(name) { + return new Promise(resolve => { + function popupshown() { + let notification = PopupNotifications.getNotification(name); + if (!notification) { + return; + } + + ok(notification, `${name} notification shown`); + ok(PopupNotifications.isPanelOpen, "notification panel open"); + + PopupNotifications.panel.removeEventListener("popupshown", popupshown); + resolve(PopupNotifications.panel.firstElementChild); + } + + PopupNotifications.panel.addEventListener("popupshown", popupshown); + }); +} + +add_setup(async function setupTestEnvironment() { + // Once InstallTrigger is removed, the tests targeting InstallTrigger should + // be removed or adapted to don't use InstallTrigger. + await SpecialPowers.pushPrefEnv({ + set: [ + ["extensions.InstallTrigger.enabled", true], + ["extensions.InstallTriggerImpl.enabled", true], + // Relax the user input requirements while running this test. + ["xpinstall.userActivation.required", false], + ], + }); +}); + +add_task(async function test_install_source_blocked_link() { + await setupPolicyEngineWithJson({ + policies: { + ExtensionSettings: { + "*": { + install_sources: ["http://blocks.other.install.sources/*"], + }, + }, + }, + }); + let popupPromise = promisePopupNotificationShown( + "addon-install-policy-blocked" + ); + let tab = await BrowserTestUtils.openNewForegroundTab({ + gBrowser, + opening: BASE_URL + "extensionsettings.html", + waitForStateStop: true, + }); + + await SpecialPowers.spawn(tab.linkedBrowser, [], () => { + content.document.getElementById("policytest").click(); + }); + await popupPromise; + BrowserTestUtils.removeTab(tab); +}); + +add_task(async function test_install_source_blocked_installtrigger() { + await setupPolicyEngineWithJson({ + policies: { + ExtensionSettings: { + "*": { + install_sources: ["http://blocks.other.install.sources/*"], + blocked_install_message: "blocked_install_message", + }, + }, + }, + }); + let popupPromise = promisePopupNotificationShown( + "addon-install-policy-blocked" + ); + let tab = await BrowserTestUtils.openNewForegroundTab({ + gBrowser, + opening: BASE_URL + "extensionsettings.html", + waitForStateStop: true, + }); + + await SpecialPowers.spawn(tab.linkedBrowser, [], () => { + content.document.getElementById("policytest_installtrigger").click(); + }); + let popup = await popupPromise; + let description = popup.querySelector(".popup-notification-description"); + ok( + description.textContent.endsWith("blocked_install_message"), + "Custom install message present" + ); + BrowserTestUtils.removeTab(tab); +}); + +add_task(async function test_install_source_blocked_otherdomain() { + await setupPolicyEngineWithJson({ + policies: { + ExtensionSettings: { + "*": { + install_sources: ["http://mochi.test/*"], + }, + }, + }, + }); + let popupPromise = promisePopupNotificationShown( + "addon-install-policy-blocked" + ); + let tab = await BrowserTestUtils.openNewForegroundTab({ + gBrowser, + opening: BASE_URL + "extensionsettings.html", + waitForStateStop: true, + }); + + await SpecialPowers.spawn(tab.linkedBrowser, [], () => { + content.document.getElementById("policytest_otherdomain").click(); + }); + await popupPromise; + BrowserTestUtils.removeTab(tab); +}); + +add_task(async function test_install_source_blocked_direct() { + await setupPolicyEngineWithJson({ + policies: { + ExtensionSettings: { + "*": { + install_sources: ["http://blocks.other.install.sources/*"], + }, + }, + }, + }); + let popupPromise = promisePopupNotificationShown( + "addon-install-policy-blocked" + ); + let tab = await BrowserTestUtils.openNewForegroundTab({ + gBrowser, + opening: BASE_URL + "extensionsettings.html", + waitForStateStop: true, + }); + + await SpecialPowers.spawn( + tab.linkedBrowser, + [{ baseUrl: BASE_URL }], + async function ({ baseUrl }) { + content.document.location.href = baseUrl + "policytest_v0.1.xpi"; + } + ); + await popupPromise; + BrowserTestUtils.removeTab(tab); +}); + +add_task(async function test_install_source_allowed_link() { + await setupPolicyEngineWithJson({ + policies: { + ExtensionSettings: { + "*": { + install_sources: ["http://mochi.test/*"], + }, + }, + }, + }); + let popupPromise = promisePopupNotificationShown("addon-webext-permissions"); + let tab = await BrowserTestUtils.openNewForegroundTab({ + gBrowser, + opening: BASE_URL + "extensionsettings.html", + waitForStateStop: true, + }); + + await SpecialPowers.spawn(tab.linkedBrowser, [], () => { + content.document.getElementById("policytest").click(); + }); + await popupPromise; + BrowserTestUtils.removeTab(tab); +}); + +add_task(async function test_install_source_allowed_installtrigger() { + await setupPolicyEngineWithJson({ + policies: { + ExtensionSettings: { + "*": { + install_sources: ["http://mochi.test/*"], + }, + }, + }, + }); + let popupPromise = promisePopupNotificationShown("addon-webext-permissions"); + let tab = await BrowserTestUtils.openNewForegroundTab({ + gBrowser, + opening: BASE_URL + "extensionsettings.html", + waitForStateStop: true, + }); + + await SpecialPowers.spawn(tab.linkedBrowser, [], () => { + content.document.getElementById("policytest_installtrigger").click(); + }); + await popupPromise; + BrowserTestUtils.removeTab(tab); +}); + +add_task(async function test_install_source_allowed_otherdomain() { + await setupPolicyEngineWithJson({ + policies: { + ExtensionSettings: { + "*": { + install_sources: ["http://mochi.test/*", "http://example.org/*"], + }, + }, + }, + }); + let popupPromise = promisePopupNotificationShown("addon-webext-permissions"); + let tab = await BrowserTestUtils.openNewForegroundTab({ + gBrowser, + opening: BASE_URL + "extensionsettings.html", + waitForStateStop: true, + }); + + await SpecialPowers.spawn(tab.linkedBrowser, [], () => { + content.document.getElementById("policytest_otherdomain").click(); + }); + await popupPromise; + BrowserTestUtils.removeTab(tab); +}); + +add_task(async function test_install_source_allowed_direct() { + await setupPolicyEngineWithJson({ + policies: { + ExtensionSettings: { + "*": { + install_sources: ["http://mochi.test/*"], + }, + }, + }, + }); + let popupPromise = promisePopupNotificationShown("addon-webext-permissions"); + let tab = await BrowserTestUtils.openNewForegroundTab({ + gBrowser, + opening: BASE_URL + "extensionsettings.html", + waitForStateStop: true, + }); + + await SpecialPowers.spawn( + tab.linkedBrowser, + [{ baseUrl: BASE_URL }], + async function ({ baseUrl }) { + content.document.location.href = baseUrl + "policytest_v0.1.xpi"; + } + ); + await popupPromise; + BrowserTestUtils.removeTab(tab); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_extensionsettings2.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_extensionsettings2.js new file mode 100644 index 0000000000..612448ee4e --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_extensionsettings2.js @@ -0,0 +1,71 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +const ADDON_ID = "policytest@mozilla.com"; +const BASE_URL = + "http://mochi.test:8888/browser/browser/components/enterprisepolicies/tests/browser"; + +async function isExtensionLockedAndUpdateDisabled(win, addonID) { + let addonCard = await BrowserTestUtils.waitForCondition(() => { + return win.document.querySelector(`addon-card[addon-id="${addonID}"]`); + }, `Get addon-card for "${addonID}"`); + let disableBtn = addonCard.querySelector('[action="toggle-disabled"]'); + let removeBtn = addonCard.querySelector('panel-item[action="remove"]'); + ok(removeBtn.disabled, "Remove button should be disabled"); + ok(disableBtn.hidden, "Disable button should be hidden"); + let updateRow = addonCard.querySelector(".addon-detail-row-updates"); + is(updateRow.hidden, true, "Update row should be hidden"); +} + +add_task(async function test_addon_install() { + let installPromise = waitForAddonInstall(ADDON_ID); + await setupPolicyEngineWithJson({ + policies: { + ExtensionSettings: { + "policytest@mozilla.com": { + install_url: `${BASE_URL}/policytest_v0.1.xpi`, + installation_mode: "force_installed", + updates_disabled: true, + }, + }, + }, + }); + await installPromise; + let addon = await AddonManager.getAddonByID(ADDON_ID); + isnot(addon, null, "Addon not installed."); + is(addon.version, "0.1", "Addon version is correct"); + + Assert.deepEqual( + addon.installTelemetryInfo, + { source: "enterprise-policy" }, + "Got the expected addon.installTelemetryInfo" + ); +}); + +add_task(async function test_addon_locked_update_disabled() { + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser); + const win = await BrowserOpenAddonsMgr( + "addons://detail/" + encodeURIComponent(ADDON_ID) + ); + + await isExtensionLockedAndUpdateDisabled(win, ADDON_ID); + + BrowserTestUtils.removeTab(tab); +}); + +add_task(async function test_addon_uninstall() { + let uninstallPromise = waitForAddonUninstall(ADDON_ID); + await setupPolicyEngineWithJson({ + policies: { + ExtensionSettings: { + "policytest@mozilla.com": { + installation_mode: "blocked", + }, + }, + }, + }); + await uninstallPromise; + let addon = await AddonManager.getAddonByID(ADDON_ID); + is(addon, null, "Addon should be uninstalled."); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_firefoxhome.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_firefoxhome.js new file mode 100644 index 0000000000..67afe70c2f --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_firefoxhome.js @@ -0,0 +1,132 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [ + ["browser.newtabpage.activity-stream.feeds.section.highlights", true], + ], + }); +}); + +add_task(async function test_firefox_home_without_policy_without_pocket() { + let tab = await BrowserTestUtils.openNewForegroundTab({ + gBrowser, + opening: "about:home", + waitForStateStop: true, + }); + + await SpecialPowers.spawn(tab.linkedBrowser, [], function () { + let search = content.document.querySelector(".search-wrapper"); + isnot(search, null, "Search section should be there."); + let topsites = content.document.querySelector( + "section[data-section-id='topsites']" + ); + isnot(topsites, null, "Top Sites section should be there."); + let highlights = content.document.querySelector( + "section[data-section-id='highlights']" + ); + isnot(highlights, null, "Highlights section should be there."); + }); + BrowserTestUtils.removeTab(tab); + await SpecialPowers.popPrefEnv(); +}); + +add_task(async function test_firefox_home_with_policy() { + await SpecialPowers.pushPrefEnv({ + set: [ + [ + "browser.newtabpage.activity-stream.discoverystream.endpointSpocsClear", + "", + ], + ], + }); + + await setupPolicyEngineWithJson({ + policies: { + FirefoxHome: { + Search: false, + TopSites: false, + Highlights: false, + Snippets: false, + }, + }, + }); + + let tab = await BrowserTestUtils.openNewForegroundTab({ + gBrowser, + opening: "about:home", + waitForStateStop: true, + }); + + await SpecialPowers.spawn(tab.linkedBrowser, [], function () { + let search = content.document.querySelector(".search-wrapper"); + is(search, null, "Search section should not be there."); + let topsites = content.document.querySelector( + "section[data-section-id='topsites']" + ); + is(topsites, null, "Top Sites section should not be there."); + let highlights = content.document.querySelector( + "section[data-section-id='highlights']" + ); + is(highlights, null, "Highlights section should not be there."); + }); + BrowserTestUtils.removeTab(tab); + await SpecialPowers.popPrefEnv(); +}); + +add_task(async function test_firefoxhome_preferences_set() { + await SpecialPowers.pushPrefEnv({ + set: [ + [ + "browser.newtabpage.activity-stream.discoverystream.endpointSpocsClear", + "", + ], + ], + }); + + await setupPolicyEngineWithJson({ + policies: { + FirefoxHome: { + Search: false, + TopSites: false, + SponsoredTopSites: false, + Highlights: false, + Pocket: false, + SponsoredPocket: false, + Snippets: false, + Locked: true, + }, + }, + }); + + await BrowserTestUtils.withNewTab("about:preferences#home", async browser => { + let data = { + Search: "browser.newtabpage.activity-stream.showSearch", + TopSites: "browser.newtabpage.activity-stream.feeds.topsites", + SponsoredTopSites: + "browser.newtabpage.activity-stream.showSponsoredTopSites", + Highlights: "browser.newtabpage.activity-stream.feeds.section.highlights", + Pocket: "browser.newtabpage.activity-stream.feeds.section.topstories", + SponsoredPocket: "browser.newtabpage.activity-stream.showSponsored", + Snippets: "browser.newtabpage.activity-stream.feeds.snippets", + }; + for (let [section, preference] of Object.entries(data)) { + is( + browser.contentDocument.querySelector( + `checkbox[preference='${preference}']` + ).disabled, + true, + `${section} checkbox should be disabled` + ); + } + }); + await setupPolicyEngineWithJson({ + policies: { + FirefoxHome: {}, + }, + }); + await SpecialPowers.popPrefEnv(); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_firefoxsuggest.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_firefoxsuggest.js new file mode 100644 index 0000000000..e6f7b02772 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_firefoxsuggest.js @@ -0,0 +1,63 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_firefox_suggest_with_policy() { + await setupPolicyEngineWithJson({ + policies: { + FirefoxSuggest: { + WebSuggestions: false, + SponsoredSuggestions: true, + ImproveSuggest: true, + Locked: true, + }, + }, + }); + + await BrowserTestUtils.withNewTab( + "about:preferences#privacy", + async browser => { + is( + browser.contentDocument.getElementById( + "firefoxSuggestNonsponsoredToggle" + ).pressed, + false, + "Web suggestions is disabled" + ); + is( + browser.contentDocument.getElementById("firefoxSuggestSponsoredToggle") + .pressed, + true, + "Sponsored suggestions is enabled" + ); + is( + browser.contentDocument.getElementById( + "firefoxSuggestDataCollectionToggle" + ).pressed, + true, + "Improve suggest is enabled" + ); + is( + browser.contentDocument.getElementById( + "firefoxSuggestNonsponsoredToggle" + ).disabled, + true, + "Web suggestions is disabled" + ); + is( + browser.contentDocument.getElementById("firefoxSuggestSponsoredToggle") + .disabled, + true, + "Sponsored suggestions is enabled" + ); + is( + browser.contentDocument.getElementById( + "firefoxSuggestDataCollectionToggle" + ).disabled, + true, + "Improve suggest is enabled" + ); + } + ); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_handlers.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_handlers.js new file mode 100644 index 0000000000..45debf73c9 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_handlers.js @@ -0,0 +1,183 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const gMIMEService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService); + +const gExternalProtocolService = Cc[ + "@mozilla.org/uriloader/external-protocol-service;1" +].getService(Ci.nsIExternalProtocolService); + +const gHandlerService = Cc[ + "@mozilla.org/uriloader/handler-service;1" +].getService(Ci.nsIHandlerService); + +// This seems odd, but for test purposes, this just has to be a file that we know exists, +// and by using this file, we don't have to worry about different platforms. +let exeFile = Services.dirsvc.get("XREExeF", Ci.nsIFile); + +add_task(async function test_valid_handlers() { + await setupPolicyEngineWithJson({ + policies: { + Handlers: { + mimeTypes: { + "application/marimba": { + action: "useHelperApp", + ask: true, + handlers: [ + { + name: "Launch", + path: exeFile.path, + }, + ], + }, + }, + schemes: { + fake_scheme: { + action: "useHelperApp", + ask: false, + handlers: [ + { + name: "Name", + uriTemplate: "https://www.example.org/?%s", + }, + ], + }, + }, + extensions: { + txt: { + action: "saveToDisk", + ask: false, + }, + }, + }, + }, + }); + + let handlerInfo = gMIMEService.getFromTypeAndExtension( + "application/marimba", + "" + ); + is(handlerInfo.preferredAction, handlerInfo.useHelperApp); + is(handlerInfo.alwaysAskBeforeHandling, true); + is(handlerInfo.preferredApplicationHandler.name, "Launch"); + is(handlerInfo.preferredApplicationHandler.executable.path, exeFile.path); + + handlerInfo.preferredApplicationHandler = null; + gHandlerService.store(handlerInfo); + + handlerInfo = handlerInfo = gMIMEService.getFromTypeAndExtension( + "application/marimba", + "" + ); + is(handlerInfo.preferredApplicationHandler, null); + + gHandlerService.remove(handlerInfo); + + handlerInfo = gExternalProtocolService.getProtocolHandlerInfo("fake_scheme"); + is(handlerInfo.preferredAction, handlerInfo.useHelperApp); + is(handlerInfo.alwaysAskBeforeHandling, false); + is(handlerInfo.preferredApplicationHandler.name, "Name"); + is( + handlerInfo.preferredApplicationHandler.uriTemplate, + "https://www.example.org/?%s" + ); + + handlerInfo.preferredApplicationHandler = null; + gHandlerService.store(handlerInfo); + + handlerInfo = gExternalProtocolService.getProtocolHandlerInfo("fake_scheme"); + is(handlerInfo.preferredApplicationHandler, null); + + gHandlerService.remove(handlerInfo); + + handlerInfo = gMIMEService.getFromTypeAndExtension("", "txt"); + is(handlerInfo.preferredAction, handlerInfo.saveToDisk); + is(handlerInfo.alwaysAskBeforeHandling, false); + + handlerInfo.preferredApplicationHandler = null; + gHandlerService.store(handlerInfo); + handlerInfo = gMIMEService.getFromTypeAndExtension("", "txt"); + is(handlerInfo.preferredApplicationHandler, null); + + gHandlerService.remove(handlerInfo); +}); + +add_task(async function test_no_handler() { + await setupPolicyEngineWithJson({ + policies: { + Handlers: { + schemes: { + no_handler: { + action: "useHelperApp", + }, + }, + }, + }, + }); + + let handlerInfo = + gExternalProtocolService.getProtocolHandlerInfo("no_handler"); + is(handlerInfo.preferredAction, handlerInfo.alwaysAsk); + is(handlerInfo.alwaysAskBeforeHandling, true); + is(handlerInfo.preferredApplicationHandler, null); + + gHandlerService.remove(handlerInfo); +}); + +add_task(async function test_bad_web_handler1() { + await setupPolicyEngineWithJson({ + policies: { + Handlers: { + schemes: { + bas_web_handler1: { + action: "useHelperApp", + handlers: [ + { + name: "Name", + uriTemplate: "http://www.example.org/?%s", + }, + ], + }, + }, + }, + }, + }); + + let handlerInfo = + gExternalProtocolService.getProtocolHandlerInfo("bad_web_handler1"); + is(handlerInfo.preferredAction, handlerInfo.alwaysAsk); + is(handlerInfo.alwaysAskBeforeHandling, true); + is(handlerInfo.preferredApplicationHandler, null); + + gHandlerService.remove(handlerInfo); +}); + +add_task(async function test_bad_web_handler2() { + await setupPolicyEngineWithJson({ + policies: { + Handlers: { + schemes: { + bas_web_handler1: { + action: "useHelperApp", + handlers: [ + { + name: "Name", + uriTemplate: "http://www.example.org/", + }, + ], + }, + }, + }, + }, + }); + + let handlerInfo = + gExternalProtocolService.getProtocolHandlerInfo("bad_web_handler1"); + is(handlerInfo.preferredAction, handlerInfo.alwaysAsk); + is(handlerInfo.alwaysAskBeforeHandling, true); + is(handlerInfo.preferredApplicationHandler, null); + + gHandlerService.remove(handlerInfo); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_masterpassword.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_masterpassword.js new file mode 100644 index 0000000000..872eb5a652 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_masterpassword.js @@ -0,0 +1,95 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +let { LoginTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/LoginTestUtils.sys.mjs" +); + +// Test that once a password is set, you can't unset it +add_task(async function test_policy_masterpassword_set() { + await setupPolicyEngineWithJson({ + policies: { + PrimaryPassword: true, + }, + }); + + LoginTestUtils.primaryPassword.enable(); + + await BrowserTestUtils.withNewTab( + "about:preferences#privacy", + async browser => { + is( + browser.contentDocument.getElementById("useMasterPassword").disabled, + true, + "Master Password checkbox should be disabled" + ); + } + ); + + LoginTestUtils.primaryPassword.disable(); +}); + +// Test that password can't be removed in changemp.xhtml +add_task(async function test_policy_nochangemp() { + await setupPolicyEngineWithJson({ + policies: { + PrimaryPassword: true, + }, + }); + + LoginTestUtils.primaryPassword.enable(); + + let changeMPWindow = window.openDialog( + "chrome://mozapps/content/preferences/changemp.xhtml", + "", + "" + ); + await BrowserTestUtils.waitForEvent(changeMPWindow, "load"); + + is( + changeMPWindow.document.getElementById("admin").hidden, + true, + "Admin message should not be visible because there is a password." + ); + + changeMPWindow.document.getElementById("oldpw").value = + LoginTestUtils.primaryPassword.masterPassword; + + is( + changeMPWindow.document.getElementById("changemp").getButton("accept") + .disabled, + true, + "OK button should not be enabled if there is an old password." + ); + + await BrowserTestUtils.closeWindow(changeMPWindow); + + LoginTestUtils.primaryPassword.disable(); +}); + +// Test that admin message shows +add_task(async function test_policy_admin() { + await setupPolicyEngineWithJson({ + policies: { + PrimaryPassword: true, + }, + }); + + let changeMPWindow = window.openDialog( + "chrome://mozapps/content/preferences/changemp.xhtml", + "", + "" + ); + await BrowserTestUtils.waitForEvent(changeMPWindow, "load"); + + is( + changeMPWindow.document.getElementById("admin").hidden, + false, + true, + "Admin message should not be hidden because there is not a password." + ); + + await BrowserTestUtils.closeWindow(changeMPWindow); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_masterpassword_aboutlogins.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_masterpassword_aboutlogins.js new file mode 100644 index 0000000000..91cc9ebc2e --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_masterpassword_aboutlogins.js @@ -0,0 +1,76 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +let { LoginTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/LoginTestUtils.sys.mjs" +); + +// Test that create in about:logins asks for primary password +add_task(async function test_policy_admin() { + await setupPolicyEngineWithJson({ + policies: { + PrimaryPassword: true, + }, + }); + + let aboutLoginsTab = await BrowserTestUtils.openNewForegroundTab({ + gBrowser, + url: "about:logins", + }); + + let browser = gBrowser.selectedBrowser; + + // Fake the subdialog + let dialogURL = ""; + let originalOpenDialog = window.openDialog; + window.openDialog = function (aDialogURL, unused, unused2, aCallback) { + dialogURL = aDialogURL; + if (aCallback) { + aCallback(); + } + }; + + await SpecialPowers.spawn(browser, [], async () => { + let loginList = Cu.waiveXrays(content.document.querySelector("login-list")); + let createButton = loginList._createLoginButton; + ok( + !createButton.disabled, + "Create button should not be disabled initially" + ); + let loginItem = Cu.waiveXrays(content.document.querySelector("login-item")); + + createButton.click(); + + let usernameInput = loginItem.shadowRoot.querySelector( + "input[name='username']" + ); + let originInput = loginItem.shadowRoot.querySelector( + "input[name='origin']" + ); + let passwordInput = loginItem.shadowRoot.querySelector( + "input[name='password']" + ); + + originInput.value = "https://www.example.org"; + usernameInput.value = "testuser1"; + passwordInput.value = "testpass1"; + + let saveChangesButton = loginItem.shadowRoot.querySelector( + ".save-changes-button" + ); + saveChangesButton.click(); + }); + await TestUtils.waitForCondition( + () => dialogURL, + "wait for open to get called asynchronously" + ); + is( + dialogURL, + "chrome://mozapps/content/preferences/changemp.xhtml", + "clicking on the save-changes-button should open the masterpassword dialog" + ); + window.openDialog = originalOpenDialog; + BrowserTestUtils.removeTab(aboutLoginsTab); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_masterpassword_doorhanger.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_masterpassword_doorhanger.js new file mode 100644 index 0000000000..224ad1d275 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_masterpassword_doorhanger.js @@ -0,0 +1,76 @@ +/** + * Test that the doorhanger notification for password saving is populated with + * the correct values in various password capture cases. + */ + +Services.scriptloader.loadSubScript( + "chrome://mochitests/content/browser/toolkit/components/passwordmgr/test/browser/head.js", + this +); + +add_task(async function test_policy_masterpassword_doorhanger() { + await setupPolicyEngineWithJson({ + policies: { + PrimaryPassword: true, + }, + }); + + let username = "username"; + let password = "password"; + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: + "https://example.com/browser/toolkit/components/" + + "passwordmgr/test/browser/form_basic.html", + }, + async function (browser) { + await SimpleTest.promiseFocus(browser.ownerGlobal); + + // Update the form with credentials from the test case. + info(`update form with username: ${username}, password: ${password}`); + await changeContentFormValues(browser, { + "#form-basic-username": username, + "#form-basic-password": password, + }); + + // Submit the form with the new credentials. This will cause the doorhanger + // notification to be displayed. + let formSubmittedPromise = listenForTestNotification("ShowDoorhanger"); + await SpecialPowers.spawn(browser, [], async function () { + let doc = this.content.document; + doc.getElementById("form-basic").submit(); + }); + await formSubmittedPromise; + + let expectedDoorhanger = "password-save"; + + info("Waiting for doorhanger of type: " + expectedDoorhanger); + let notif = await waitForDoorhanger(browser, expectedDoorhanger); + + // Fake the subdialog + let dialogURL = ""; + let originalOpenDialog = window.openDialog; + window.openDialog = function (aDialogURL, unused, unused2, aCallback) { + dialogURL = aDialogURL; + if (aCallback) { + aCallback(); + } + }; + + await clickDoorhangerButton(notif, REMEMBER_BUTTON); + + await TestUtils.waitForCondition( + () => dialogURL, + "wait for open to get called asynchronously" + ); + is( + dialogURL, + "chrome://mozapps/content/preferences/changemp.xhtml", + "clicking on the checkbox should open the masterpassword dialog" + ); + window.openDialog = originalOpenDialog; + } + ); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_offertosavelogins.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_offertosavelogins.js new file mode 100644 index 0000000000..5ad1fe44d1 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_offertosavelogins.js @@ -0,0 +1,23 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_policy_offertosavelogins() { + await setupPolicyEngineWithJson({ + policies: { + OfferToSaveLogins: false, + }, + }); + + await BrowserTestUtils.withNewTab( + "about:preferences#privacy", + async browser => { + is( + browser.contentDocument.getElementById("savePasswords").disabled, + true, + "Save passwords is disabled" + ); + } + ); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_override_postupdatepage.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_override_postupdatepage.js new file mode 100644 index 0000000000..2208ee955f --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_override_postupdatepage.js @@ -0,0 +1,132 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +// This test was based on the test browser_bug538331.js + +const UPDATE_PROVIDED_PAGE = "https://default.example.com/"; +const POLICY_PROVIDED_PAGE = "https://policy.example.com/"; + +const PREF_MSTONE = "browser.startup.homepage_override.mstone"; + +/* + * The important parts for this test are: + * - actions="showURL" + * - openURL="${UPDATE_PROVIDED_PAGE}" + */ +const XML_UPDATE = ` + + + + +`; + +add_task(async function test_override_postupdate_page() { + let originalMstone = Services.prefs.getCharPref(PREF_MSTONE); + // Set the preferences needed for the test: they will be cleared up + // after it runs. + await SpecialPowers.pushPrefEnv({ set: [[PREF_MSTONE, originalMstone]] }); + + registerCleanupFunction(async () => { + let activeUpdateFile = getActiveUpdateFile(); + activeUpdateFile.remove(false); + reloadUpdateManagerData(true); + }); + + writeUpdatesToXMLFile(XML_UPDATE); + reloadUpdateManagerData(false); + + is( + getPostUpdatePage(), + UPDATE_PROVIDED_PAGE, + "Post-update page was provided by active-update.xml." + ); + + // Now perform the same action but set the policy to override this page + await setupPolicyEngineWithJson({ + policies: { + OverridePostUpdatePage: POLICY_PROVIDED_PAGE, + }, + }); + + is( + getPostUpdatePage(), + POLICY_PROVIDED_PAGE, + "Post-update page was provided by policy." + ); +}); + +function getPostUpdatePage() { + Services.prefs.setCharPref(PREF_MSTONE, "PreviousMilestone"); + return Cc["@mozilla.org/browser/clh;1"].getService(Ci.nsIBrowserHandler) + .defaultArgs; +} + +/** + * Removes the updates.xml file and returns the nsIFile for the + * active-update.xml file. + * + * @return The nsIFile for the active-update.xml file. + */ +function getActiveUpdateFile() { + let updateRootDir = Services.dirsvc.get("UpdRootD", Ci.nsIFile); + let updatesFile = updateRootDir.clone(); + updatesFile.append("updates.xml"); + if (updatesFile.exists()) { + // The following is non-fatal. + try { + updatesFile.remove(false); + } catch (e) {} + } + let activeUpdateFile = updateRootDir.clone(); + activeUpdateFile.append("active-update.xml"); + return activeUpdateFile; +} + +/** + * Reloads the update xml files. + * + * @param skipFiles (optional) + * If true, the update xml files will not be read and the metadata will + * be reset. If false (the default), the update xml files will be read + * to populate the update metadata. + */ +function reloadUpdateManagerData(skipFiles = false) { + Cc["@mozilla.org/updates/update-manager;1"] + .getService(Ci.nsIUpdateManager) + .QueryInterface(Ci.nsIObserver) + .observe(null, "um-reload-update-data", skipFiles ? "skip-files" : ""); +} + +/** + * Writes the updates specified to the active-update.xml file. + * + * @param aText + * The updates represented as a string to write to the active-update.xml + * file. + */ +function writeUpdatesToXMLFile(aText) { + const PERMS_FILE = 0o644; + + const MODE_WRONLY = 0x02; + const MODE_CREATE = 0x08; + const MODE_TRUNCATE = 0x20; + + let activeUpdateFile = getActiveUpdateFile(); + if (!activeUpdateFile.exists()) { + activeUpdateFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, PERMS_FILE); + } + let fos = Cc["@mozilla.org/network/file-output-stream;1"].createInstance( + Ci.nsIFileOutputStream + ); + let flags = MODE_WRONLY | MODE_CREATE | MODE_TRUNCATE; + fos.init(activeUpdateFile, flags, PERMS_FILE, 0); + fos.write(aText, aText.length); + fos.close(); +} diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_pageinfo_permissions.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_pageinfo_permissions.js new file mode 100644 index 0000000000..4921464782 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_pageinfo_permissions.js @@ -0,0 +1,76 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +const TEST_ORIGIN = "https://example.com"; + +/* Verifies that items on the page info page are properly disabled + when the corresponding policies are locked */ +add_task(async function test_pageinfo_permissions() { + await setupPolicyEngineWithJson({ + policies: { + Permissions: { + Camera: { + BlockNewRequests: true, + Locked: true, + }, + Microphone: { + BlockNewRequests: true, + Locked: true, + }, + Location: { + BlockNewRequests: true, + Locked: true, + }, + Notifications: { + BlockNewRequests: true, + Locked: true, + }, + VirtualReality: { + BlockNewRequests: true, + Locked: true, + }, + Autoplay: { + Default: "block-audio", + Locked: true, + }, + }, + InstallAddonsPermission: { + Default: false, + }, + PopupBlocking: { + Locked: true, + }, + Cookies: { + Locked: true, + }, + }, + }); + + let permissions = [ + "geo", + "autoplay-media", + "install", + "popup", + "desktop-notification", + "cookie", + "camera", + "microphone", + "xr", + ]; + + await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function (browser) { + let pageInfo = BrowserPageInfo(TEST_ORIGIN, "permTab"); + await BrowserTestUtils.waitForEvent(pageInfo, "load"); + + for (let i = 0; i < permissions.length; i++) { + let permission = permissions[i]; + let checkbox = await TestUtils.waitForCondition(() => + pageInfo.document.getElementById(`${permission}Def`) + ); + + ok(checkbox.disabled, `${permission} checkbox should be disabled`); + } + + pageInfo.close(); + }); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_passwordmanager.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_passwordmanager.js new file mode 100644 index 0000000000..f62d6cbf50 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_passwordmanager.js @@ -0,0 +1,25 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_pwmanager_blocked() { + await setupPolicyEngineWithJson({ + policies: { + PasswordManagerEnabled: false, + }, + }); + + await BrowserTestUtils.withNewTab( + "about:preferences#privacy", + async browser => { + is( + browser.contentDocument.getElementById("showPasswords").disabled, + true, + "showPasswords should be disabled." + ); + } + ); + + await testPageBlockedByPolicy("about:logins"); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_search_engine.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_search_engine.js new file mode 100644 index 0000000000..c0b7b20535 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_search_engine.js @@ -0,0 +1,109 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +ChromeUtils.defineESModuleGetters(this, { + CustomizableUITestUtils: + "resource://testing-common/CustomizableUITestUtils.sys.mjs", +}); + +let gCUITestUtils = new CustomizableUITestUtils(window); + +add_task(async function test_setup() { + await gCUITestUtils.addSearchBar(); + registerCleanupFunction(() => { + gCUITestUtils.removeSearchBar(); + }); +}); + +// |shouldWork| should be true if opensearch is expected to work and false if +// it is not. +async function test_opensearch(shouldWork) { + let searchBar = BrowserSearch.searchBar; + + let rootDir = getRootDirectory(gTestPath); + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + rootDir + "opensearch.html" + ); + let searchPopup = document.getElementById("PopupSearchAutoComplete"); + let promiseSearchPopupShown = BrowserTestUtils.waitForEvent( + searchPopup, + "popupshown" + ); + let searchBarButton = searchBar.querySelector(".searchbar-search-button"); + + searchBarButton.click(); + await promiseSearchPopupShown; + let oneOffsContainer = searchPopup.searchOneOffsContainer; + let engineElement = oneOffsContainer.querySelector( + ".searchbar-engine-one-off-add-engine" + ); + if (shouldWork) { + ok(engineElement, "There should be search engines available to add"); + ok( + searchBar.getAttribute("addengines"), + "Search bar should have addengines attribute" + ); + } else { + is( + engineElement, + null, + "There should be no search engines available to add" + ); + ok( + !searchBar.getAttribute("addengines"), + "Search bar should not have addengines attribute" + ); + } + await BrowserTestUtils.removeTab(tab); +} + +add_task(async function test_opensearch_works() { + // Clear out policies so we can test with no policies applied + await setupPolicyEngineWithJson({ + policies: {}, + }); + // Ensure that opensearch works before we make sure that it can be properly + // disabled + await test_opensearch(true); +}); + +add_task(async function setup_prevent_installs() { + await setupPolicyEngineWithJson({ + policies: { + SearchEngines: { + PreventInstalls: true, + }, + }, + }); +}); + +add_task(async function test_prevent_install_ui() { + // Check that about:preferences does not prompt user to install search engines + // if that feature is disabled + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + "about:preferences#search" + ); + await SpecialPowers.spawn(tab.linkedBrowser, [], async function () { + let linkContainer = content.document.getElementById("addEnginesBox"); + if (!linkContainer.hidden) { + await ContentTaskUtils.waitForMutationCondition( + linkContainer, + { attributeFilter: ["hidden"] }, + () => linkContainer.hidden + ); + } + ok( + linkContainer.hidden, + '"Find more search engines" link should be hidden' + ); + }); + await BrowserTestUtils.removeTab(tab); +}); + +add_task(async function test_opensearch_disabled() { + // Check that search engines cannot be added via opensearch + await test_opensearch(false); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_searchbar.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_searchbar.js new file mode 100644 index 0000000000..af892f2813 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_searchbar.js @@ -0,0 +1,36 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_setup(async function () { + await setupPolicyEngineWithJson({ + policies: { + SearchBar: "separate", + }, + }); +}); + +add_task(async function test_menu_shown() { + let newWin = await BrowserTestUtils.openNewBrowserWindow(); + let placement = CustomizableUI.getPlacementOfWidget("search-container"); + isnot(placement, null, "Search bar has a placement"); + is( + placement.area, + CustomizableUI.AREA_NAVBAR, + "Search bar is in the nav bar" + ); + await BrowserTestUtils.closeWindow(newWin); +}); + +add_task(async function test_menu_shown() { + await setupPolicyEngineWithJson({ + policies: { + SearchBar: "unified", + }, + }); + let newWin = await BrowserTestUtils.openNewBrowserWindow(); + let placement = CustomizableUI.getPlacementOfWidget("search-container"); + is(placement, null, "Search bar has no placement"); + await BrowserTestUtils.closeWindow(newWin); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_set_homepage.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_set_homepage.js new file mode 100644 index 0000000000..0c586fc45f --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_set_homepage.js @@ -0,0 +1,115 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +registerCleanupFunction(function restore_pref_values() { + // These two prefs are set as user prefs in case the "Locked" + // option from this policy was not used. In this case, it won't + // be tracked nor restored by the PoliciesPrefTracker. + Services.prefs.clearUserPref("browser.startup.homepage"); +}); + +add_task(async function homepage_test_simple() { + await setupPolicyEngineWithJson({ + policies: { + Homepage: { + URL: "http://example1.com/", + }, + }, + }); + await check_homepage({ expectedURL: "http://example1.com/" }); +}); + +add_task(async function homepage_test_repeat_same_policy_value() { + // Simulate homepage change after policy applied + Services.prefs.setStringPref( + "browser.startup.homepage", + "http://example2.com/" + ); + Services.prefs.setIntPref("browser.startup.page", 3); + + // Policy should have no effect. Homepage has not been locked and policy value + // has not changed. We should be respecting the homepage that the user gave. + await setupPolicyEngineWithJson({ + policies: { + Homepage: { + URL: "http://example1.com/", + }, + }, + }); + await check_homepage({ + expectedURL: "http://example2.com/", + expectedPageVal: 3, + }); + Services.prefs.clearUserPref("browser.startup.page"); + Services.prefs.clearUserPref("browser.startup.homepage"); +}); + +add_task(async function homepage_test_empty_additional() { + await setupPolicyEngineWithJson({ + policies: { + Homepage: { + URL: "http://example1.com/", + Additional: [], + }, + }, + }); + await check_homepage({ expectedURL: "http://example1.com/" }); +}); + +add_task(async function homepage_test_single_additional() { + await setupPolicyEngineWithJson({ + policies: { + Homepage: { + URL: "http://example1.com/", + Additional: ["http://example2.com/"], + }, + }, + }); + await check_homepage({ + expectedURL: "http://example1.com/|http://example2.com/", + }); +}); + +add_task(async function homepage_test_multiple_additional() { + await setupPolicyEngineWithJson({ + policies: { + Homepage: { + URL: "http://example1.com/", + Additional: ["http://example2.com/", "http://example3.com/"], + }, + }, + }); + await check_homepage({ + expectedURL: + "http://example1.com/|http://example2.com/|http://example3.com/", + }); +}); + +add_task(async function homepage_test_locked() { + await setupPolicyEngineWithJson({ + policies: { + Homepage: { + URL: "http://example4.com/", + Additional: ["http://example5.com/", "http://example6.com/"], + Locked: true, + }, + }, + }); + await check_homepage({ + expectedURL: + "http://example4.com/|http://example5.com/|http://example6.com/", + locked: true, + }); +}); + +add_task(async function homepage_test_anchor_link() { + await setupPolicyEngineWithJson({ + policies: { + Homepage: { + URL: "http://example1.com/#test", + }, + }, + }); + await check_homepage({ expectedURL: "http://example1.com/#test" }); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_set_startpage.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_set_startpage.js new file mode 100644 index 0000000000..bc28cdd51a --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_set_startpage.js @@ -0,0 +1,68 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +add_setup(async function () { + // browser.startup.page is set by unittest-required/user.js, + // but we need the default value + await SpecialPowers.pushPrefEnv({ + clear: [["browser.startup.page"]], + }); +}); + +add_task(async function homepage_test_startpage_homepage() { + await setupPolicyEngineWithJson({ + policies: { + Homepage: { + URL: "http://example1.com/#test", + StartPage: "homepage", + }, + }, + }); + await check_homepage({ + expectedURL: "http://example1.com/#test", + expectedPageVal: 1, + }); +}); + +add_task(async function homepage_test_startpage_homepage_locked() { + await setupPolicyEngineWithJson({ + policies: { + Homepage: { + URL: "http://example1.com/#test", + StartPage: "homepage-locked", + Locked: true, + }, + }, + }); + await check_homepage({ + expectedURL: "http://example1.com/#test", + expectedPageVal: 1, + locked: true, + }); +}); + +add_task(async function homepage_test_startpage_none() { + await setupPolicyEngineWithJson({ + policies: { + Homepage: { + StartPage: "none", + }, + }, + }); + await check_homepage({ + expectedURL: "chrome://browser/content/blanktab.html", + expectedPageVal: 1, + }); +}); + +add_task(async function homepage_test_startpage_restore() { + await setupPolicyEngineWithJson({ + policies: { + Homepage: { + StartPage: "previous-session", + }, + }, + }); + await check_homepage({ expectedPageVal: 3 }); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_support_menu.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_support_menu.js new file mode 100644 index 0000000000..d0a833484a --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_support_menu.js @@ -0,0 +1,68 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +add_setup(async function () { + await setupPolicyEngineWithJson({ + policies: { + SupportMenu: { + Title: "Title", + URL: "https://example.com/", + AccessKey: "T", + }, + }, + }); +}); + +add_task(async function test_help_menu() { + is( + Services.policies.getSupportMenu().URL.href, + "https://example.com/", + "The policy should have the correct URL." + ); + buildHelpMenu(); + let supportMenu = document.getElementById("helpPolicySupport"); + is(supportMenu.hidden, false, "The policy menu should be visible."); + is( + supportMenu.getAttribute("label"), + "Title", + "The policy menu should have the correct title." + ); + is( + supportMenu.getAttribute("accesskey"), + "T", + "The policy menu should have the correct access key." + ); +}); + +add_task(async function test_help_menu_app_menu() { + is( + Services.policies.getSupportMenu().URL.href, + "https://example.com/", + "The policy should have the correct URL." + ); + let menuButton = document.getElementById("PanelUI-menu-button"); + menuButton.click(); + await BrowserTestUtils.waitForEvent(window.PanelUI.mainView, "ViewShown"); + + let helpButtonId = "appMenu-help-button2"; + document.getElementById(helpButtonId).click(); + await BrowserTestUtils.waitForEvent( + document.getElementById("PanelUI-helpView"), + "ViewShown" + ); + + let supportMenu = document.getElementById("appMenu_helpPolicySupport"); + is(supportMenu.hidden, false, "The policy menu should be visible."); + is( + supportMenu.getAttribute("label"), + "Title", + "The policy menu should have the correct title." + ); + is( + supportMenu.getAttribute("accesskey"), + "T", + "The policy menu should have the correct access key." + ); + window.PanelUI.hide(); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_usermessaging.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_usermessaging.js new file mode 100644 index 0000000000..d8a3381779 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_usermessaging.js @@ -0,0 +1,21 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_notice_in_aboutprefences() { + await setupPolicyEngineWithJson({ + policies: { + UserMessaging: { + MoreFromMozilla: false, + }, + }, + }); + + await BrowserTestUtils.withNewTab("about:preferences", async browser => { + let moreFromMozillaCategory = browser.contentDocument.getElementById( + "category-more-from-mozilla" + ); + ok(moreFromMozillaCategory.hidden, "The category is hidden"); + }); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_websitefilter.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_websitefilter.js new file mode 100644 index 0000000000..be51e76dce --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_websitefilter.js @@ -0,0 +1,186 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +const SUPPORT_FILES_PATH = + "http://mochi.test:8888/browser/browser/components/enterprisepolicies/tests/browser/"; +const BLOCKED_PAGE = "policy_websitefilter_block.html"; +const EXCEPTION_PAGE = "policy_websitefilter_exception.html"; +const SAVELINKAS_PAGE = "policy_websitefilter_savelink.html"; + +async function clearWebsiteFilter() { + await setupPolicyEngineWithJson({ + policies: { + WebsiteFilter: { + Block: [], + Exceptions: [], + }, + }, + }); +} + +add_task(async function test_http() { + await setupPolicyEngineWithJson({ + policies: { + WebsiteFilter: { + Block: ["*://mochi.test/*policy_websitefilter_*"], + Exceptions: ["*://mochi.test/*_websitefilter_exception*"], + }, + }, + }); + + await checkBlockedPage(SUPPORT_FILES_PATH + BLOCKED_PAGE, true); + await checkBlockedPage( + "view-source:" + SUPPORT_FILES_PATH + BLOCKED_PAGE, + true + ); + await checkBlockedPage( + "about:reader?url=" + SUPPORT_FILES_PATH + BLOCKED_PAGE, + true + ); + await checkBlockedPage( + "about:READER?url=" + SUPPORT_FILES_PATH + BLOCKED_PAGE, + true + ); + await checkBlockedPage(SUPPORT_FILES_PATH + EXCEPTION_PAGE, false); + + await checkBlockedPage(SUPPORT_FILES_PATH + "301.sjs", true); + + await checkBlockedPage(SUPPORT_FILES_PATH + "302.sjs", true); + await clearWebsiteFilter(); +}); + +add_task(async function test_http_mixed_case() { + await setupPolicyEngineWithJson({ + policies: { + WebsiteFilter: { + Block: ["*://mochi.test/*policy_websitefilter_*"], + Exceptions: ["*://mochi.test/*_websitefilter_exception*"], + }, + }, + }); + + await checkBlockedPage(SUPPORT_FILES_PATH + BLOCKED_PAGE.toUpperCase(), true); + await checkBlockedPage( + SUPPORT_FILES_PATH + EXCEPTION_PAGE.toUpperCase(), + false + ); + await clearWebsiteFilter(); +}); + +add_task(async function test_file() { + await setupPolicyEngineWithJson({ + policies: { + WebsiteFilter: { + Block: ["file:///*"], + }, + }, + }); + + await checkBlockedPage("file:///this_should_be_blocked", true); + await clearWebsiteFilter(); +}); + +add_task(async function test_savelink() { + await setupPolicyEngineWithJson({ + policies: { + WebsiteFilter: { + Block: ["*://mochi.test/*policy_websitefilter_block*"], + }, + }, + }); + + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + SUPPORT_FILES_PATH + SAVELINKAS_PAGE + ); + + let contextMenu = document.getElementById("contentAreaContextMenu"); + let promiseContextMenuOpen = BrowserTestUtils.waitForEvent( + contextMenu, + "popupshown" + ); + await BrowserTestUtils.synthesizeMouse( + "#savelink_blocked", + 0, + 0, + { + type: "contextmenu", + button: 2, + centered: true, + }, + gBrowser.selectedBrowser + ); + await promiseContextMenuOpen; + + let saveLink = document.getElementById("context-savelink"); + is(saveLink.disabled, true, "Save Link As should be disabled"); + + let promiseContextMenuHidden = BrowserTestUtils.waitForEvent( + contextMenu, + "popuphidden" + ); + contextMenu.hidePopup(); + await promiseContextMenuHidden; + + promiseContextMenuOpen = BrowserTestUtils.waitForEvent( + contextMenu, + "popupshown" + ); + await BrowserTestUtils.synthesizeMouse( + "#savelink_notblocked", + 0, + 0, + { + type: "contextmenu", + button: 2, + centered: true, + }, + gBrowser.selectedBrowser + ); + await promiseContextMenuOpen; + + saveLink = document.getElementById("context-savelink"); + is(saveLink.disabled, false, "Save Link As should not be disabled"); + + promiseContextMenuHidden = BrowserTestUtils.waitForEvent( + contextMenu, + "popuphidden" + ); + contextMenu.hidePopup(); + await promiseContextMenuHidden; + + BrowserTestUtils.removeTab(tab); + await clearWebsiteFilter(); +}); + +add_task(async function test_http_json_policy() { + await setupPolicyEngineWithJson({ + policies: { + WebsiteFilter: `{ + "Block": ["*://mochi.test/*policy_websitefilter_*"], + "Exceptions": ["*://mochi.test/*_websitefilter_exception*"] + }`, + }, + }); + + await checkBlockedPage(SUPPORT_FILES_PATH + BLOCKED_PAGE, true); + await checkBlockedPage( + "view-source:" + SUPPORT_FILES_PATH + BLOCKED_PAGE, + true + ); + await checkBlockedPage( + "about:reader?url=" + SUPPORT_FILES_PATH + BLOCKED_PAGE, + true + ); + await checkBlockedPage( + "about:READER?url=" + SUPPORT_FILES_PATH + BLOCKED_PAGE, + true + ); + await checkBlockedPage(SUPPORT_FILES_PATH + EXCEPTION_PAGE, false); + + await checkBlockedPage(SUPPORT_FILES_PATH + "301.sjs", true); + + await checkBlockedPage(SUPPORT_FILES_PATH + "302.sjs", true); + await clearWebsiteFilter(); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/disable_app_update/browser.ini b/browser/components/enterprisepolicies/tests/browser/disable_app_update/browser.ini new file mode 100644 index 0000000000..d311bcf910 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/disable_app_update/browser.ini @@ -0,0 +1,9 @@ +[DEFAULT] +prefs = + app.update.disabledForTesting=false + browser.policies.alternatePath='/browser/components/enterprisepolicies/tests/browser/disable_app_update/config_disable_app_update.json' +support-files = + config_disable_app_update.json +skip-if = os == 'win' && msix # Updater is disabled in MSIX builds + +[browser_policy_disable_app_update.js] diff --git a/browser/components/enterprisepolicies/tests/browser/disable_app_update/browser_policy_disable_app_update.js b/browser/components/enterprisepolicies/tests/browser/disable_app_update/browser_policy_disable_app_update.js new file mode 100644 index 0000000000..e6ad7ab3c5 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/disable_app_update/browser_policy_disable_app_update.js @@ -0,0 +1,121 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +ChromeUtils.defineESModuleGetters(this, { + UrlbarTestUtils: "resource://testing-common/UrlbarTestUtils.sys.mjs", +}); + +var updateService = Cc["@mozilla.org/updates/update-service;1"].getService( + Ci.nsIApplicationUpdateService +); + +add_task(async function test_updates_post_policy() { + is( + Services.policies.isAllowed("appUpdate"), + false, + "appUpdate should be disabled by policy." + ); + + is( + updateService.canCheckForUpdates, + false, + "Should not be able to check for updates with DisableAppUpdate enabled." + ); +}); + +add_task(async function test_update_preferences_ui() { + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + "about:preferences" + ); + + await SpecialPowers.spawn(tab.linkedBrowser, [], async function () { + let setting = content.document.getElementById("updateSettingsContainer"); + is( + setting.hidden, + true, + "Update choices should be disabled when app update is locked by policy" + ); + }); + + BrowserTestUtils.removeTab(tab); +}); + +add_task(async function test_update_about_ui() { + let aboutDialog = await waitForAboutDialog(); + let panelId = "policyDisabled"; + + await BrowserTestUtils.waitForCondition( + () => aboutDialog.gAppUpdater?.selectedPanel?.id == panelId, + 'Waiting for expected panel ID - expected "' + panelId + '"' + ); + is( + aboutDialog.gAppUpdater.selectedPanel.id, + panelId, + "The About Dialog panel Id should equal " + panelId + ); + + // Make sure that we still remain on the "disabled by policy" panel after + // `AppUpdater.stop()` is called. + aboutDialog.gAppUpdater._appUpdater.stop(); + is( + aboutDialog.gAppUpdater.selectedPanel.id, + panelId, + "The About Dialog panel Id should still equal " + panelId + ); + + aboutDialog.close(); +}); + +/** + * Waits for the About Dialog to load. + * + * @return A promise that returns the domWindow for the About Dialog and + * resolves when the About Dialog loads. + */ +function waitForAboutDialog() { + return new Promise(resolve => { + var listener = { + onOpenWindow: aXULWindow => { + Services.wm.removeListener(listener); + + async function aboutDialogOnLoad() { + domwindow.removeEventListener("load", aboutDialogOnLoad, true); + let chromeURI = "chrome://browser/content/aboutDialog.xhtml"; + is( + domwindow.document.location.href, + chromeURI, + "About dialog appeared" + ); + resolve(domwindow); + } + + var domwindow = aXULWindow.docShell.domWindow; + domwindow.addEventListener("load", aboutDialogOnLoad, true); + }, + onCloseWindow: aXULWindow => {}, + }; + + Services.wm.addListener(listener); + openAboutDialog(); + }); +} + +add_task(async function test_no_update_intervention() { + await BrowserTestUtils.withNewTab("about:blank", async () => { + let context = await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + value: "update firefox", + waitForFocus, + fireInputEvent: true, + }); + for (let result of context.results) { + Assert.notEqual(result.type, UrlbarUtils.RESULT_TYPE.TIP); + } + await UrlbarTestUtils.promisePopupClose(window, () => + window.gURLBar.blur() + ); + }); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/disable_app_update/config_disable_app_update.json b/browser/components/enterprisepolicies/tests/browser/disable_app_update/config_disable_app_update.json new file mode 100644 index 0000000000..f36622021f --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/disable_app_update/config_disable_app_update.json @@ -0,0 +1,5 @@ +{ + "policies": { + "DisableAppUpdate": true + } +} diff --git a/browser/components/enterprisepolicies/tests/browser/disable_default_bookmarks/bookmarks_policies.json b/browser/components/enterprisepolicies/tests/browser/disable_default_bookmarks/bookmarks_policies.json new file mode 100644 index 0000000000..117768efb3 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/disable_default_bookmarks/bookmarks_policies.json @@ -0,0 +1,5 @@ +{ + "policies": { + "NoDefaultBookmarks": true + } +} diff --git a/browser/components/enterprisepolicies/tests/browser/disable_default_bookmarks/browser.ini b/browser/components/enterprisepolicies/tests/browser/disable_default_bookmarks/browser.ini new file mode 100644 index 0000000000..b7469c550e --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/disable_default_bookmarks/browser.ini @@ -0,0 +1,7 @@ +[DEFAULT] +prefs = + browser.policies.alternatePath='/browser/components/enterprisepolicies/tests/browser/disable_default_bookmarks/bookmarks_policies.json' +support-files = + bookmarks_policies.json + +[browser_policy_no_default_bookmarks.js] diff --git a/browser/components/enterprisepolicies/tests/browser/disable_default_bookmarks/browser_policy_no_default_bookmarks.js b/browser/components/enterprisepolicies/tests/browser/disable_default_bookmarks/browser_policy_no_default_bookmarks.js new file mode 100644 index 0000000000..aecd088ab3 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/disable_default_bookmarks/browser_policy_no_default_bookmarks.js @@ -0,0 +1,24 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// This test must run in a separate folder because the +// No Default Bookmarks policy needs to be present on +// the first run of the profile, and not dinamically loaded +// like most of the policies tested in the main test folder. + +add_task(async function test_no_default_bookmarks() { + let firstBookmarkOnToolbar = await PlacesUtils.bookmarks.fetch({ + parentGuid: PlacesUtils.bookmarks.toolbarGuid, + index: 0, + }); + + let firstBookmarkOnMenu = await PlacesUtils.bookmarks.fetch({ + parentGuid: PlacesUtils.bookmarks.menuGuid, + index: 0, + }); + + is(firstBookmarkOnToolbar, null, "No bookmarks on toolbar"); + is(firstBookmarkOnMenu, null, "No bookmarks on menu"); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/disable_developer_tools/browser.ini b/browser/components/enterprisepolicies/tests/browser/disable_developer_tools/browser.ini new file mode 100644 index 0000000000..3db44612f8 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/disable_developer_tools/browser.ini @@ -0,0 +1,7 @@ +[DEFAULT] +prefs = + browser.policies.alternatePath='/browser/components/enterprisepolicies/tests/browser/disable_developer_tools/config_disable_developer_tools.json' +support-files = + config_disable_developer_tools.json + +[browser_policy_disable_developer_tools.js] diff --git a/browser/components/enterprisepolicies/tests/browser/disable_developer_tools/browser_policy_disable_developer_tools.js b/browser/components/enterprisepolicies/tests/browser/disable_developer_tools/browser_policy_disable_developer_tools.js new file mode 100644 index 0000000000..f0281f6f46 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/disable_developer_tools/browser_policy_disable_developer_tools.js @@ -0,0 +1,87 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { EnterprisePolicyTesting } = ChromeUtils.importESModule( + "resource://testing-common/EnterprisePolicyTesting.sys.mjs" +); +var updateService = Cc["@mozilla.org/updates/update-service;1"].getService( + Ci.nsIApplicationUpdateService +); + +add_task(async function test_updates_post_policy() { + is( + Services.policies.isAllowed("devtools"), + false, + "devtools should be disabled by policy." + ); + + is( + Services.prefs.getBoolPref("devtools.policy.disabled"), + true, + "devtools dedicated disabled pref is set to true" + ); + + Services.prefs.setBoolPref("devtools.policy.disabled", false); + + is( + Services.prefs.getBoolPref("devtools.policy.disabled"), + true, + "devtools dedicated disabled pref can not be updated" + ); + + await testPageBlockedByPolicy("about:devtools-toolbox"); + await testPageBlockedByPolicy("about:debugging"); + await testPageBlockedByPolicy("about:profiling"); + + let testURL = "data:text/html;charset=utf-8,test"; + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + testURL, + false + ); + + let menuButton = document.getElementById("PanelUI-menu-button"); + menuButton.click(); + await BrowserTestUtils.waitForEvent(window.PanelUI.mainView, "ViewShown"); + let moreToolsButtonId = "appMenu-more-button2"; + document.getElementById(moreToolsButtonId).click(); + await BrowserTestUtils.waitForEvent( + document.getElementById("appmenu-moreTools"), + "ViewShown" + ); + is( + document.getElementById("appmenu-developer-tools-view").children.length, + 2, + "The developer tools are properly populated" + ); + window.PanelUI.hide(); + + BrowserTestUtils.removeTab(tab); +}); + +// Copied from ../head.js. head.js was never intended to be used with tests +// that use a JSON file versus calling setupPolicyEngineWithJson so I have +// to copy this function here versus including it. +async function testPageBlockedByPolicy(page, policyJSON) { + if (policyJSON) { + await EnterprisePolicyTesting.setupPolicyEngineWithJson(policyJSON); + } + await BrowserTestUtils.withNewTab( + { gBrowser, url: "about:blank" }, + async browser => { + BrowserTestUtils.loadURIString(browser, page); + await BrowserTestUtils.browserLoaded(browser, false, page, true); + await SpecialPowers.spawn(browser, [page], async function (innerPage) { + ok( + content.document.documentURI.startsWith( + "about:neterror?e=blockedByPolicy" + ), + content.document.documentURI + + " should start with about:neterror?e=blockedByPolicy" + ); + }); + } + ); +} diff --git a/browser/components/enterprisepolicies/tests/browser/disable_developer_tools/config_disable_developer_tools.json b/browser/components/enterprisepolicies/tests/browser/disable_developer_tools/config_disable_developer_tools.json new file mode 100644 index 0000000000..08c393dec6 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/disable_developer_tools/config_disable_developer_tools.json @@ -0,0 +1,5 @@ +{ + "policies": { + "DisableDeveloperTools": true + } +} diff --git a/browser/components/enterprisepolicies/tests/browser/disable_forget_button/browser.ini b/browser/components/enterprisepolicies/tests/browser/disable_forget_button/browser.ini new file mode 100644 index 0000000000..689f54987e --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/disable_forget_button/browser.ini @@ -0,0 +1,7 @@ +[DEFAULT] +prefs = + browser.policies.alternatePath='/browser/components/enterprisepolicies/tests/browser/disable_forget_button/forget_button.json' +support-files = + forget_button.json + +[browser_policy_disable_forgetbutton.js] diff --git a/browser/components/enterprisepolicies/tests/browser/disable_forget_button/browser_policy_disable_forgetbutton.js b/browser/components/enterprisepolicies/tests/browser/disable_forget_button/browser_policy_disable_forgetbutton.js new file mode 100644 index 0000000000..723aad5d75 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/disable_forget_button/browser_policy_disable_forgetbutton.js @@ -0,0 +1,9 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_policy_disable_forget_button() { + let widget = CustomizableUI.getWidget("panic-button"); + isnot(widget.type, "view", "Forget Button was not created"); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/disable_forget_button/forget_button.json b/browser/components/enterprisepolicies/tests/browser/disable_forget_button/forget_button.json new file mode 100644 index 0000000000..30baf64df4 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/disable_forget_button/forget_button.json @@ -0,0 +1,5 @@ +{ + "policies": { + "DisableForgetButton": true + } +} diff --git a/browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/browser.ini b/browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/browser.ini new file mode 100644 index 0000000000..9c828828c0 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/browser.ini @@ -0,0 +1,8 @@ +[DEFAULT] +prefs = + browser.policies.alternatePath='/browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/config_disable_fxscreenshots.json' + extensions.screenshots.disabled=false +support-files = + config_disable_fxscreenshots.json + +[browser_policy_disable_fxscreenshots.js] diff --git a/browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/browser_policy_disable_fxscreenshots.js b/browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/browser_policy_disable_fxscreenshots.js new file mode 100644 index 0000000000..e2b9232aa3 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/browser_policy_disable_fxscreenshots.js @@ -0,0 +1,35 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const PREF_DISABLE_FX_SCREENSHOTS = "extensions.screenshots.disabled"; + +async function checkScreenshots(shouldBeEnabled) { + return BrowserTestUtils.waitForCondition(() => { + return ( + !!PageActions.actionForID("screenshots_mozilla_org") == shouldBeEnabled + ); + }, "Expecting screenshots to be " + shouldBeEnabled); +} + +add_task(async function test_disable_firefox_screenshots() { + // 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 + // testing/profiles/common/user.js). What we do here to test this policy is to enable + // it on this specific test folder (through browser.ini) and then we let the policy + // engine be responsible for disabling Firefox Screenshots in this case. + + is( + Services.prefs.getBoolPref(PREF_DISABLE_FX_SCREENSHOTS), + true, + "Screenshots pref is disabled" + ); + + await BrowserTestUtils.withNewTab("data:text/html,Test", async function () { + await checkScreenshots(false); + }); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/config_disable_fxscreenshots.json b/browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/config_disable_fxscreenshots.json new file mode 100644 index 0000000000..4caf055394 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/disable_fxscreenshots/config_disable_fxscreenshots.json @@ -0,0 +1,5 @@ +{ + "policies": { + "DisableFirefoxScreenshots": true + } +} diff --git a/browser/components/enterprisepolicies/tests/browser/extensionsettings.html b/browser/components/enterprisepolicies/tests/browser/extensionsettings.html new file mode 100644 index 0000000000..da70ebdf59 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/extensionsettings.html @@ -0,0 +1,28 @@ + + + + + + + + +

+policytest@mozilla.com +

+

+policytest@mozilla.com +

+

+policytest@mozilla.com +

+ + diff --git a/browser/components/enterprisepolicies/tests/browser/hardware_acceleration/browser.ini b/browser/components/enterprisepolicies/tests/browser/hardware_acceleration/browser.ini new file mode 100644 index 0000000000..9f7b977e6c --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/hardware_acceleration/browser.ini @@ -0,0 +1,7 @@ +[DEFAULT] +prefs = + browser.policies.alternatePath='/browser/components/enterprisepolicies/tests/browser/hardware_acceleration/disable_hardware_acceleration.json' +support-files = + disable_hardware_acceleration.json + +[browser_policy_hardware_acceleration.js] diff --git a/browser/components/enterprisepolicies/tests/browser/hardware_acceleration/browser_policy_hardware_acceleration.js b/browser/components/enterprisepolicies/tests/browser/hardware_acceleration/browser_policy_hardware_acceleration.js new file mode 100644 index 0000000000..436bd410d1 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/hardware_acceleration/browser_policy_hardware_acceleration.js @@ -0,0 +1,13 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_policy_hardware_acceleration() { + let winUtils = Services.wm.getMostRecentWindow("").windowUtils; + let layerManager = winUtils.layerManagerType; + ok( + layerManager == "Basic" || layerManager == "WebRender (Software)", + "Hardware acceleration disabled" + ); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/hardware_acceleration/disable_hardware_acceleration.json b/browser/components/enterprisepolicies/tests/browser/hardware_acceleration/disable_hardware_acceleration.json new file mode 100644 index 0000000000..acbdc0a3f4 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/hardware_acceleration/disable_hardware_acceleration.json @@ -0,0 +1,5 @@ +{ + "policies": { + "HardwareAcceleration": false + } +} diff --git a/browser/components/enterprisepolicies/tests/browser/head.js b/browser/components/enterprisepolicies/tests/browser/head.js new file mode 100644 index 0000000000..b1b5207f1d --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/head.js @@ -0,0 +1,253 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { EnterprisePolicyTesting, PoliciesPrefTracker } = + ChromeUtils.importESModule( + "resource://testing-common/EnterprisePolicyTesting.sys.mjs" + ); + +ChromeUtils.defineModuleGetter( + this, + "HomePage", + "resource:///modules/HomePage.jsm" +); + +PoliciesPrefTracker.start(); + +async function setupPolicyEngineWithJson(json, customSchema) { + PoliciesPrefTracker.restoreDefaultValues(); + if (typeof json != "object") { + let filePath = getTestFilePath(json ? json : "non-existing-file.json"); + return EnterprisePolicyTesting.setupPolicyEngineWithJson( + filePath, + customSchema + ); + } + return EnterprisePolicyTesting.setupPolicyEngineWithJson(json, customSchema); +} + +function checkLockedPref(prefName, prefValue) { + EnterprisePolicyTesting.checkPolicyPref(prefName, prefValue, true); +} + +function checkUnlockedPref(prefName, prefValue) { + EnterprisePolicyTesting.checkPolicyPref(prefName, prefValue, false); +} + +// Checks that a page was blocked by seeing if it was replaced with about:neterror +async function checkBlockedPage(url, expectedBlocked) { + let newTab = BrowserTestUtils.addTab(gBrowser); + gBrowser.selectedTab = newTab; + + if (expectedBlocked) { + let promise = BrowserTestUtils.waitForErrorPage(gBrowser.selectedBrowser); + BrowserTestUtils.loadURIString(gBrowser, url); + await promise; + is( + newTab.linkedBrowser.documentURI.spec.startsWith( + "about:neterror?e=blockedByPolicy" + ), + true, + "Should be blocked by policy" + ); + } else { + let promise = BrowserTestUtils.browserStopped(gBrowser, url); + BrowserTestUtils.loadURIString(gBrowser, url); + await promise; + + is( + newTab.linkedBrowser.documentURI.spec, + url, + "Should not be blocked by policy" + ); + } + BrowserTestUtils.removeTab(newTab); +} + +async function check_homepage({ + expectedURL, + expectedPageVal = -1, + locked = false, +}) { + if (expectedURL) { + is(HomePage.get(), expectedURL, "Homepage URL should match expected"); + is( + Services.prefs.prefIsLocked("browser.startup.homepage"), + locked, + "Lock status of browser.startup.homepage should match expected" + ); + } + if (expectedPageVal != -1) { + is( + Services.prefs.getIntPref("browser.startup.page", -1), + expectedPageVal, + "Pref page value should match expected" + ); + is( + Services.prefs.prefIsLocked("browser.startup.page"), + locked, + "Lock status of browser.startup.page should match expected" + ); + } + + // Test that UI is disabled when the Locked property is enabled + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + "about:preferences" + ); + await ContentTask.spawn( + tab.linkedBrowser, + { expectedURL, expectedPageVal, locked }, + // eslint-disable-next-line no-shadow + async function ({ expectedURL, expectedPageVal, locked }) { + if (expectedPageVal != -1) { + // Only check restore checkbox for StartPage + let browserRestoreSessionCheckbox = content.document.getElementById( + "browserRestoreSession" + ); + is( + browserRestoreSessionCheckbox.disabled, + locked, + "Disabled status of session restore status should match expected" + ); + let shouldBeChecked = expectedPageVal === 3; + is( + browserRestoreSessionCheckbox.checked, + shouldBeChecked, + "Session restore status checkbox should be: " + + (shouldBeChecked ? "checked" : "unchecked") + ); + } + + if (!expectedURL) { + // If only StartPage was changed, no need to check these + return; + } + await content.gotoPref("paneHome"); + + let homepageTextbox = content.document.getElementById("homePageUrl"); + // Unfortunately this test does not work because the new UI does not fill + // default values into the URL box at the moment. + // is(homepageTextbox.value, expectedURL, + // "Homepage URL should match expected"); + + // Wait for rendering to be finished + await ContentTaskUtils.waitForCondition( + () => + content.document.getElementById("useCurrentBtn").disabled === locked + ); + + is( + homepageTextbox.disabled, + locked, + "Homepage URL text box disabled status should match expected" + ); + is( + content.document.getElementById("homeMode").disabled, + locked, + "Home mode drop down disabled status should match expected" + ); + is( + content.document.getElementById("useCurrentBtn").disabled, + locked, + '"Use current page" button disabled status should match expected' + ); + is( + content.document.getElementById("useBookmarkBtn").disabled, + locked, + '"Use bookmark" button disabled status should match expected' + ); + is( + content.document.getElementById("restoreDefaultHomePageBtn").disabled, + locked, + '"Restore defaults" button disabled status should match expected' + ); + } + ); + await BrowserTestUtils.removeTab(tab); +} + +add_setup(async function policies_headjs_startWithCleanSlate() { + if (Services.policies.status != Ci.nsIEnterprisePolicies.INACTIVE) { + await setupPolicyEngineWithJson(""); + } + is( + Services.policies.status, + Ci.nsIEnterprisePolicies.INACTIVE, + "Engine is inactive at the start of the test" + ); +}); + +registerCleanupFunction(async function policies_headjs_finishWithCleanSlate() { + if (Services.policies.status != Ci.nsIEnterprisePolicies.INACTIVE) { + await setupPolicyEngineWithJson(""); + } + is( + Services.policies.status, + Ci.nsIEnterprisePolicies.INACTIVE, + "Engine is inactive at the end of the test" + ); + + EnterprisePolicyTesting.resetRunOnceState(); + PoliciesPrefTracker.stop(); +}); + +function waitForAddonInstall(addonId) { + return new Promise(resolve => { + let listener = { + onInstallEnded(install, addon) { + if (addon.id == addonId) { + AddonManager.removeInstallListener(listener); + resolve(); + } + }, + onDownloadFailed() { + AddonManager.removeInstallListener(listener); + resolve(); + }, + onInstallFailed() { + AddonManager.removeInstallListener(listener); + resolve(); + }, + }; + AddonManager.addInstallListener(listener); + }); +} + +function waitForAddonUninstall(addonId) { + return new Promise(resolve => { + let listener = {}; + listener.onUninstalled = addon => { + if (addon.id == addonId) { + AddonManager.removeAddonListener(listener); + resolve(); + } + }; + AddonManager.addAddonListener(listener); + }); +} + +async function testPageBlockedByPolicy(page, policyJSON) { + if (policyJSON) { + await EnterprisePolicyTesting.setupPolicyEngineWithJson(policyJSON); + } + await BrowserTestUtils.withNewTab( + { gBrowser, url: "about:blank" }, + async browser => { + BrowserTestUtils.loadURIString(browser, page); + await BrowserTestUtils.browserLoaded(browser, false, page, true); + await SpecialPowers.spawn(browser, [page], async function (innerPage) { + ok( + content.document.documentURI.startsWith( + "about:neterror?e=blockedByPolicy" + ), + content.document.documentURI + + " should start with about:neterror?e=blockedByPolicy" + ); + }); + } + ); +} diff --git a/browser/components/enterprisepolicies/tests/browser/homepage_button/browser.ini b/browser/components/enterprisepolicies/tests/browser/homepage_button/browser.ini new file mode 100644 index 0000000000..d2b15850a3 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/homepage_button/browser.ini @@ -0,0 +1,7 @@ +[DEFAULT] +prefs = + browser.policies.alternatePath='/browser/components/enterprisepolicies/tests/browser/homepage_button/homepage_policies.json' +support-files = + homepage_policies.json + +[browser_show_home_button_with_homepage_policy.js] diff --git a/browser/components/enterprisepolicies/tests/browser/homepage_button/browser_show_home_button_with_homepage_policy.js b/browser/components/enterprisepolicies/tests/browser/homepage_button/browser_show_home_button_with_homepage_policy.js new file mode 100644 index 0000000000..c1eafb0a52 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/homepage_button/browser_show_home_button_with_homepage_policy.js @@ -0,0 +1,9 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_homepage_button_with_homepage() { + let homeButton = window.document.getElementById("home-button"); + isnot(homeButton, null, "The home button should be visible"); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/homepage_button/homepage_policies.json b/browser/components/enterprisepolicies/tests/browser/homepage_button/homepage_policies.json new file mode 100644 index 0000000000..960e68348e --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/homepage_button/homepage_policies.json @@ -0,0 +1,7 @@ +{ + "policies": { + "Homepage": { + "URL": "http://example1.com/" + } + } +} diff --git a/browser/components/enterprisepolicies/tests/browser/managedbookmarks/browser.ini b/browser/components/enterprisepolicies/tests/browser/managedbookmarks/browser.ini new file mode 100644 index 0000000000..7b6dff29ce --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/managedbookmarks/browser.ini @@ -0,0 +1,8 @@ +[DEFAULT] +prefs = + browser.policies.alternatePath='/browser/components/enterprisepolicies/tests/browser/managedbookmarks/managedbookmarks.json' +support-files = + managedbookmarks.json + +skip-if = (os == "linux") # Popup timeout issue - see Bug 1742167 +[browser_policy_managedbookmarks.js] diff --git a/browser/components/enterprisepolicies/tests/browser/managedbookmarks/browser_policy_managedbookmarks.js b/browser/components/enterprisepolicies/tests/browser/managedbookmarks/browser_policy_managedbookmarks.js new file mode 100644 index 0000000000..494f49978c --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/managedbookmarks/browser_policy_managedbookmarks.js @@ -0,0 +1,210 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_policy_managedbookmarks() { + let managedBookmarksMenu = + window.document.getElementById("managed-bookmarks"); + + is( + managedBookmarksMenu.hidden, + false, + "Managed bookmarks button should be visible." + ); + is( + managedBookmarksMenu.label, + "Folder 1", + "Managed bookmarks buttons should have correct label" + ); + + let popupShownPromise = BrowserTestUtils.waitForEvent( + managedBookmarksMenu.menupopup, + "popupshown", + false + ); + let popupHiddenPromise = BrowserTestUtils.waitForEvent( + managedBookmarksMenu.menupopup, + "popuphidden", + false + ); + managedBookmarksMenu.open = true; + await popupShownPromise; + + is( + managedBookmarksMenu.menupopup.children[0].label, + "Bookmark 1", + "Bookmark should have correct label" + ); + is( + managedBookmarksMenu.menupopup.children[0].link, + "https://example.com/", + "Bookmark should have correct link" + ); + is( + managedBookmarksMenu.menupopup.children[1].label, + "Bookmark 2", + "Bookmark should have correct label" + ); + is( + managedBookmarksMenu.menupopup.children[1].link, + "https://bookmark2.example.com/", + "Bookmark should have correct link" + ); + let subFolder = managedBookmarksMenu.menupopup.children[2]; + is(subFolder.label, "Folder 2", "Subfolder should have correct label"); + is( + subFolder.menupopup.children[0].label, + "Bookmark 3", + "Bookmark should have correct label" + ); + is( + subFolder.menupopup.children[0].link, + "https://bookmark3.example.com/", + "Bookmark should have correct link" + ); + is( + subFolder.menupopup.children[1].label, + "Bookmark 4", + "Bookmark should have correct link" + ); + is( + subFolder.menupopup.children[1].link, + "https://bookmark4.example.com/", + "Bookmark should have correct label" + ); + subFolder = managedBookmarksMenu.menupopup.children[3]; + await TestUtils.waitForCondition(() => { + // Need to wait for Fluent to translate + return subFolder.label == "Subfolder"; + }, "Subfolder should have correct label"); + is( + subFolder.menupopup.children[0].label, + "Bookmark 5", + "Bookmark should have correct label" + ); + is( + subFolder.menupopup.children[0].link, + "https://bookmark5.example.com/", + "Bookmark should have correct link" + ); + is( + subFolder.menupopup.children[1].label, + "Bookmark 6", + "Bookmark should have correct link" + ); + is( + subFolder.menupopup.children[1].link, + "https://bookmark6.example.com/", + "Bookmark should have correct label" + ); + + managedBookmarksMenu.open = false; + await popupHiddenPromise; +}); + +add_task(async function test_open_managedbookmark() { + let managedBookmarksMenu = + window.document.getElementById("managed-bookmarks"); + + let promise = BrowserTestUtils.waitForEvent( + managedBookmarksMenu.menupopup, + "popupshown", + false + ); + managedBookmarksMenu.open = true; + await promise; + + let context = document.getElementById("placesContext"); + let openContextMenuPromise = BrowserTestUtils.waitForEvent( + context, + "popupshown" + ); + EventUtils.synthesizeMouseAtCenter( + managedBookmarksMenu.menupopup.children[0], + { + button: 2, + type: "contextmenu", + } + ); + await openContextMenuPromise; + info("Opened context menu"); + + ok( + document.getElementById("placesContext_open:newprivatewindow").hidden, + "Private Browsing menu should be hidden" + ); + ok( + document.getElementById("placesContext_openContainer:tabs").hidden, + "Open in Tabs should be hidden" + ); + ok( + document.getElementById("placesContext_delete").hidden, + "Delete should be hidden" + ); + + let tabCreatedPromise = BrowserTestUtils.waitForNewTab(gBrowser, null, true); + + let openInNewTabOption = document.getElementById("placesContext_open:newtab"); + context.activateItem(openInNewTabOption); + info("Click open in new tab"); + + let lastOpenedTab = await tabCreatedPromise; + Assert.equal( + lastOpenedTab.linkedBrowser.currentURI.spec, + "https://example.com/", + "Should have opened the correct URI" + ); + await BrowserTestUtils.removeTab(lastOpenedTab); +}); + +add_task(async function test_copy_managedbookmark() { + let managedBookmarksMenu = + window.document.getElementById("managed-bookmarks"); + + let promise = BrowserTestUtils.waitForEvent( + managedBookmarksMenu.menupopup, + "popupshown", + false + ); + managedBookmarksMenu.open = true; + await promise; + + let context = document.getElementById("placesContext"); + let openContextMenuPromise = BrowserTestUtils.waitForEvent( + context, + "popupshown" + ); + EventUtils.synthesizeMouseAtCenter( + managedBookmarksMenu.menupopup.children[0], + { + button: 2, + type: "contextmenu", + } + ); + await openContextMenuPromise; + info("Opened context menu"); + + let copyOption = document.getElementById("placesContext_copy"); + + await new Promise((resolve, reject) => { + SimpleTest.waitForClipboard( + "https://example.com/", + () => { + context.activateItem(copyOption); + }, + resolve, + () => { + ok(false, "Clipboard copy failed"); + reject(); + } + ); + }); + + let popupHidden = BrowserTestUtils.waitForEvent( + managedBookmarksMenu.menupopup, + "popuphidden" + ); + managedBookmarksMenu.menupopup.hidePopup(); + await popupHidden; +}); diff --git a/browser/components/enterprisepolicies/tests/browser/managedbookmarks/managedbookmarks.json b/browser/components/enterprisepolicies/tests/browser/managedbookmarks/managedbookmarks.json new file mode 100644 index 0000000000..e93d910d87 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/managedbookmarks/managedbookmarks.json @@ -0,0 +1,44 @@ +{ + "policies": { + "DisablePrivateBrowsing": true, + "DisplayBookmarksToolbar": true, + "ManagedBookmarks": [ + { + "toplevel_name": "Folder 1" + }, + { + "name": "Bookmark 1", + "url": "https://example.com/" + }, + { + "name": "Bookmark 2", + "url": "https://bookmark2.example.com/" + }, + { + "children": [ + { + "name": "Bookmark 3", + "url": "https://bookmark3.example.com/" + }, + { + "name": "Bookmark 4", + "url": "https://bookmark4.example.com/" + } + ], + "name": "Folder 2" + }, + { + "children": [ + { + "name": "Bookmark 5", + "url": "https://bookmark5.example.com/" + }, + { + "name": "Bookmark 6", + "url": "https://bookmark6.example.com/" + } + ] + } + ] + } +} diff --git a/browser/components/enterprisepolicies/tests/browser/opensearch.html b/browser/components/enterprisepolicies/tests/browser/opensearch.html new file mode 100644 index 0000000000..b3f12d6bd4 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/opensearch.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/browser/components/enterprisepolicies/tests/browser/opensearchEngine.xml b/browser/components/enterprisepolicies/tests/browser/opensearchEngine.xml new file mode 100644 index 0000000000..21ddc4b9a9 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/opensearchEngine.xml @@ -0,0 +1,12 @@ + + Foo + Foo Search + utf-8 + data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGklEQVQoz2NgGB6AnZ1dUlJSXl4eSDIyMhLW4Ovr%2B%2Fr168uXL69Zs4YoG%2BLi4i5dusTExMTGxsbNzd3f37937976%2BnpmZmagbHR09J49e5YvX66kpATVEBYW9ubNm2nTphkbG7e2tp44cQLIuHfvXm5urpaWFlDKysqqu7v73LlzECMYIiIiHj58mJCQoKKicvXq1bS0NKBgW1vbjh074uPjgeqAXE1NzSdPnvDz84M0AEUvXLgAsW379u1z5swBen3jxo2zZ892cHB4%2BvQp0KlAfwI1cHJyghQFBwfv2rULokFXV%2FfixYu7d%2B8GGqGgoMDKyrpu3br9%2B%2FcDuXl5eVA%2FAEWBfoWHAdAYoNuAYQ0XAeoUERFhGDYAAPoUaT2dfWJuAAAAAElFTkSuQmCC + + + + http://mochi.test:8888/browser/browser/components/search/test/ + fooalias + diff --git a/browser/components/enterprisepolicies/tests/browser/policy_websitefilter_block.html b/browser/components/enterprisepolicies/tests/browser/policy_websitefilter_block.html new file mode 100644 index 0000000000..dd6596615d --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/policy_websitefilter_block.html @@ -0,0 +1,10 @@ + + + + + This page should be blocked + + + This page should not be seen. + + diff --git a/browser/components/enterprisepolicies/tests/browser/policy_websitefilter_exception.html b/browser/components/enterprisepolicies/tests/browser/policy_websitefilter_exception.html new file mode 100644 index 0000000000..bf389aac31 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/policy_websitefilter_exception.html @@ -0,0 +1,10 @@ + + + + + This page should not be blocked + + + This page should be seen. + + diff --git a/browser/components/enterprisepolicies/tests/browser/policy_websitefilter_savelink.html b/browser/components/enterprisepolicies/tests/browser/policy_websitefilter_savelink.html new file mode 100644 index 0000000000..d2ec93eac5 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/policy_websitefilter_savelink.html @@ -0,0 +1,11 @@ + + + + + Save Link As test + + + Should not be saveable
+ Should be saveable + + diff --git a/browser/components/enterprisepolicies/tests/browser/policytest_v0.1.xpi b/browser/components/enterprisepolicies/tests/browser/policytest_v0.1.xpi new file mode 100644 index 0000000000..ee2a6289ee Binary files /dev/null and b/browser/components/enterprisepolicies/tests/browser/policytest_v0.1.xpi differ diff --git a/browser/components/enterprisepolicies/tests/browser/policytest_v0.2.xpi b/browser/components/enterprisepolicies/tests/browser/policytest_v0.2.xpi new file mode 100644 index 0000000000..59d589eba9 Binary files /dev/null and b/browser/components/enterprisepolicies/tests/browser/policytest_v0.2.xpi differ diff --git a/browser/components/enterprisepolicies/tests/browser/show_home_button/browser.ini b/browser/components/enterprisepolicies/tests/browser/show_home_button/browser.ini new file mode 100644 index 0000000000..3e6114506d --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/show_home_button/browser.ini @@ -0,0 +1,5 @@ +[DEFAULT] +support-files = + ../head.js + +[browser_policy_show_home_button.js] diff --git a/browser/components/enterprisepolicies/tests/browser/show_home_button/browser_policy_show_home_button.js b/browser/components/enterprisepolicies/tests/browser/show_home_button/browser_policy_show_home_button.js new file mode 100644 index 0000000000..c1d7242dc0 --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/show_home_button/browser_policy_show_home_button.js @@ -0,0 +1,38 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +/* import-globals-from ../head.js */ + +"use strict"; + +add_task(async function test_home_button_shown_boolean() { + await setupPolicyEngineWithJson({ + policies: { + ShowHomeButton: true, + }, + }); + + // Since testing will apply the policy after the browser has already started, + // we will need to open a new window to actually see the menu bar + let newWin = await BrowserTestUtils.openNewBrowserWindow(); + let homeButton = newWin.document.getElementById("home-button"); + isnot(homeButton, null, "The home button should be visible"); + + await BrowserTestUtils.closeWindow(newWin); +}); + +add_task(async function test_home_button_hidden_boolean() { + await setupPolicyEngineWithJson({ + policies: { + ShowHomeButton: false, + }, + }); + + // Since testing will apply the policy after the browser has already started, + // we will need to open a new window to actually see the menu bar + let newWin = await BrowserTestUtils.openNewBrowserWindow(); + let homeButton = newWin.document.getElementById("home-button"); + is(homeButton, null, "The home button should be gone"); + + await BrowserTestUtils.closeWindow(newWin); +}); diff --git a/browser/components/enterprisepolicies/tests/browser/show_home_button/show_home_button_policies.json b/browser/components/enterprisepolicies/tests/browser/show_home_button/show_home_button_policies.json new file mode 100644 index 0000000000..960e68348e --- /dev/null +++ b/browser/components/enterprisepolicies/tests/browser/show_home_button/show_home_button_policies.json @@ -0,0 +1,7 @@ +{ + "policies": { + "Homepage": { + "URL": "http://example1.com/" + } + } +} -- cgit v1.2.3