Bug 1336395 - Disallow same alias in search engines r?jaws
MozReview-Commit-ID: 1GidMz0dimv
--- a/browser/components/preferences/in-content-old/search.js
+++ b/browser/components/preferences/in-content-old/search.js
@@ -261,18 +261,20 @@ var gSearchPane = {
let eduplicate = false;
let dupName = "";
// Check for duplicates in Places keywords.
let bduplicate = !!(await PlacesUtils.keywords.fetch(keyword));
// Check for duplicates in changes we haven't committed yet
let engines = gEngineView._engineStore.engines;
+ let lc_keyword = keyword.toLocaleLowerCase();
for (let engine of engines) {
- if (engine.alias == keyword &&
+ if (engine.alias &&
+ engine.alias.toLocaleLowerCase() == lc_keyword &&
engine.name != aEngine.name) {
eduplicate = true;
dupName = engine.name;
break;
}
}
// Notify the user if they have chosen an existing engine/bookmark keyword
--- a/browser/components/preferences/in-content/main.js
+++ b/browser/components/preferences/in-content/main.js
@@ -1040,18 +1040,20 @@ var gMainPane = {
let eduplicate = false;
let dupName = "";
// Check for duplicates in Places keywords.
let bduplicate = !!(await PlacesUtils.keywords.fetch(keyword));
// Check for duplicates in changes we haven't committed yet
let engines = gEngineView._engineStore.engines;
+ let lc_keyword = keyword.toLocaleLowerCase();
for (let engine of engines) {
- if (engine.alias == keyword &&
+ if (engine.alias &&
+ engine.alias.toLocaleLowerCase() == lc_keyword &&
engine.name != aEngine.name) {
eduplicate = true;
dupName = engine.name;
break;
}
}
// Notify the user if they have chosen an existing engine/bookmark keyword
--- a/browser/components/preferences/in-content/tests/browser.ini
+++ b/browser/components/preferences/in-content/tests/browser.ini
@@ -13,16 +13,17 @@ skip-if = !updater
[browser_bug410900.js]
[browser_bug705422.js]
[browser_bug731866.js]
[browser_search_within_preferences.js]
[browser_bug795764_cachedisabled.js]
[browser_bug1018066_resetScrollPosition.js]
[browser_bug1020245_openPreferences_to_paneContent.js]
[browser_bug1184989_prevent_scrolling_when_preferences_flipped.js]
+[browser_engines.js]
support-files =
browser_bug1184989_prevent_scrolling_when_preferences_flipped.xul
[browser_change_app_handler.js]
skip-if = os != "win" # This test tests the windows-specific app selection dialog, so can't run on non-Windows
[browser_checkspelling.js]
[browser_connection.js]
[browser_connection_bug388287.js]
[browser_cookies_exceptions.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_engines.js
@@ -0,0 +1,26 @@
+// Test Engine list
+add_task(async function() {
+ let prefs = await openPreferencesViaOpenPreferencesAPI("general-search", {leaveOpen: true});
+ is(prefs.selectedPane, "paneGeneral", "General pane is selected by default");
+ let doc = gBrowser.contentDocument;
+
+ let tree = doc.querySelector("#engineList");
+ ok(!tree.hidden, "The search engine list should be visible when Search is requested");
+
+ // Check for default search engines to be displayed in the engineList
+ let defaultEngines = Services.search.getDefaultEngines();
+ for (let i = 0; i < defaultEngines.length; i++) {
+ let engine = defaultEngines[i];
+ let cellName = tree.view.getCellText(i, tree.columns.getNamedColumn("engineName"));
+ is(cellName, engine.name, "Default search engine " + engine.name + " displayed correctly");
+ }
+
+ // Avoid duplicated keywords
+ tree.view.setCellText(0, tree.columns.getNamedColumn("engineKeyword"), "keyword");
+ tree.view.setCellText(1, tree.columns.getNamedColumn("engineKeyword"), "keyword");
+ let cellKeyword = tree.view.getCellText(1, tree.columns.getNamedColumn("engineKeyword"));
+ isnot(cellKeyword, "keyword", "Do not allow duplicated keywords");
+
+ await BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});
+