[tor-commits] [tor-browser] 17/43: Bug 1499095 - Remove engines hidden by policy after restoring defaults. r=Standard8, a=RyanVM

gitolite role git at cupani.torproject.org
Tue May 31 07:07:00 UTC 2022


This is an automated email from the git hooks/post-receive script.

pierov pushed a commit to branch tor-browser-91.10.0esr-11.0-1
in repository tor-browser.

commit 8f84602ca73cda7d71c9d7ae82e04f4f52855b57
Author: Mike Kaply <mozilla at kaply.com>
AuthorDate: Tue Apr 12 14:58:45 2022 +0000

    Bug 1499095 - Remove engines hidden by policy after restoring defaults. r=Standard8, a=RyanVM
    
    Differential Revision: https://phabricator.services.mozilla.com/D142888
---
 .../tests/browser/browser_policy_search_engine.js  | 55 ++++++++++++++++++++++
 browser/components/preferences/search.js           | 16 +++++++
 2 files changed, 71 insertions(+)

diff --git a/browser/components/enterprisepolicies/tests/browser/browser_policy_search_engine.js b/browser/components/enterprisepolicies/tests/browser/browser_policy_search_engine.js
index e99c19afb4c97..3307de85d9309 100644
--- a/browser/components/enterprisepolicies/tests/browser/browser_policy_search_engine.js
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_search_engine.js
@@ -2,6 +2,12 @@
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 "use strict";
 
+const { SearchTestUtils } = ChromeUtils.import(
+  "resource://testing-common/SearchTestUtils.jsm"
+);
+const { SearchUtils } = ChromeUtils.import(
+  "resource://gre/modules/SearchUtils.jsm"
+);
 const { CustomizableUITestUtils } = ChromeUtils.import(
   "resource://testing-common/CustomizableUITestUtils.jsm"
 );
@@ -468,3 +474,52 @@ add_task(async function test_install_with_suggest() {
   await Services.search.removeEngine(engine);
   EnterprisePolicyTesting.resetRunOnceState();
 });
+
+add_task(async function test_reset_default() {
+  await setupPolicyEngineWithJson({
+    policies: {
+      SearchEngines: {
+        Remove: ["DuckDuckGo"],
+      },
+    },
+  });
+  // Get in line, because the Search policy callbacks are async.
+  await TestUtils.waitForTick();
+
+  let engine = Services.search.getEngineByName("DuckDuckGo");
+
+  is(engine.hidden, true, "Application specified engine should be hidden.");
+
+  await BrowserTestUtils.withNewTab(
+    "about:preferences#search",
+    async browser => {
+      let tree = browser.contentDocument.querySelector("#engineList");
+      for (let i = 0; i < tree.view.rowCount; i++) {
+        let cellName = tree.view.getCellText(
+          i,
+          tree.columns.getNamedColumn("engineName")
+        );
+        isnot(cellName, "DuckDuckGo", "DuckDuckGo should be invisible");
+      }
+      let restoreDefaultsButton = browser.contentDocument.getElementById(
+        "restoreDefaultSearchEngines"
+      );
+      let updatedPromise = SearchTestUtils.promiseSearchNotification(
+        SearchUtils.MODIFIED_TYPE.CHANGED,
+        SearchUtils.TOPIC_ENGINE_MODIFIED
+      );
+      restoreDefaultsButton.click();
+      await updatedPromise;
+      for (let i = 0; i < tree.view.rowCount; i++) {
+        let cellName = tree.view.getCellText(
+          i,
+          tree.columns.getNamedColumn("engineName")
+        );
+        isnot(cellName, "DuckDuckGo", "DuckDuckGo should be invisible");
+      }
+    }
+  );
+
+  engine.hidden = false;
+  EnterprisePolicyTesting.resetRunOnceState();
+});
diff --git a/browser/components/preferences/search.js b/browser/components/preferences/search.js
index 0fc1531b3e166..676b6a016abbe 100644
--- a/browser/components/preferences/search.js
+++ b/browser/components/preferences/search.js
@@ -784,6 +784,22 @@ EngineStore.prototype = {
         added++;
       }
     }
+
+    // We can't do this as part of the loop above because the indices are
+    // used for moving engines.
+    let policyRemovedEngineNames =
+      Services.policies.getActivePolicies()?.SearchEngines?.Remove || [];
+    for (let engineName of policyRemovedEngineNames) {
+      let engine = Services.search.getEngineByName(engineName);
+      if (engine) {
+        try {
+          await Services.search.removeEngine(engine);
+        } catch (ex) {
+          // Engine might not exist
+        }
+      }
+    }
+
     Services.search.resetToOriginalDefaultEngine();
     gSearchPane.showRestoreDefaults(false);
     gSearchPane.buildDefaultEngineDropDowns();

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tor-commits mailing list