browser_policy_search_engine.js (3282B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 ChromeUtils.defineESModuleGetters(this, { 6 CustomizableUITestUtils: 7 "resource://testing-common/CustomizableUITestUtils.sys.mjs", 8 }); 9 10 let gCUITestUtils = new CustomizableUITestUtils(window); 11 12 add_task(async function test_setup() { 13 SpecialPowers.pushPrefEnv({ 14 set: [["browser.search.widget.new", false]], 15 }); 16 await gCUITestUtils.addSearchBar(); 17 registerCleanupFunction(() => { 18 gCUITestUtils.removeSearchBar(); 19 }); 20 }); 21 22 // |shouldWork| should be true if opensearch is expected to work and false if 23 // it is not. 24 async function test_opensearch(shouldWork) { 25 let searchBar = document.getElementById("searchbar"); 26 27 let rootDir = getRootDirectory(gTestPath); 28 let tab = await BrowserTestUtils.openNewForegroundTab( 29 gBrowser, 30 rootDir + "opensearch.html" 31 ); 32 let searchPopup = document.getElementById("PopupSearchAutoComplete"); 33 let promiseSearchPopupShown = BrowserTestUtils.waitForEvent( 34 searchPopup, 35 "popupshown" 36 ); 37 let searchBarButton = searchBar.querySelector(".searchbar-search-button"); 38 39 searchBarButton.click(); 40 await promiseSearchPopupShown; 41 let oneOffsContainer = searchPopup.searchOneOffsContainer; 42 let engineElement = oneOffsContainer.querySelector( 43 ".searchbar-engine-one-off-add-engine" 44 ); 45 if (shouldWork) { 46 ok(engineElement, "There should be search engines available to add"); 47 ok( 48 searchBar.getAttribute("addengines"), 49 "Search bar should have addengines attribute" 50 ); 51 } else { 52 is( 53 engineElement, 54 null, 55 "There should be no search engines available to add" 56 ); 57 ok( 58 !searchBar.getAttribute("addengines"), 59 "Search bar should not have addengines attribute" 60 ); 61 } 62 await BrowserTestUtils.removeTab(tab); 63 } 64 65 add_task(async function test_opensearch_works() { 66 // Clear out policies so we can test with no policies applied 67 await setupPolicyEngineWithJson({ 68 policies: {}, 69 }); 70 // Ensure that opensearch works before we make sure that it can be properly 71 // disabled 72 await test_opensearch(true); 73 }); 74 75 add_task(async function setup_prevent_installs() { 76 await setupPolicyEngineWithJson({ 77 policies: { 78 SearchEngines: { 79 PreventInstalls: true, 80 }, 81 }, 82 }); 83 }); 84 85 add_task(async function test_prevent_install_ui() { 86 // Check that about:preferences does not prompt user to install search engines 87 // if that feature is disabled 88 let tab = await BrowserTestUtils.openNewForegroundTab( 89 gBrowser, 90 "about:preferences#search" 91 ); 92 await SpecialPowers.spawn(tab.linkedBrowser, [], async function () { 93 let linkContainer = content.document.getElementById("addEnginesBox"); 94 if (!linkContainer.hidden) { 95 await ContentTaskUtils.waitForMutationCondition( 96 linkContainer, 97 { attributeFilter: ["hidden"] }, 98 () => linkContainer.hidden 99 ); 100 } 101 ok( 102 linkContainer.hidden, 103 '"Find more search engines" link should be hidden' 104 ); 105 }); 106 await BrowserTestUtils.removeTab(tab); 107 }); 108 109 add_task(async function test_opensearch_disabled() { 110 // Check that search engines cannot be added via opensearch 111 await test_opensearch(false); 112 });