From 2cdba405f7aa53bcd08e17aa3e5888b8cdba19ec Mon Sep 17 00:00:00 2001 From: Philip Chee Date: Tue, 27 Sep 2016 16:48:14 +0800 Subject: [PATCH] Bug 1281005 - Move the nsPlacesAutocomplete component to Suite (mozilla-central part) r=mak77 --- toolkit/components/places/moz.build | 6 - .../components/places/nsPlacesAutoComplete.js | 1369 ----------------- .../places/nsPlacesAutoComplete.manifest | 3 - .../places/tests/autocomplete/.eslintrc | 5 - .../tests/autocomplete/head_autocomplete.js | 314 ---- .../places/tests/autocomplete/test_416211.js | 30 - .../places/tests/autocomplete/test_416214.js | 38 - .../places/tests/autocomplete/test_417798.js | 36 - .../places/tests/autocomplete/test_418257.js | 43 - .../places/tests/autocomplete/test_422277.js | 25 - ...st_autocomplete_on_value_removed_479089.js | 54 - .../test_download_embed_bookmarks.js | 53 - .../tests/autocomplete/test_empty_search.js | 69 - .../places/tests/autocomplete/test_enabled.js | 69 - .../tests/autocomplete/test_escape_self.js | 30 - .../autocomplete/test_ignore_protocol.js | 27 - .../tests/autocomplete/test_keyword_search.js | 73 - .../autocomplete/test_match_beginning.js | 45 - .../autocomplete/test_multi_word_search.js | 49 - .../tests/autocomplete/test_special_search.js | 183 --- .../tests/autocomplete/test_swap_protocol.js | 63 - .../tests/autocomplete/test_tabmatches.js | 97 -- .../autocomplete/test_word_boundary_search.js | 105 -- .../places/tests/autocomplete/xpcshell.ini | 29 - toolkit/components/places/tests/moz.build | 5 - 25 files changed, 2820 deletions(-) delete mode 100644 toolkit/components/places/nsPlacesAutoComplete.js delete mode 100644 toolkit/components/places/nsPlacesAutoComplete.manifest delete mode 100644 toolkit/components/places/tests/autocomplete/.eslintrc delete mode 100644 toolkit/components/places/tests/autocomplete/head_autocomplete.js delete mode 100644 toolkit/components/places/tests/autocomplete/test_416211.js delete mode 100644 toolkit/components/places/tests/autocomplete/test_416214.js delete mode 100644 toolkit/components/places/tests/autocomplete/test_417798.js delete mode 100644 toolkit/components/places/tests/autocomplete/test_418257.js delete mode 100644 toolkit/components/places/tests/autocomplete/test_422277.js delete mode 100644 toolkit/components/places/tests/autocomplete/test_autocomplete_on_value_removed_479089.js delete mode 100644 toolkit/components/places/tests/autocomplete/test_download_embed_bookmarks.js delete mode 100644 toolkit/components/places/tests/autocomplete/test_empty_search.js delete mode 100644 toolkit/components/places/tests/autocomplete/test_enabled.js delete mode 100644 toolkit/components/places/tests/autocomplete/test_escape_self.js delete mode 100644 toolkit/components/places/tests/autocomplete/test_ignore_protocol.js delete mode 100644 toolkit/components/places/tests/autocomplete/test_keyword_search.js delete mode 100644 toolkit/components/places/tests/autocomplete/test_match_beginning.js delete mode 100644 toolkit/components/places/tests/autocomplete/test_multi_word_search.js delete mode 100644 toolkit/components/places/tests/autocomplete/test_special_search.js delete mode 100644 toolkit/components/places/tests/autocomplete/test_swap_protocol.js delete mode 100644 toolkit/components/places/tests/autocomplete/test_tabmatches.js delete mode 100644 toolkit/components/places/tests/autocomplete/test_word_boundary_search.js delete mode 100644 toolkit/components/places/tests/autocomplete/xpcshell.ini diff --git a/toolkit/components/places/moz.build b/toolkit/components/places/moz.build index a3788dcf63e2..55ab218ef885 100644 --- a/toolkit/components/places/moz.build +++ b/toolkit/components/places/moz.build @@ -85,12 +85,6 @@ if CONFIG['MOZ_PLACES']: 'UnifiedComplete.js', ] - if CONFIG['MOZ_SUITE']: - EXTRA_COMPONENTS += [ - 'nsPlacesAutoComplete.js', - 'nsPlacesAutoComplete.manifest', - ] - FINAL_LIBRARY = 'xul' include('/ipc/chromium/chromium-config.mozbuild') diff --git a/toolkit/components/places/nsPlacesAutoComplete.js b/toolkit/components/places/nsPlacesAutoComplete.js deleted file mode 100644 index 30615fe072cc..000000000000 --- a/toolkit/components/places/nsPlacesAutoComplete.js +++ /dev/null @@ -1,1369 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * vim: sw=2 ts=2 sts=2 expandtab - * 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/. */ - -Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); -Components.utils.import("resource://gre/modules/Services.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", - "resource://gre/modules/PlacesUtils.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "TelemetryStopwatch", - "resource://gre/modules/TelemetryStopwatch.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "NetUtil", - "resource://gre/modules/NetUtil.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "Task", - "resource://gre/modules/Task.jsm"); - -//////////////////////////////////////////////////////////////////////////////// -//// Constants - -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cr = Components.results; - -// This SQL query fragment provides the following: -// - whether the entry is bookmarked (kQueryIndexBookmarked) -// - the bookmark title, if it is a bookmark (kQueryIndexBookmarkTitle) -// - the tags associated with a bookmarked entry (kQueryIndexTags) -const kBookTagSQLFragment = - `EXISTS(SELECT 1 FROM moz_bookmarks WHERE fk = h.id) AS bookmarked, - ( - SELECT title FROM moz_bookmarks WHERE fk = h.id AND title NOTNULL - ORDER BY lastModified DESC LIMIT 1 - ) AS btitle, - ( - SELECT GROUP_CONCAT(t.title, ',') - FROM moz_bookmarks b - JOIN moz_bookmarks t ON t.id = +b.parent AND t.parent = :parent - WHERE b.fk = h.id - ) AS tags`; - -// observer topics -const kTopicShutdown = "places-shutdown"; -const kPrefChanged = "nsPref:changed"; - -// Match type constants. These indicate what type of search function we should -// be using. -const MATCH_ANYWHERE = Ci.mozIPlacesAutoComplete.MATCH_ANYWHERE; -const MATCH_BOUNDARY_ANYWHERE = Ci.mozIPlacesAutoComplete.MATCH_BOUNDARY_ANYWHERE; -const MATCH_BOUNDARY = Ci.mozIPlacesAutoComplete.MATCH_BOUNDARY; -const MATCH_BEGINNING = Ci.mozIPlacesAutoComplete.MATCH_BEGINNING; -const MATCH_BEGINNING_CASE_SENSITIVE = Ci.mozIPlacesAutoComplete.MATCH_BEGINNING_CASE_SENSITIVE; - -// AutoComplete index constants. All AutoComplete queries will provide these -// columns in this order. -const kQueryIndexURL = 0; -const kQueryIndexTitle = 1; -const kQueryIndexFaviconURL = 2; -const kQueryIndexBookmarked = 3; -const kQueryIndexBookmarkTitle = 4; -const kQueryIndexTags = 5; -const kQueryIndexVisitCount = 6; -const kQueryIndexTyped = 7; -const kQueryIndexPlaceId = 8; -const kQueryIndexQueryType = 9; -const kQueryIndexOpenPageCount = 10; - -// AutoComplete query type constants. Describes the various types of queries -// that we can process. -const kQueryTypeKeyword = 0; -const kQueryTypeFiltered = 1; - -// This separator is used as an RTL-friendly way to split the title and tags. -// It can also be used by an nsIAutoCompleteResult consumer to re-split the -// "comment" back into the title and the tag. -const kTitleTagsSeparator = " \u2013 "; - -const kBrowserUrlbarBranch = "browser.urlbar."; -// Toggle autocomplete. -const kBrowserUrlbarAutocompleteEnabledPref = "autocomplete.enabled"; - -//////////////////////////////////////////////////////////////////////////////// -//// Globals - -XPCOMUtils.defineLazyServiceGetter(this, "gTextURIService", - "@mozilla.org/intl/texttosuburi;1", - "nsITextToSubURI"); - -//////////////////////////////////////////////////////////////////////////////// -//// Helpers - -/** - * Initializes our temporary table on a given database. - * - * @param aDatabase - * The mozIStorageConnection to set up the temp table on. - */ -function initTempTable(aDatabase) -{ - // Note: this should be kept up-to-date with the definition in - // nsPlacesTables.h. - let stmt = aDatabase.createAsyncStatement( - `CREATE TEMP TABLE moz_openpages_temp ( - url TEXT PRIMARY KEY - , open_count INTEGER - )` - ); - stmt.executeAsync(); - stmt.finalize(); - - // Note: this should be kept up-to-date with the definition in - // nsPlacesTriggers.h. - stmt = aDatabase.createAsyncStatement( - `CREATE TEMPORARY TRIGGER moz_openpages_temp_afterupdate_trigger - AFTER UPDATE OF open_count ON moz_openpages_temp FOR EACH ROW - WHEN NEW.open_count = 0 - BEGIN - DELETE FROM moz_openpages_temp - WHERE url = NEW.url; - END` - ); - stmt.executeAsync(); - stmt.finalize(); -} - -/** - * Used to unescape encoded URI strings, and drop information that we do not - * care about for searching. - * - * @param aURIString - * The text to unescape and modify. - * @return the modified uri. - */ -function fixupSearchText(aURIString) -{ - let uri = stripPrefix(aURIString); - return gTextURIService.unEscapeURIForUI("UTF-8", uri); -} - -/** - * Strip prefixes from the URI that we don't care about for searching. - * - * @param aURIString - * The text to modify. - * @return the modified uri. - */ -function stripPrefix(aURIString) -{ - let uri = aURIString; - - if (uri.indexOf("http://") == 0) { - uri = uri.slice(7); - } - else if (uri.indexOf("https://") == 0) { - uri = uri.slice(8); - } - else if (uri.indexOf("ftp://") == 0) { - uri = uri.slice(6); - } - - if (uri.indexOf("www.") == 0) { - uri = uri.slice(4); - } - return uri; -} - -/** - * safePrefGetter get the pref with type safety. - * This will return the default value provided if no pref is set. - * - * @param aPrefBranch - * The nsIPrefBranch containing the required preference - * @param aName - * A preference name - * @param aDefault - * The preference's default value - * @return the preference value or provided default - */ - -function safePrefGetter(aPrefBranch, aName, aDefault) { - let types = { - boolean: "Bool", - number: "Int", - string: "Char" - }; - let type = types[typeof(aDefault)]; - if (!type) { - throw "Unknown type!"; - } - - // If the pref isn't set, we want to use the default. - if (aPrefBranch.getPrefType(aName) == Ci.nsIPrefBranch.PREF_INVALID) { - return aDefault; - } - try { - return aPrefBranch["get" + type + "Pref"](aName); - } - catch (e) { - return aDefault; - } -} - -/** - * Whether UnifiedComplete is alive. - */ -function isUnifiedCompleteInstantiated() { - try { - return Components.manager.QueryInterface(Ci.nsIServiceManager) - .isServiceInstantiated(Cc["@mozilla.org/autocomplete/search;1?name=unifiedcomplete"], - Ci.mozIPlacesAutoComplete); - } catch (ex) { - return false; - } -} - -//////////////////////////////////////////////////////////////////////////////// -//// AutoCompleteStatementCallbackWrapper class - -/** - * Wraps a callback and ensures that handleCompletion is not dispatched if the - * query is no longer tracked. - * - * @param aAutocomplete - * A reference to a nsPlacesAutoComplete. - * @param aCallback - * A reference to a mozIStorageStatementCallback - * @param aDBConnection - * The database connection to execute the queries on. - */ -function AutoCompleteStatementCallbackWrapper(aAutocomplete, aCallback, - aDBConnection) -{ - this._autocomplete = aAutocomplete; - this._callback = aCallback; - this._db = aDBConnection; -} - -AutoCompleteStatementCallbackWrapper.prototype = { - ////////////////////////////////////////////////////////////////////////////// - //// mozIStorageStatementCallback - - handleResult: function ACSCW_handleResult(aResultSet) - { - this._callback.handleResult.apply(this._callback, arguments); - }, - - handleError: function ACSCW_handleError(aError) - { - this._callback.handleError.apply(this._callback, arguments); - }, - - handleCompletion: function ACSCW_handleCompletion(aReason) - { - // Only dispatch handleCompletion if we are not done searching and are a - // pending search. - if (!this._autocomplete.isSearchComplete() && - this._autocomplete.isPendingSearch(this._handle)) { - this._callback.handleCompletion.apply(this._callback, arguments); - } - }, - - ////////////////////////////////////////////////////////////////////////////// - //// AutoCompleteStatementCallbackWrapper - - /** - * Executes the specified query asynchronously. This object will notify - * this._callback if we should notify (logic explained in handleCompletion). - * - * @param aQueries - * The queries to execute asynchronously. - * @return a mozIStoragePendingStatement that can be used to cancel the - * queries. - */ - executeAsync: function ACSCW_executeAsync(aQueries) - { - return this._handle = this._db.executeAsync(aQueries, aQueries.length, - this); - }, - - ////////////////////////////////////////////////////////////////////////////// - //// nsISupports - - QueryInterface: XPCOMUtils.generateQI([ - Ci.mozIStorageStatementCallback, - ]) -}; - -//////////////////////////////////////////////////////////////////////////////// -//// nsPlacesAutoComplete class -//// @mozilla.org/autocomplete/search;1?name=history - -function nsPlacesAutoComplete() -{ - ////////////////////////////////////////////////////////////////////////////// - //// Shared Constants for Smart Getters - - // TODO bug 412736 in case of a frecency tie, break it with h.typed and - // h.visit_count which is better than nothing. This is slow, so not doing it - // yet... - function baseQuery(conditions = "") { - let query = `SELECT h.url, h.title, f.url, ${kBookTagSQLFragment}, - h.visit_count, h.typed, h.id, :query_type, - t.open_count - FROM moz_places h - LEFT JOIN moz_favicons f ON f.id = h.favicon_id - LEFT JOIN moz_openpages_temp t ON t.url = h.url - WHERE h.frecency <> 0 - AND AUTOCOMPLETE_MATCH(:searchString, h.url, - IFNULL(btitle, h.title), tags, - h.visit_count, h.typed, - bookmarked, t.open_count, - :matchBehavior, :searchBehavior) - ${conditions} - ORDER BY h.frecency DESC, h.id DESC - LIMIT :maxResults`; - return query; - } - - ////////////////////////////////////////////////////////////////////////////// - //// Smart Getters - - XPCOMUtils.defineLazyGetter(this, "_db", function() { - // Get a cloned, read-only version of the database. We'll only ever write - // to our own in-memory temp table, and having a cloned copy means we do not - // run the risk of our queries taking longer due to the main database - // connection performing a long-running task. - let db = PlacesUtils.history.DBConnection.clone(true); - - // Autocomplete often fallbacks to a table scan due to lack of text indices. - // In such cases a larger cache helps reducing IO. The default Storage - // value is MAX_CACHE_SIZE_BYTES in storage/mozStorageConnection.cpp. - let stmt = db.createAsyncStatement("PRAGMA cache_size = -6144"); // 6MiB - stmt.executeAsync(); - stmt.finalize(); - - // Create our in-memory tables for tab tracking. - initTempTable(db); - - // Populate the table with current open pages cache contents. - if (this._openPagesCache.length > 0) { - // Avoid getter re-entrance from the _registerOpenPageQuery lazy getter. - let stmt = this._registerOpenPageQuery = - db.createAsyncStatement(this._registerOpenPageQuerySQL); - let params = stmt.newBindingParamsArray(); - for (let i = 0; i < this._openPagesCache.length; i++) { - let bp = params.newBindingParams(); - bp.bindByName("page_url", this._openPagesCache[i]); - params.addParams(bp); - } - stmt.bindParameters(params); - stmt.executeAsync(); - stmt.finalize(); - delete this._openPagesCache; - } - - return db; - }); - - this._customQuery = (conditions = "") => { - return this._db.createAsyncStatement(baseQuery(conditions)); - }; - - XPCOMUtils.defineLazyGetter(this, "_defaultQuery", function() { - return this._db.createAsyncStatement(baseQuery()); - }); - - XPCOMUtils.defineLazyGetter(this, "_historyQuery", function() { - // Enforce ignoring the visit_count index, since the frecency one is much - // faster in this case. ANALYZE helps the query planner to figure out the - // faster path, but it may not have run yet. - return this._db.createAsyncStatement(baseQuery("AND +h.visit_count > 0")); - }); - - XPCOMUtils.defineLazyGetter(this, "_bookmarkQuery", function() { - return this._db.createAsyncStatement(baseQuery("AND bookmarked")); - }); - - XPCOMUtils.defineLazyGetter(this, "_tagsQuery", function() { - return this._db.createAsyncStatement(baseQuery("AND tags IS NOT NULL")); - }); - - XPCOMUtils.defineLazyGetter(this, "_openPagesQuery", function() { - return this._db.createAsyncStatement( - `SELECT t.url, t.url, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - :query_type, t.open_count, NULL - FROM moz_openpages_temp t - LEFT JOIN moz_places h ON h.url_hash = hash(t.url) AND h.url = t.url - WHERE h.id IS NULL - AND AUTOCOMPLETE_MATCH(:searchString, t.url, t.url, NULL, - NULL, NULL, NULL, t.open_count, - :matchBehavior, :searchBehavior) - ORDER BY t.ROWID DESC - LIMIT :maxResults` - ); - }); - - XPCOMUtils.defineLazyGetter(this, "_typedQuery", function() { - return this._db.createAsyncStatement(baseQuery("AND h.typed = 1")); - }); - - XPCOMUtils.defineLazyGetter(this, "_adaptiveQuery", function() { - return this._db.createAsyncStatement( - `/* do not warn (bug 487789) */ - SELECT h.url, h.title, f.url, ${kBookTagSQLFragment}, - h.visit_count, h.typed, h.id, :query_type, t.open_count - FROM ( - SELECT ROUND( - MAX(use_count) * (1 + (input = :search_string)), 1 - ) AS rank, place_id - FROM moz_inputhistory - WHERE input BETWEEN :search_string AND :search_string || X'FFFF' - GROUP BY place_id - ) AS i - JOIN moz_places h ON h.id = i.place_id - LEFT JOIN moz_favicons f ON f.id = h.favicon_id - LEFT JOIN moz_openpages_temp t ON t.url = h.url - WHERE AUTOCOMPLETE_MATCH(NULL, h.url, - IFNULL(btitle, h.title), tags, - h.visit_count, h.typed, bookmarked, - t.open_count, - :matchBehavior, :searchBehavior) - ORDER BY rank DESC, h.frecency DESC` - ); - }); - - XPCOMUtils.defineLazyGetter(this, "_keywordQuery", function() { - return this._db.createAsyncStatement( - `/* do not warn (bug 487787) */ - SELECT REPLACE(h.url, '%s', :query_string) AS search_url, h.title, - IFNULL(f.url, (SELECT f.url - FROM moz_places - JOIN moz_favicons f ON f.id = favicon_id - WHERE rev_host = h.rev_host - ORDER BY frecency DESC - LIMIT 1) - ), 1, NULL, NULL, h.visit_count, h.typed, h.id, - :query_type, t.open_count - FROM moz_keywords k - JOIN moz_places h ON k.place_id = h.id - LEFT JOIN moz_favicons f ON f.id = h.favicon_id - LEFT JOIN moz_openpages_temp t ON t.url = search_url - WHERE k.keyword = LOWER(:keyword)` - ); - }); - - this._registerOpenPageQuerySQL = - `INSERT OR REPLACE INTO moz_openpages_temp (url, open_count) - VALUES (:page_url, - IFNULL( - ( - SELECT open_count + 1 - FROM moz_openpages_temp - WHERE url = :page_url - ), - 1 - ) - )`; - XPCOMUtils.defineLazyGetter(this, "_registerOpenPageQuery", function() { - return this._db.createAsyncStatement(this._registerOpenPageQuerySQL); - }); - - XPCOMUtils.defineLazyGetter(this, "_unregisterOpenPageQuery", function() { - return this._db.createAsyncStatement( - `UPDATE moz_openpages_temp - SET open_count = open_count - 1 - WHERE url = :page_url` - ); - }); - - ////////////////////////////////////////////////////////////////////////////// - //// Initialization - - // load preferences - this._prefs = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefService). - getBranch(kBrowserUrlbarBranch); - this._syncEnabledPref(); - this._loadPrefs(true); - - // register observers - this._os = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); - this._os.addObserver(this, kTopicShutdown, false); - -} - -nsPlacesAutoComplete.prototype = { - ////////////////////////////////////////////////////////////////////////////// - //// nsIAutoCompleteSearch - - startSearch: function PAC_startSearch(aSearchString, aSearchParam, - aPreviousResult, aListener) - { - // Stop the search in case the controller has not taken care of it. - this.stopSearch(); - - // Note: We don't use aPreviousResult to make sure ordering of results are - // consistent. See bug 412730 for more details. - - // We want to store the original string with no leading or trailing - // whitespace for case sensitive searches. - this._originalSearchString = aSearchString.trim(); - - this._currentSearchString = - fixupSearchText(this._originalSearchString.toLowerCase()); - - let params = new Set(aSearchParam.split(" ")); - this._enableActions = params.has("enable-actions"); - this._disablePrivateActions = params.has("disable-private-actions"); - - this._listener = aListener; - let result = Cc["@mozilla.org/autocomplete/simple-result;1"]. - createInstance(Ci.nsIAutoCompleteSimpleResult); - result.setSearchString(aSearchString); - result.setListener(this); - this._result = result; - - // If we are not enabled, we need to return now. - if (!this._enabled) { - this._finishSearch(true); - return; - } - - // Reset our search behavior to the default. - if (this._currentSearchString) { - this._behavior = this._defaultBehavior; - } - else { - this._behavior = this._emptySearchDefaultBehavior; - } - // For any given search, we run up to four queries: - // 1) keywords (this._keywordQuery) - // 2) adaptive learning (this._adaptiveQuery) - // 3) open pages not supported by history (this._openPagesQuery) - // 4) query from this._getSearch - // (1) only gets ran if we get any filtered tokens from this._getSearch, - // since if there are no tokens, there is nothing to match, so there is no - // reason to run the query). - let {query, tokens} = - this._getSearch(this._getUnfilteredSearchTokens(this._currentSearchString)); - let queries = tokens.length ? - [this._getBoundKeywordQuery(tokens), this._getBoundAdaptiveQuery()] : - [this._getBoundAdaptiveQuery()]; - - if (this._hasBehavior("openpage")) { - queries.push(this._getBoundOpenPagesQuery(tokens)); - } - queries.push(query); - - // Start executing our queries. - this._telemetryStartTime = Date.now(); - this._executeQueries(queries); - - // Set up our persistent state for the duration of the search. - this._searchTokens = tokens; - this._usedPlaces = {}; - }, - - stopSearch: function PAC_stopSearch() - { - // We need to cancel our searches so we do not get any [more] results. - // However, it's possible we haven't actually started any searches, so this - // method may throw because this._pendingQuery may be undefined. - if (this._pendingQuery) { - this._stopActiveQuery(); - } - - this._finishSearch(false); - }, - - ////////////////////////////////////////////////////////////////////////////// - //// nsIAutoCompleteSimpleResultListener - - onValueRemoved: function PAC_onValueRemoved(aResult, aURISpec, aRemoveFromDB) - { - if (aRemoveFromDB) { - PlacesUtils.history.removePage(NetUtil.newURI(aURISpec)); - } - }, - - ////////////////////////////////////////////////////////////////////////////// - //// mozIPlacesAutoComplete - - // If the connection has not yet been started, use this local cache. This - // prevents autocomplete from initing the database till the first search. - _openPagesCache: [], - registerOpenPage: function PAC_registerOpenPage(aURI) - { - if (!this._databaseInitialized) { - this._openPagesCache.push(aURI.spec); - return; - } - - let stmt = this._registerOpenPageQuery; - stmt.params.page_url = aURI.spec; - stmt.executeAsync(); - }, - - unregisterOpenPage: function PAC_unregisterOpenPage(aURI) - { - if (!this._databaseInitialized) { - let index = this._openPagesCache.indexOf(aURI.spec); - if (index != -1) { - this._openPagesCache.splice(index, 1); - } - return; - } - - let stmt = this._unregisterOpenPageQuery; - stmt.params.page_url = aURI.spec; - stmt.executeAsync(); - }, - - ////////////////////////////////////////////////////////////////////////////// - //// mozIStorageStatementCallback - - handleResult: function PAC_handleResult(aResultSet) - { - let row, haveMatches = false; - while ((row = aResultSet.getNextRow())) { - let match = this._processRow(row); - haveMatches = haveMatches || match; - - if (this._result.matchCount == this._maxRichResults) { - // We have enough results, so stop running our search. - this._stopActiveQuery(); - - // And finish our search. - this._finishSearch(true); - return; - } - - } - - // Notify about results if we've gotten them. - if (haveMatches) { - this._notifyResults(true); - } - }, - - handleError: function PAC_handleError(aError) - { - Components.utils.reportError("Places AutoComplete: An async statement encountered an " + - "error: " + aError.result + ", '" + aError.message + "'"); - }, - - handleCompletion: function PAC_handleCompletion(aReason) - { - // If we have already finished our search, we should bail out early. - if (this.isSearchComplete()) { - return; - } - - // If we do not have enough results, and our match type is - // MATCH_BOUNDARY_ANYWHERE, search again with MATCH_ANYWHERE to get more - // results. - if (this._matchBehavior == MATCH_BOUNDARY_ANYWHERE && - this._result.matchCount < this._maxRichResults && !this._secondPass) { - this._secondPass = true; - let queries = [ - this._getBoundAdaptiveQuery(MATCH_ANYWHERE), - this._getBoundSearchQuery(MATCH_ANYWHERE, this._searchTokens), - ]; - this._executeQueries(queries); - return; - } - - this._finishSearch(true); - }, - - ////////////////////////////////////////////////////////////////////////////// - //// nsIObserver - - observe: function PAC_observe(aSubject, aTopic, aData) - { - if (aTopic == kTopicShutdown) { - this._os.removeObserver(this, kTopicShutdown); - - // Remove our preference observer. - this._prefs.removeObserver("", this); - delete this._prefs; - - // Finalize the statements that we have used. - let stmts = [ - "_defaultQuery", - "_historyQuery", - "_bookmarkQuery", - "_tagsQuery", - "_openPagesQuery", - "_typedQuery", - "_adaptiveQuery", - "_keywordQuery", - "_registerOpenPageQuery", - "_unregisterOpenPageQuery", - ]; - for (let i = 0; i < stmts.length; i++) { - // We do not want to create any query we haven't already created, so - // see if it is a getter first. - if (Object.getOwnPropertyDescriptor(this, stmts[i]).value !== undefined) { - this[stmts[i]].finalize(); - } - } - - if (this._databaseInitialized) { - this._db.asyncClose(); - } - } - else if (aTopic == kPrefChanged) { - // Avoid re-entrancy when flipping linked preferences. - if (this._ignoreNotifications) - return; - this._ignoreNotifications = true; - this._loadPrefs(false, aTopic, aData); - this._ignoreNotifications = false; - } - }, - - ////////////////////////////////////////////////////////////////////////////// - //// nsPlacesAutoComplete - - get _databaseInitialized() { - return Object.getOwnPropertyDescriptor(this, "_db").value !== undefined; - }, - - /** - * Generates the tokens used in searching from a given string. - * - * @param aSearchString - * The string to generate tokens from. - * @return an array of tokens. - */ - _getUnfilteredSearchTokens: function PAC_unfilteredSearchTokens(aSearchString) - { - // Calling split on an empty string will return an array containing one - // empty string. We don't want that, as it'll break our logic, so return an - // empty array then. - return aSearchString.length ? aSearchString.split(" ") : []; - }, - - /** - * Properly cleans up when searching is completed. - * - * @param aNotify - * Indicates if we should notify the AutoComplete listener about our - * results or not. - */ - _finishSearch: function PAC_finishSearch(aNotify) - { - // Notify about results if we are supposed to. - if (aNotify) { - this._notifyResults(false); - } - - // Clear our state - delete this._originalSearchString; - delete this._currentSearchString; - delete this._strippedPrefix; - delete this._searchTokens; - delete this._listener; - delete this._result; - delete this._usedPlaces; - delete this._pendingQuery; - this._secondPass = false; - this._enableActions = false; - }, - - /** - * Executes the given queries asynchronously. - * - * @param aQueries - * The queries to execute. - */ - _executeQueries: function PAC_executeQueries(aQueries) - { - // Because we might get a handleCompletion for canceled queries, we want to - // filter out queries we no longer care about (described in the - // handleCompletion implementation of AutoCompleteStatementCallbackWrapper). - - // Create our wrapper object and execute the queries. - let wrapper = new AutoCompleteStatementCallbackWrapper(this, this, this._db); - this._pendingQuery = wrapper.executeAsync(aQueries); - }, - - /** - * Stops executing our active query. - */ - _stopActiveQuery: function PAC_stopActiveQuery() - { - this._pendingQuery.cancel(); - delete this._pendingQuery; - }, - - /** - * Notifies the listener about results. - * - * @param aSearchOngoing - * Indicates if the search is ongoing or not. - */ - _notifyResults: function PAC_notifyResults(aSearchOngoing) - { - let result = this._result; - let resultCode = result.matchCount ? "RESULT_SUCCESS" : "RESULT_NOMATCH"; - if (aSearchOngoing) { - resultCode += "_ONGOING"; - } - result.setSearchResult(Ci.nsIAutoCompleteResult[resultCode]); - this._listener.onSearchResult(this, result); - if (this._telemetryStartTime) { - let elapsed = Date.now() - this._telemetryStartTime; - if (elapsed > 50) { - try { - Services.telemetry - .getHistogramById("PLACES_AUTOCOMPLETE_1ST_RESULT_TIME_MS") - .add(elapsed); - } catch (ex) { - Components.utils.reportError("Unable to report telemetry."); - } - } - this._telemetryStartTime = null; - } - }, - - /** - * Synchronize suggest.* prefs with autocomplete.enabled. - */ - _syncEnabledPref: function PAC_syncEnabledPref() - { - let suggestPrefs = ["suggest.history", "suggest.bookmark", "suggest.openpage"]; - let types = ["History", "Bookmark", "Openpage"]; - - this._enabled = safePrefGetter(this._prefs, kBrowserUrlbarAutocompleteEnabledPref, - true); - this._suggestHistory = safePrefGetter(this._prefs, "suggest.history", true); - this._suggestBookmark = safePrefGetter(this._prefs, "suggest.bookmark", true); - this._suggestOpenpage = safePrefGetter(this._prefs, "suggest.openpage", true); - - if (this._enabled) { - // If the autocomplete preference is active, activate all suggest - // preferences only if all of them are false. - if (types.every(type => this["_suggest" + type] == false)) { - for (let type of suggestPrefs) { - this._prefs.setBoolPref(type, true); - } - } - } else { - // If the preference was deactivated, deactivate all suggest preferences. - for (let type of suggestPrefs) { - this._prefs.setBoolPref(type, false); - } - } - }, - - /** - * Loads the preferences that we care about. - * - * @param [optional] aRegisterObserver - * Indicates if the preference observer should be added or not. The - * default value is false. - * @param [optional] aTopic - * Observer's topic, if any. - * @param [optional] aSubject - * Observer's subject, if any. - */ - _loadPrefs: function PAC_loadPrefs(aRegisterObserver, aTopic, aData) - { - // Avoid race conditions with UnifiedComplete component. - if (aData && !isUnifiedCompleteInstantiated()) { - // Synchronize suggest.* prefs with autocomplete.enabled. - if (aData == kBrowserUrlbarAutocompleteEnabledPref) { - this._syncEnabledPref(); - } else if (aData.startsWith("suggest.")) { - let suggestPrefs = ["suggest.history", "suggest.bookmark", "suggest.openpage"]; - this._prefs.setBoolPref(kBrowserUrlbarAutocompleteEnabledPref, - suggestPrefs.some(pref => safePrefGetter(this._prefs, pref, true))); - } - } - - this._enabled = safePrefGetter(this._prefs, - kBrowserUrlbarAutocompleteEnabledPref, - true); - this._matchBehavior = safePrefGetter(this._prefs, - "matchBehavior", - MATCH_BOUNDARY_ANYWHERE); - this._filterJavaScript = safePrefGetter(this._prefs, "filter.javascript", true); - this._maxRichResults = safePrefGetter(this._prefs, "maxRichResults", 25); - this._restrictHistoryToken = safePrefGetter(this._prefs, - "restrict.history", "^"); - this._restrictBookmarkToken = safePrefGetter(this._prefs, - "restrict.bookmark", "*"); - this._restrictTypedToken = safePrefGetter(this._prefs, "restrict.typed", "~"); - this._restrictTagToken = safePrefGetter(this._prefs, "restrict.tag", "+"); - this._restrictOpenPageToken = safePrefGetter(this._prefs, - "restrict.openpage", "%"); - this._matchTitleToken = safePrefGetter(this._prefs, "match.title", "#"); - this._matchURLToken = safePrefGetter(this._prefs, "match.url", "@"); - - this._suggestHistory = safePrefGetter(this._prefs, "suggest.history", true); - this._suggestBookmark = safePrefGetter(this._prefs, "suggest.bookmark", true); - this._suggestOpenpage = safePrefGetter(this._prefs, "suggest.openpage", true); - this._suggestTyped = safePrefGetter(this._prefs, "suggest.history.onlyTyped", false); - - // If history is not set, onlyTyped value should be ignored. - if (!this._suggestHistory) { - this._suggestTyped = false; - } - let types = ["History", "Bookmark", "Openpage", "Typed"]; - this._defaultBehavior = types.reduce((memo, type) => { - let prefValue = this["_suggest" + type]; - return memo | (prefValue && - Ci.mozIPlacesAutoComplete["BEHAVIOR_" + type.toUpperCase()]); - }, 0); - - // Further restrictions to apply for "empty searches" (i.e. searches for ""). - // The empty behavior is typed history, if history is enabled. Otherwise, - // it is bookmarks, if they are enabled. If both history and bookmarks are disabled, - // it defaults to open pages. - this._emptySearchDefaultBehavior = Ci.mozIPlacesAutoComplete.BEHAVIOR_RESTRICT; - if (this._suggestHistory) { - this._emptySearchDefaultBehavior |= Ci.mozIPlacesAutoComplete.BEHAVIOR_HISTORY | - Ci.mozIPlacesAutoComplete.BEHAVIOR_TYPED; - } else if (this._suggestBookmark) { - this._emptySearchDefaultBehavior |= Ci.mozIPlacesAutoComplete.BEHAVIOR_BOOKMARK; - } else { - this._emptySearchDefaultBehavior |= Ci.mozIPlacesAutoComplete.BEHAVIOR_OPENPAGE; - } - - // Validate matchBehavior; default to MATCH_BOUNDARY_ANYWHERE. - if (this._matchBehavior != MATCH_ANYWHERE && - this._matchBehavior != MATCH_BOUNDARY && - this._matchBehavior != MATCH_BEGINNING) { - this._matchBehavior = MATCH_BOUNDARY_ANYWHERE; - } - // register observer - if (aRegisterObserver) { - this._prefs.addObserver("", this, false); - } - }, - - /** - * Given an array of tokens, this function determines which query should be - * ran. It also removes any special search tokens. - * - * @param aTokens - * An array of search tokens. - * @return an object with two properties: - * query: the correctly optimized, bound query to search the database - * with. - * tokens: the filtered list of tokens to search with. - */ - _getSearch: function PAC_getSearch(aTokens) - { - let foundToken = false; - let restrict = (behavior) => { - if (!foundToken) { - this._behavior = 0; - this._setBehavior("restrict"); - foundToken = true; - } - this._setBehavior(behavior); - }; - - // Set the proper behavior so our call to _getBoundSearchQuery gives us the - // correct query. - for (let i = aTokens.length - 1; i >= 0; i--) { - switch (aTokens[i]) { - case this._restrictHistoryToken: - restrict("history"); - break; - case this._restrictBookmarkToken: - restrict("bookmark"); - break; - case this._restrictTagToken: - restrict("tag"); - break; - case this._restrictOpenPageToken: - if (!this._enableActions) { - continue; - } - restrict("openpage"); - break; - case this._matchTitleToken: - restrict("title"); - break; - case this._matchURLToken: - restrict("url"); - break; - case this._restrictTypedToken: - restrict("typed"); - break; - default: - // We do not want to remove the token if we did not match. - continue; - } - - aTokens.splice(i, 1); - } - - // Set the right JavaScript behavior based on our preference. Note that the - // preference is whether or not we should filter JavaScript, and the - // behavior is if we should search it or not. - if (!this._filterJavaScript) { - this._setBehavior("javascript"); - } - - return { - query: this._getBoundSearchQuery(this._matchBehavior, aTokens), - tokens: aTokens - }; - }, - - /** - * @return a string consisting of the search query to be used based on the - * previously set urlbar suggestion preferences. - */ - _getSuggestionPrefQuery: function PAC_getSuggestionPrefQuery() - { - if (!this._hasBehavior("restrict") && this._hasBehavior("history") && - this._hasBehavior("bookmark")) { - return this._hasBehavior("typed") ? this._customQuery("AND h.typed = 1") - : this._defaultQuery; - } - let conditions = []; - if (this._hasBehavior("history")) { - // Enforce ignoring the visit_count index, since the frecency one is much - // faster in this case. ANALYZE helps the query planner to figure out the - // faster path, but it may not have up-to-date information yet. - conditions.push("+h.visit_count > 0"); - } - if (this._hasBehavior("typed")) { - conditions.push("h.typed = 1"); - } - if (this._hasBehavior("bookmark")) { - conditions.push("bookmarked"); - } - if (this._hasBehavior("tag")) { - conditions.push("tags NOTNULL"); - } - - return conditions.length ? this._customQuery("AND " + conditions.join(" AND ")) - : this._defaultQuery; - }, - - /** - * Obtains the search query to be used based on the previously set search - * behaviors (accessed by this._hasBehavior). The query is bound and ready to - * execute. - * - * @param aMatchBehavior - * How this query should match its tokens to the search string. - * @param aTokens - * An array of search tokens. - * @return the correctly optimized query to search the database with and the - * new list of tokens to search with. The query has all the needed - * parameters bound, so consumers can execute it without doing any - * additional work. - */ - _getBoundSearchQuery: function PAC_getBoundSearchQuery(aMatchBehavior, - aTokens) - { - let query = this._getSuggestionPrefQuery(); - - // Bind the needed parameters to the query so consumers can use it. - let params = query.params; - params.parent = PlacesUtils.tagsFolderId; - params.query_type = kQueryTypeFiltered; - params.matchBehavior = aMatchBehavior; - params.searchBehavior = this._behavior; - - // We only want to search the tokens that we are left with - not the - // original search string. - params.searchString = aTokens.join(" "); - - // Limit the query to the the maximum number of desired results. - // This way we can avoid doing more work than needed. - params.maxResults = this._maxRichResults; - - return query; - }, - - _getBoundOpenPagesQuery: function PAC_getBoundOpenPagesQuery(aTokens) - { - let query = this._openPagesQuery; - - // Bind the needed parameters to the query so consumers can use it. - let params = query.params; - params.query_type = kQueryTypeFiltered; - params.matchBehavior = this._matchBehavior; - params.searchBehavior = this._behavior; - - // We only want to search the tokens that we are left with - not the - // original search string. - params.searchString = aTokens.join(" "); - params.maxResults = this._maxRichResults; - - return query; - }, - - /** - * Obtains the keyword query with the properly bound parameters. - * - * @param aTokens - * The array of search tokens to check against. - * @return the bound keyword query. - */ - _getBoundKeywordQuery: function PAC_getBoundKeywordQuery(aTokens) - { - // The keyword is the first word in the search string, with the parameters - // following it. - let searchString = this._originalSearchString; - let queryString = ""; - let queryIndex = searchString.indexOf(" "); - if (queryIndex != -1) { - queryString = searchString.substring(queryIndex + 1); - } - // We need to escape the parameters as if they were the query in a URL - queryString = encodeURIComponent(queryString).replace(/%20/g, "+"); - - // The first word could be a keyword, so that's what we'll search. - let keyword = aTokens[0]; - - let query = this._keywordQuery; - let params = query.params; - params.keyword = keyword; - params.query_string = queryString; - params.query_type = kQueryTypeKeyword; - - return query; - }, - - /** - * Obtains the adaptive query with the properly bound parameters. - * - * @return the bound adaptive query. - */ - _getBoundAdaptiveQuery: function PAC_getBoundAdaptiveQuery(aMatchBehavior) - { - // If we were not given a match behavior, use the stored match behavior. - if (arguments.length == 0) { - aMatchBehavior = this._matchBehavior; - } - - let query = this._adaptiveQuery; - let params = query.params; - params.parent = PlacesUtils.tagsFolderId; - params.search_string = this._currentSearchString; - params.query_type = kQueryTypeFiltered; - params.matchBehavior = aMatchBehavior; - params.searchBehavior = this._behavior; - - return query; - }, - - /** - * Processes a mozIStorageRow to generate the proper data for the AutoComplete - * result. This will add an entry to the current result if it matches the - * criteria. - * - * @param aRow - * The row to process. - * @return true if the row is accepted, and false if not. - */ - _processRow: function PAC_processRow(aRow) - { - // Before we do any work, make sure this entry isn't already in our results. - let entryId = aRow.getResultByIndex(kQueryIndexPlaceId); - let escapedEntryURL = aRow.getResultByIndex(kQueryIndexURL); - let openPageCount = aRow.getResultByIndex(kQueryIndexOpenPageCount) || 0; - - // If actions are enabled and the page is open, add only the switch-to-tab - // result. Otherwise, add the normal result. - let [url, action] = this._enableActions && openPageCount > 0 && this._hasBehavior("openpage") ? - ["moz-action:switchtab," + escapedEntryURL, "action "] : - [escapedEntryURL, ""]; - - if (this._inResults(entryId, url)) { - return false; - } - - let entryTitle = aRow.getResultByIndex(kQueryIndexTitle) || ""; - let entryFavicon = aRow.getResultByIndex(kQueryIndexFaviconURL) || ""; - let entryBookmarked = aRow.getResultByIndex(kQueryIndexBookmarked); - let entryBookmarkTitle = entryBookmarked ? - aRow.getResultByIndex(kQueryIndexBookmarkTitle) : null; - let entryTags = aRow.getResultByIndex(kQueryIndexTags) || ""; - - // Always prefer the bookmark title unless it is empty - let title = entryBookmarkTitle || entryTitle; - - let style; - if (aRow.getResultByIndex(kQueryIndexQueryType) == kQueryTypeKeyword) { - style = "keyword"; - title = NetUtil.newURI(escapedEntryURL).host; - } - - // We will always prefer to show tags if we have them. - let showTags = !!entryTags; - - // However, we'll act as if a page is not bookmarked if the user wants - // only history and not bookmarks and there are no tags. - if (this._hasBehavior("history") && !this._hasBehavior("bookmark") && - !showTags) { - showTags = false; - style = "favicon"; - } - - // If we have tags and should show them, we need to add them to the title. - if (showTags) { - title += kTitleTagsSeparator + entryTags; - } - // We have to determine the right style to display. Tags show the tag icon, - // bookmarks get the bookmark icon, and keywords get the keyword icon. If - // the result does not fall into any of those, it just gets the favicon. - if (!style) { - // It is possible that we already have a style set (from a keyword - // search or because of the user's preferences), so only set it if we - // haven't already done so. - if (showTags) { - style = "tag"; - } - else if (entryBookmarked) { - style = "bookmark"; - } - else { - style = "favicon"; - } - } - - this._addToResults(entryId, url, title, entryFavicon, action + style); - return true; - }, - - /** - * Checks to see if the given place has already been added to the results. - * - * @param aPlaceId - * The place id to check for, may be null. - * @param aUrl - * The url to check for. - * @return true if the place has been added, false otherwise. - * - * @note Must check both the id and the url for a negative match, since - * autocomplete may run in the middle of a new page addition. In such - * a case the switch-to-tab query would hash the page by url, then a - * next query, running after the page addition, would hash it by id. - * It's not possible to just rely on url though, since keywords - * dynamically modify the url to include their search string. - */ - _inResults: function PAC_inResults(aPlaceId, aUrl) - { - if (aPlaceId && aPlaceId in this._usedPlaces) { - return true; - } - return aUrl in this._usedPlaces; - }, - - /** - * Adds a result to the AutoComplete results. Also tracks that we've added - * this place_id into the result set. - * - * @param aPlaceId - * The place_id of the item to be added to the result set. This is - * used by _inResults. - * @param aURISpec - * The URI spec for the entry. - * @param aTitle - * The title to give the entry. - * @param aFaviconSpec - * The favicon to give to the entry. - * @param aStyle - * Indicates how the entry should be styled when displayed. - */ - _addToResults: function PAC_addToResults(aPlaceId, aURISpec, aTitle, - aFaviconSpec, aStyle) - { - // Add this to our internal tracker to ensure duplicates do not end up in - // the result. _usedPlaces is an Object that is being used as a set. - // Not all entries have a place id, thus we fallback to the url for them. - // We cannot use only the url since keywords entries are modified to - // include the search string, and would be returned multiple times. Ids - // are faster too. - this._usedPlaces[aPlaceId || aURISpec] = true; - - // Obtain the favicon for this URI. - let favicon; - if (aFaviconSpec) { - let uri = NetUtil.newURI(aFaviconSpec); - favicon = PlacesUtils.favicons.getFaviconLinkForIcon(uri).spec; - } - favicon = favicon || PlacesUtils.favicons.defaultFavicon.spec; - - this._result.appendMatch(aURISpec, aTitle, favicon, aStyle); - }, - - /** - * Determines if the specified AutoComplete behavior is set. - * - * @param aType - * The behavior type to test for. - * @return true if the behavior is set, false otherwise. - */ - _hasBehavior: function PAC_hasBehavior(aType) - { - let behavior = Ci.mozIPlacesAutoComplete["BEHAVIOR_" + aType.toUpperCase()]; - - if (this._disablePrivateActions && - behavior == Ci.mozIPlacesAutoComplete.BEHAVIOR_OPENPAGE) { - return false; - } - - return this._behavior & behavior; - }, - - /** - * Enables the desired AutoComplete behavior. - * - * @param aType - * The behavior type to set. - */ - _setBehavior: function PAC_setBehavior(aType) - { - this._behavior |= - Ci.mozIPlacesAutoComplete["BEHAVIOR_" + aType.toUpperCase()]; - }, - - /** - * Determines if we are done searching or not. - * - * @return true if we have completed searching, false otherwise. - */ - isSearchComplete: function PAC_isSearchComplete() - { - // If _pendingQuery is null, we should no longer do any work since we have - // already called _finishSearch. This means we completed our search. - return this._pendingQuery == null; - }, - - /** - * Determines if the given handle of a pending statement is a pending search - * or not. - * - * @param aHandle - * A mozIStoragePendingStatement to check and see if we are waiting for - * results from it still. - * @return true if it is a pending query, false otherwise. - */ - isPendingSearch: function PAC_isPendingSearch(aHandle) - { - return this._pendingQuery == aHandle; - }, - - ////////////////////////////////////////////////////////////////////////////// - //// nsISupports - - classID: Components.ID("d0272978-beab-4adc-a3d4-04b76acfa4e7"), - - _xpcom_factory: XPCOMUtils.generateSingletonFactory(nsPlacesAutoComplete), - - QueryInterface: XPCOMUtils.generateQI([ - Ci.nsIAutoCompleteSearch, - Ci.nsIAutoCompleteSimpleResultListener, - Ci.mozIPlacesAutoComplete, - Ci.mozIStorageStatementCallback, - Ci.nsIObserver, - Ci.nsISupportsWeakReference, - ]) -}; - -var components = [nsPlacesAutoComplete]; -this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components); diff --git a/toolkit/components/places/nsPlacesAutoComplete.manifest b/toolkit/components/places/nsPlacesAutoComplete.manifest deleted file mode 100644 index 77dc732af23d..000000000000 --- a/toolkit/components/places/nsPlacesAutoComplete.manifest +++ /dev/null @@ -1,3 +0,0 @@ -component {d0272978-beab-4adc-a3d4-04b76acfa4e7} nsPlacesAutoComplete.js -contract @mozilla.org/autocomplete/search;1?name=history {d0272978-beab-4adc-a3d4-04b76acfa4e7} - diff --git a/toolkit/components/places/tests/autocomplete/.eslintrc b/toolkit/components/places/tests/autocomplete/.eslintrc deleted file mode 100644 index 8a895f93bd06..000000000000 --- a/toolkit/components/places/tests/autocomplete/.eslintrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": [ - "../../../../../testing/xpcshell/xpcshell.eslintrc" - ] -} diff --git a/toolkit/components/places/tests/autocomplete/head_autocomplete.js b/toolkit/components/places/tests/autocomplete/head_autocomplete.js deleted file mode 100644 index ef6864ed1d10..000000000000 --- a/toolkit/components/places/tests/autocomplete/head_autocomplete.js +++ /dev/null @@ -1,314 +0,0 @@ -/* 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/. */ - -var Ci = Components.interfaces; -var Cc = Components.classes; -var Cr = Components.results; -var Cu = Components.utils; - -Cu.import("resource://gre/modules/Services.jsm"); - -// Import common head. -{ - let commonFile = do_get_file("../head_common.js", false); - let uri = Services.io.newFileURI(commonFile); - Services.scriptloader.loadSubScript(uri.spec, this); -} - -// Put any other stuff relative to this test folder below. - - -/** - * Header file for autocomplete testcases that create a set of pages with uris, - * titles, tags and tests that a given search term matches certain pages. - */ - -var current_test = 0; - -function AutoCompleteInput(aSearches) { - this.searches = aSearches; -} -AutoCompleteInput.prototype = { - timeout: 10, - textValue: "", - searches: null, - searchParam: "", - popupOpen: false, - minResultsForPopup: 0, - invalidate: function() {}, - disableAutoComplete: false, - completeDefaultIndex: false, - get popup() { return this; }, - onSearchBegin: function() {}, - onSearchComplete: function() {}, - setSelectedIndex: function() {}, - get searchCount() { return this.searches.length; }, - getSearchAt: function(aIndex) { return this.searches[aIndex]; }, - QueryInterface: XPCOMUtils.generateQI([ - Ci.nsIAutoCompleteInput, - Ci.nsIAutoCompletePopup, - ]) -}; - -function toURI(aSpec) { - return uri(aSpec); -} - -var appendTags = true; -// Helper to turn off tag matching in results -function ignoreTags() -{ - print("Ignoring tags from results"); - appendTags = false; -} - -function ensure_results(aSearch, aExpected) -{ - let controller = Cc["@mozilla.org/autocomplete/controller;1"]. - getService(Ci.nsIAutoCompleteController); - - // Make an AutoCompleteInput that uses our searches - // and confirms results on search complete - let input = new AutoCompleteInput(["history"]); - - controller.input = input; - - if (typeof kSearchParam == "string") - input.searchParam = kSearchParam; - - let numSearchesStarted = 0; - input.onSearchBegin = function() { - numSearchesStarted++; - do_check_eq(numSearchesStarted, 1); - }; - - input.onSearchComplete = function() { - do_check_eq(numSearchesStarted, 1); - aExpected = aExpected.slice(); - - // Check to see the expected uris and titles match up (in any order) - for (let i = 0; i < controller.matchCount; i++) { - let value = controller.getValueAt(i); - let comment = controller.getCommentAt(i); - - print("Looking for '" + value + "', '" + comment + "' in expected results..."); - let j; - for (j = 0; j < aExpected.length; j++) { - // Skip processed expected results - if (aExpected[j] == undefined) - continue; - - let [uri, title, tags] = gPages[aExpected[j]]; - - // Load the real uri and titles and tags if necessary - uri = toURI(kURIs[uri]).spec; - title = kTitles[title]; - if (tags && appendTags) - title += " \u2013 " + tags.map(aTag => kTitles[aTag]); - print("Checking against expected '" + uri + "', '" + title + "'..."); - - // Got a match on both uri and title? - if (uri == value && title == comment) { - print("Got it at index " + j + "!!"); - // Make it undefined so we don't process it again - aExpected[j] = undefined; - break; - } - } - - // We didn't hit the break, so we must have not found it - if (j == aExpected.length) - do_throw("Didn't find the current result ('" + value + "', '" + comment + "') in expected: " + aExpected); - } - - // Make sure we have the right number of results - print("Expecting " + aExpected.length + " results; got " + - controller.matchCount + " results"); - do_check_eq(controller.matchCount, aExpected.length); - - // If we expect results, make sure we got matches - do_check_eq(controller.searchStatus, aExpected.length ? - Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH : - Ci.nsIAutoCompleteController.STATUS_COMPLETE_NO_MATCH); - - // Fetch the next test if we have more - if (++current_test < gTests.length) - run_test(); - - do_test_finished(); - }; - - print("Searching for.. '" + aSearch + "'"); - controller.startSearch(aSearch); -} - -// Get history services -var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); -var bhist = histsvc.QueryInterface(Ci.nsIBrowserHistory); -var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); -var tagsvc = Cc["@mozilla.org/browser/tagging-service;1"]. - getService(Ci.nsITaggingService); -var iosvc = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); -var prefs = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefBranch); - -// Some date not too long ago -var gDate = new Date(Date.now() - 1000 * 60 * 60) * 1000; -// Store the page info for each uri -var gPages = []; - -// Initialization tasks to be run before the next test -var gNextTestSetupTasks = []; - -/** - * Adds a page, and creates various properties for it depending on the - * parameters passed in. This function will also add one visit, unless - * aNoVisit is true. - * - * @param aURI - * An index into kURIs that holds the string for the URI we are to add a - * page for. - * @param aTitle - * An index into kTitles that holds the string for the title we are to - * associate with the specified URI. - * @param aBook [optional] - * An index into kTitles that holds the string for the title we are to - * associate with the bookmark. If this is undefined, no bookmark is - * created. - * @param aTags [optional] - * An array of indexes into kTitles that hold the strings for the tags we - * are to associate with the URI. If this is undefined (or aBook is), no - * tags are added. - * @param aKey [optional] - * A string to associate as the keyword for this bookmark. aBook must be - * a valid index into kTitles for this to be checked and used. - * @param aTransitionType [optional] - * The transition type to use when adding the visit. The default is - * nsINavHistoryService::TRANSITION_LINK. - * @param aNoVisit [optional] - * If true, no visit is added for the URI. If false or undefined, a - * visit is added. - */ -function addPageBook(aURI, aTitle, aBook, aTags, aKey, aTransitionType, aNoVisit) -{ - gNextTestSetupTasks.push([task_addPageBook, arguments]); -} - -function* task_addPageBook(aURI, aTitle, aBook, aTags, aKey, aTransitionType, aNoVisit) -{ - // Add a page entry for the current uri - gPages[aURI] = [aURI, aBook != undefined ? aBook : aTitle, aTags]; - - let uri = toURI(kURIs[aURI]); - let title = kTitles[aTitle]; - - let out = [aURI, aTitle, aBook, aTags, aKey]; - out.push("\nuri=" + kURIs[aURI]); - out.push("\ntitle=" + title); - - // Add the page and a visit if we need to - if (!aNoVisit) { - yield PlacesTestUtils.addVisits({ - uri: uri, - transition: aTransitionType || TRANSITION_LINK, - visitDate: gDate, - title: title - }); - out.push("\nwith visit"); - } - - // Add a bookmark if we need to - if (aBook != undefined) { - let book = kTitles[aBook]; - let bmid = bmsvc.insertBookmark(bmsvc.unfiledBookmarksFolder, uri, - bmsvc.DEFAULT_INDEX, book); - out.push("\nbook=" + book); - - // Add a keyword to the bookmark if we need to - if (aKey != undefined) - yield PlacesUtils.keywords.insert({url: uri.spec, keyword: aKey}); - - // Add tags if we need to - if (aTags != undefined && aTags.length > 0) { - // Convert each tag index into the title - let tags = aTags.map(aTag => kTitles[aTag]); - tagsvc.tagURI(uri, tags); - out.push("\ntags=" + tags); - } - } - - print("\nAdding page/book/tag: " + out.join(", ")); -} - -function run_test() { - print("\n"); - // always search in history + bookmarks, no matter what the default is - prefs.setBoolPref("browser.urlbar.suggest.history", true); - prefs.setBoolPref("browser.urlbar.suggest.bookmark", true); - prefs.setBoolPref("browser.urlbar.suggest.openpage", true); - prefs.setBoolPref("browser.urlbar.suggest.history.onlyTyped", false); - - // Search is asynchronous, so don't let the test finish immediately - do_test_pending(); - - // Load the test and print a description then run the test - let [description, search, expected, func] = gTests[current_test]; - print(description); - - // By default assume we want to match tags - appendTags = true; - - // Do an extra function if necessary - if (func) - func(); - - Task.spawn(function* () { - // Iterate over all tasks and execute them - for (let [fn, args] of gNextTestSetupTasks) { - yield fn.apply(this, args); - } - - // Clean up to allow tests to register more functions. - gNextTestSetupTasks = []; - - // At this point frecency could still be updating due to latest pages - // updates. This is not a problem in real life, but autocomplete tests - // should return reliable resultsets, thus we have to wait. - yield PlacesTestUtils.promiseAsyncUpdates(); - - }).then(() => ensure_results(search, expected), - do_report_unexpected_exception); -} - -// Utility function to remove history pages -function removePages(aURIs) -{ - gNextTestSetupTasks.push([do_removePages, arguments]); -} - -function do_removePages(aURIs) -{ - for (let uri of aURIs) - histsvc.removePage(toURI(kURIs[uri])); -} - -// Utility function to mark pages as typed -function markTyped(aURIs, aTitle) -{ - gNextTestSetupTasks.push([task_markTyped, arguments]); -} - -function* task_markTyped(aURIs, aTitle) -{ - for (let uri of aURIs) { - yield PlacesTestUtils.addVisits({ - uri: toURI(kURIs[uri]), - transition: TRANSITION_TYPED, - title: kTitles[aTitle] - }); - } -} diff --git a/toolkit/components/places/tests/autocomplete/test_416211.js b/toolkit/components/places/tests/autocomplete/test_416211.js deleted file mode 100644 index 8f662b5b13fc..000000000000 --- a/toolkit/components/places/tests/autocomplete/test_416211.js +++ /dev/null @@ -1,30 +0,0 @@ -/* 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/. */ - -/* - * Test bug 416211 to make sure results that match the tag show the bookmark - * title instead of the page title. - */ - -var theTag = "superTag"; - -// Define some shared uris and titles (each page needs its own uri) -var kURIs = [ - "http://theuri/", -]; -var kTitles = [ - "Page title", - "Bookmark title", - theTag, -]; - -// Add page with a title, bookmark, and [tags] -addPageBook(0, 0, 1, [2]); - -// Provide for each test: description; search terms; array of gPages indices of -// pages that should match; optional function to be run before the test -var gTests = [ - ["0: Make sure the tag match gives the bookmark title", - theTag, [0]], -]; diff --git a/toolkit/components/places/tests/autocomplete/test_416214.js b/toolkit/components/places/tests/autocomplete/test_416214.js deleted file mode 100644 index f8911800691a..000000000000 --- a/toolkit/components/places/tests/autocomplete/test_416214.js +++ /dev/null @@ -1,38 +0,0 @@ -/* 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/. */ - -/* - * Test autocomplete for non-English URLs that match the tag bug 416214. Also - * test bug 417441 by making sure escaped ascii characters like "+" remain - * escaped. - * - * - add a visit for a page with a non-English URL - * - add a tag for the page - * - search for the tag - * - test number of matches (should be exactly one) - * - make sure the url is decoded - */ - -var theTag = "superTag"; - -// Define some shared uris and titles (each page needs its own uri) -var kURIs = [ - "http://escaped/ユニコード", - "http://asciiescaped/blocking-firefox3%2B", -]; -var kTitles = [ - "title", - theTag, -]; - -// Add pages that match the tag -addPageBook(0, 0, 0, [1]); -addPageBook(1, 0, 0, [1]); - -// Provide for each test: description; search terms; array of gPages indices of -// pages that should match; optional function to be run before the test -var gTests = [ - ["0: Make sure tag matches return the right url as well as '+' remain escaped", - theTag, [0, 1]], -]; diff --git a/toolkit/components/places/tests/autocomplete/test_417798.js b/toolkit/components/places/tests/autocomplete/test_417798.js deleted file mode 100644 index 6306c4125c81..000000000000 --- a/toolkit/components/places/tests/autocomplete/test_417798.js +++ /dev/null @@ -1,36 +0,0 @@ -/* 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/. */ - -/** - * Test for bug 417798 to make sure javascript: URIs don't show up unless the - * user searches for javascript: explicitly. - */ - -// Define some shared uris and titles (each page needs its own uri) -var kURIs = [ - "http://abc/def", - "javascript:5", -]; -var kTitles = [ - "Title with javascript:", -]; - -addPageBook(0, 0); // regular url -// javascript: uri as bookmark (no visit) -addPageBook(1, 0, 0, undefined, undefined, undefined, true); - -// Provide for each test: description; search terms; array of gPages indices of -// pages that should match; optional function to be run before the test -var gTests = [ - ["0: Match non-javascript: with plain search", - "a", [0]], - ["1: Match non-javascript: with almost javascript:", - "javascript", [0]], - ["2: Match javascript:", - "javascript:", [0, 1]], - ["3: Match nothing with non-first javascript:", - "5 javascript:", []], - ["4: Match javascript: with multi-word search", - "javascript: 5", [1]], -]; diff --git a/toolkit/components/places/tests/autocomplete/test_418257.js b/toolkit/components/places/tests/autocomplete/test_418257.js deleted file mode 100644 index edff19d8b0f0..000000000000 --- a/toolkit/components/places/tests/autocomplete/test_418257.js +++ /dev/null @@ -1,43 +0,0 @@ -/* 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/. */ - -/** - * Test bug 418257 by making sure tags are returned with the title as part of - * the "comment" if there are tags even if we didn't match in the tags. They - * are separated from the title by a endash. - */ - -// Define some shared uris and titles (each page needs its own uri) -var kURIs = [ - "http://page1", - "http://page2", - "http://page3", - "http://page4", -]; -var kTitles = [ - "tag1", - "tag2", - "tag3", -]; - -// Add pages with varying number of tags -addPageBook(0, 0, 0, [0]); -addPageBook(1, 0, 0, [0, 1]); -addPageBook(2, 0, 0, [0, 2]); -addPageBook(3, 0, 0, [0, 1, 2]); - -// Provide for each test: description; search terms; array of gPages indices of -// pages that should match; optional function to be run before the test -var gTests = [ - ["0: Make sure tags come back in the title when matching tags", - "page1 tag", [0]], - ["1: Check tags in title for page2", - "page2 tag", [1]], - ["2: Make sure tags appear even when not matching the tag", - "page3", [2]], - ["3: Multiple tags come in commas for page4", - "page4", [3]], - ["4: Extra test just to make sure we match the title", - "tag2", [1, 3]], -]; diff --git a/toolkit/components/places/tests/autocomplete/test_422277.js b/toolkit/components/places/tests/autocomplete/test_422277.js deleted file mode 100644 index d6eb193dc8f0..000000000000 --- a/toolkit/components/places/tests/autocomplete/test_422277.js +++ /dev/null @@ -1,25 +0,0 @@ -/* 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/. */ - -/** - * Test bug 422277 to make sure bad escaped uris don't get escaped. This makes - * sure we don't hit an assertion for "not a UTF8 string". - */ - -// Define some shared uris and titles (each page needs its own uri) -var kURIs = [ - "http://site/%EAid", -]; -var kTitles = [ - "title", -]; - -addPageBook(0, 0); - -// Provide for each test: description; search terms; array of gPages indices of -// pages that should match; optional function to be run before the test -var gTests = [ - ["0: Bad escaped uri stays escaped", - "site", [0]], -]; diff --git a/toolkit/components/places/tests/autocomplete/test_autocomplete_on_value_removed_479089.js b/toolkit/components/places/tests/autocomplete/test_autocomplete_on_value_removed_479089.js deleted file mode 100644 index 8c9b31cdbbba..000000000000 --- a/toolkit/components/places/tests/autocomplete/test_autocomplete_on_value_removed_479089.js +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* 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/. */ - -/* - * Need to test that removing a page from autocomplete actually removes a page - * Description From Shawn Wilsher :sdwilsh 2009-02-18 11:29:06 PST - * We don't test the code path of onValueRemoved - * for the autocomplete implementation - * Bug 479089 - */ - -var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"]. -getService(Ci.nsINavHistoryService); - -function run_test() -{ - run_next_test(); -} - -add_task(function* test_autocomplete_on_value_removed() -{ - // QI to nsIAutoCompleteSimpleResultListener - var listener = Cc["@mozilla.org/autocomplete/search;1?name=history"]. - getService(Components.interfaces.nsIAutoCompleteSimpleResultListener); - - // add history visit - var testUri = uri("http://foo.mozilla.com/"); - yield PlacesTestUtils.addVisits({ - uri: testUri, - referrer: uri("http://mozilla.com/") - }); - // create a query object - var query = histsvc.getNewQuery(); - // create the options object we will never use - var options = histsvc.getNewQueryOptions(); - // look for this uri only - query.uri = testUri; - // execute - var queryRes = histsvc.executeQuery(query, options); - // open the result container - queryRes.root.containerOpen = true; - // debug queries - // dump_table("moz_places"); - do_check_eq(queryRes.root.childCount, 1); - // call the untested code path - listener.onValueRemoved(null, testUri.spec, true); - // make sure it is GONE from the DB - do_check_eq(queryRes.root.childCount, 0); - // close the container - queryRes.root.containerOpen = false; -}); diff --git a/toolkit/components/places/tests/autocomplete/test_download_embed_bookmarks.js b/toolkit/components/places/tests/autocomplete/test_download_embed_bookmarks.js deleted file mode 100644 index 65bec60cc787..000000000000 --- a/toolkit/components/places/tests/autocomplete/test_download_embed_bookmarks.js +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * vim:set ts=2 sw=2 sts=2 et: - * 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/. */ - -/** - * Tests bug 449406 to ensure that TRANSITION_DOWNLOAD, TRANSITION_EMBED and - * TRANSITION_FRAMED_LINK bookmarked uri's show up in the location bar. - */ - -// Define some shared uris and titles (each page needs its own uri) -var kURIs = [ - "http://download/bookmarked", - "http://embed/bookmarked", - "http://framed/bookmarked", - "http://download", - "http://embed", - "http://framed", -]; -var kTitles = [ - "download-bookmark", - "embed-bookmark", - "framed-bookmark", - "download2", - "embed2", - "framed2", -]; - -// Add download and embed uris -addPageBook(0, 0, 0, undefined, undefined, TRANSITION_DOWNLOAD); -addPageBook(1, 1, 1, undefined, undefined, TRANSITION_EMBED); -addPageBook(2, 2, 2, undefined, undefined, TRANSITION_FRAMED_LINK); -addPageBook(3, 3, undefined, undefined, undefined, TRANSITION_DOWNLOAD); -addPageBook(4, 4, undefined, undefined, undefined, TRANSITION_EMBED); -addPageBook(5, 5, undefined, undefined, undefined, TRANSITION_FRAMED_LINK); - -// Provide for each test: description; search terms; array of gPages indices of -// pages that should match; optional function to be run before the test -var gTests = [ - ["0: Searching for bookmarked download uri matches", - kTitles[0], [0]], - ["1: Searching for bookmarked embed uri matches", - kTitles[1], [1]], - ["2: Searching for bookmarked framed uri matches", - kTitles[2], [2]], - ["3: Searching for download uri does not match", - kTitles[3], []], - ["4: Searching for embed uri does not match", - kTitles[4], []], - ["5: Searching for framed uri does not match", - kTitles[5], []], -]; diff --git a/toolkit/components/places/tests/autocomplete/test_empty_search.js b/toolkit/components/places/tests/autocomplete/test_empty_search.js deleted file mode 100644 index df8eac383a7e..000000000000 --- a/toolkit/components/places/tests/autocomplete/test_empty_search.js +++ /dev/null @@ -1,69 +0,0 @@ -/* 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/. */ - -/** - * Test for bug 426864 that makes sure the empty search (drop down list) only - * shows typed pages from history. - */ - -// Define some shared uris and titles (each page needs its own uri) -var kURIs = [ - "http://foo/0", - "http://foo/1", - "http://foo/2", - "http://foo/3", - "http://foo/4", - "http://foo/5", -]; -var kTitles = [ - "title", -]; - -// Visited (in history) -addPageBook(0, 0); // history -addPageBook(1, 0, 0); // bookmark -addPageBook(2, 0); // history typed -addPageBook(3, 0, 0); // bookmark typed - -// Unvisited bookmark -addPageBook(4, 0, 0); // bookmark -addPageBook(5, 0, 0); // bookmark typed - -// Set some pages as typed -markTyped([2, 3, 5], 0); -// Remove pages from history to treat them as unvisited -removePages([4, 5]); - -// Provide for each test: description; search terms; array of gPages indices of -// pages that should match; optional function to be run before the test -var gTests = [ - ["0: Match everything", - "foo", [0, 1, 2, 3, 4, 5]], - ["1: Match only typed history", - "foo ^ ~", [2, 3]], - ["2: Drop-down empty search matches only typed history", - "", [2, 3]], - ["3: Drop-down empty search matches only bookmarks", - "", [2, 3], matchBookmarks], - ["4: Drop-down empty search matches only typed", - "", [2, 3], matchTyped], -]; - -function matchBookmarks() { - prefs.setBoolPref("browser.urlbar.suggest.history", false); - prefs.setBoolPref("browser.urlbar.suggest.bookmark", true); - clearPrefs(); -} - -function matchTyped() { - prefs.setBoolPref("browser.urlbar.suggest.history", true); - prefs.setBoolPref("browser.urlbar.suggest.history.onlyTyped", true); - clearPrefs(); -} - -function clearPrefs() { - prefs.clearUserPref("browser.urlbar.suggest.history"); - prefs.clearUserPref("browser.urlbar.suggest.bookmark"); - prefs.clearUserPref("browser.urlbar.suggest.history.onlyTyped"); -} diff --git a/toolkit/components/places/tests/autocomplete/test_enabled.js b/toolkit/components/places/tests/autocomplete/test_enabled.js deleted file mode 100644 index 80fc4a136df7..000000000000 --- a/toolkit/components/places/tests/autocomplete/test_enabled.js +++ /dev/null @@ -1,69 +0,0 @@ -/* 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/. */ - -/** - * Test for bug 471903 to make sure searching in autocomplete can be turned on - * and off. Also test bug 463535 for pref changing search. - */ - -// Define some shared uris and titles (each page needs its own uri) -var kURIs = [ - "http://url/0", -]; -var kTitles = [ - "title", -]; - -addPageBook(0, 0); // visited page - -// Provide for each test: description; search terms; array of gPages indices of -// pages that should match; optional function to be run before the test -var gTests = [ - ["1: plain search", - "url", [0]], - ["2: search disabled", - "url", [], () => setSearch(0)], - ["3: resume normal search", - "url", [0], () => setSearch(1)], -]; - -function setSearch(aSearch) { - prefs.setBoolPref("browser.urlbar.autocomplete.enabled", !!aSearch); -} - -add_task(function* test_sync_enabled() { - // Initialize autocomplete component. - Cc["@mozilla.org/autocomplete/search;1?name=history"] - .getService(Ci.mozIPlacesAutoComplete); - - let types = [ "history", "bookmark", "openpage" ]; - - // Test the service keeps browser.urlbar.autocomplete.enabled synchronized - // with browser.urlbar.suggest prefs. - for (let type of types) { - Services.prefs.setBoolPref("browser.urlbar.suggest." + type, true); - } - Assert.equal(Services.prefs.getBoolPref("browser.urlbar.autocomplete.enabled"), true); - - // Disable autocomplete and check all the suggest prefs are set to false. - Services.prefs.setBoolPref("browser.urlbar.autocomplete.enabled", false); - for (let type of types) { - Assert.equal(Services.prefs.getBoolPref("browser.urlbar.suggest." + type), false); - } - - // Setting even a single suggest pref to true should enable autocomplete. - Services.prefs.setBoolPref("browser.urlbar.suggest.history", true); - for (let type of types.filter(t => t != "history")) { - Assert.equal(Services.prefs.getBoolPref("browser.urlbar.suggest." + type), false); - } - Assert.equal(Services.prefs.getBoolPref("browser.urlbar.autocomplete.enabled"), true); - - // Disable autocoplete again, then re-enable it and check suggest prefs - // have been reset. - Services.prefs.setBoolPref("browser.urlbar.autocomplete.enabled", false); - Services.prefs.setBoolPref("browser.urlbar.autocomplete.enabled", true); - for (let type of types.filter(t => t != "history")) { - Assert.equal(Services.prefs.getBoolPref("browser.urlbar.suggest." + type), true); - } -}); diff --git a/toolkit/components/places/tests/autocomplete/test_escape_self.js b/toolkit/components/places/tests/autocomplete/test_escape_self.js deleted file mode 100644 index 0b0918b8ffe2..000000000000 --- a/toolkit/components/places/tests/autocomplete/test_escape_self.js +++ /dev/null @@ -1,30 +0,0 @@ -/* 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/. */ - -/** - * Test bug 422698 to make sure searches with urls from the location bar - * correctly match itself when it contains escaped characters. - */ - -// Define some shared uris and titles (each page needs its own uri) -var kURIs = [ - "http://unescapeduri/", - "http://escapeduri/%40/", -]; -var kTitles = [ - "title", -]; - -// Add unescaped and escaped uris -addPageBook(0, 0); -addPageBook(1, 0); - -// Provide for each test: description; search terms; array of gPages indices of -// pages that should match; optional function to be run before the test -var gTests = [ - ["0: Unescaped location matches itself", - kURIs[0], [0]], - ["1: Escaped location matches itself", - kURIs[1], [1]], -]; diff --git a/toolkit/components/places/tests/autocomplete/test_ignore_protocol.js b/toolkit/components/places/tests/autocomplete/test_ignore_protocol.js deleted file mode 100644 index 2ad63b735f42..000000000000 --- a/toolkit/components/places/tests/autocomplete/test_ignore_protocol.js +++ /dev/null @@ -1,27 +0,0 @@ -/* 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/. */ - -/** - * Test bug 424509 to make sure searching for "h" doesn't match "http" of urls. - */ - -// Define some shared uris and titles (each page needs its own uri) -var kURIs = [ - "http://site/", - "http://happytimes/", -]; -var kTitles = [ - "title", -]; - -// Add site without "h" and with "h" -addPageBook(0, 0); -addPageBook(1, 0); - -// Provide for each test: description; search terms; array of gPages indices of -// pages that should match; optional function to be run before the test -var gTests = [ - ["0: Searching for h matches site and not http://", - "h", [1]], -]; diff --git a/toolkit/components/places/tests/autocomplete/test_keyword_search.js b/toolkit/components/places/tests/autocomplete/test_keyword_search.js deleted file mode 100644 index 796f386bb826..000000000000 --- a/toolkit/components/places/tests/autocomplete/test_keyword_search.js +++ /dev/null @@ -1,73 +0,0 @@ -/* 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/. */ - -/** - * Test for bug 392143 that puts keyword results into the autocomplete. Makes - * sure that multiple parameter queries get spaces converted to +, + converted - * to %2B, non-ascii become escaped, and pages in history that match the - * keyword uses the page's title. - * - * Also test for bug 249468 by making sure multiple keyword bookmarks with the - * same keyword appear in the list. - */ - -// Details for the keyword bookmark -var keyBase = "http://abc/?search="; -var keyKey = "key"; - -// A second keyword bookmark with the same keyword -var otherBase = "http://xyz/?foo="; - -var unescaped = "ユニコード"; -var pageInHistory = "ThisPageIsInHistory"; - -// Define some shared uris and titles (each page needs its own uri) -var kURIs = [ - keyBase + "%s", - keyBase + "term", - keyBase + "multi+word", - keyBase + "blocking%2B", - keyBase + unescaped, - keyBase + pageInHistory, - keyBase, - otherBase + "%s", - keyBase + "twoKey", - otherBase + "twoKey" -]; -var kTitles = [ - "Generic page title", - "Keyword title", - "abc", - "xyz" -]; - -// Add the keyword bookmark -addPageBook(0, 0, 1, [], keyKey); -// Add in the "fake pages" for keyword searches -gPages[1] = [1, 2]; -gPages[2] = [2, 2]; -gPages[3] = [3, 2]; -gPages[4] = [4, 2]; -// Add a page into history -addPageBook(5, 2); -gPages[6] = [6, 2]; - -// Provide for each test: description; search terms; array of gPages indices of -// pages that should match; optional function to be run before the test -var gTests = [ - ["0: Plain keyword query", - keyKey + " term", [1]], - ["1: Multi-word keyword query", - keyKey + " multi word", [2]], - ["2: Keyword query with +", - keyKey + " blocking+", [3]], - ["3: Unescaped term in query", - keyKey + " " + unescaped, [4]], - ["4: Keyword that happens to match a page", - keyKey + " " + pageInHistory, [5]], - ["5: Keyword without query (without space)", - keyKey, [6]], - ["6: Keyword without query (with space)", - keyKey + " ", [6]], -]; diff --git a/toolkit/components/places/tests/autocomplete/test_match_beginning.js b/toolkit/components/places/tests/autocomplete/test_match_beginning.js deleted file mode 100644 index b9ba3ab39b1c..000000000000 --- a/toolkit/components/places/tests/autocomplete/test_match_beginning.js +++ /dev/null @@ -1,45 +0,0 @@ -/* 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/. */ - -/** - * Test bug 451760 which allows matching only at the beginning of urls or - * titles to simulate Firefox 2 functionality. - */ - -// Define some shared uris and titles (each page needs its own uri) -var kURIs = [ - "http://x.com/y", - "https://y.com/x", -]; -var kTitles = [ - "a b", - "b a", -]; - -addPageBook(0, 0); -addPageBook(1, 1); - -// Provide for each test: description; search terms; array of gPages indices of -// pages that should match; optional function to be run before the test -var gTests = [ - // Tests after this one will match at the beginning - ["0: Match at the beginning of titles", - "a", [0], - () => setBehavior(3)], - ["1: Match at the beginning of titles", - "b", [1]], - ["2: Match at the beginning of urls", - "x", [0]], - ["3: Match at the beginning of urls", - "y", [1]], - - // Tests after this one will match against word boundaries and anywhere - ["4: Sanity check that matching anywhere finds more", - "a", [0, 1], - () => setBehavior(1)], -]; - -function setBehavior(aType) { - prefs.setIntPref("browser.urlbar.matchBehavior", aType); -} diff --git a/toolkit/components/places/tests/autocomplete/test_multi_word_search.js b/toolkit/components/places/tests/autocomplete/test_multi_word_search.js deleted file mode 100644 index c0b896c8687f..000000000000 --- a/toolkit/components/places/tests/autocomplete/test_multi_word_search.js +++ /dev/null @@ -1,49 +0,0 @@ -/* 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/. */ - -/** - * Test for bug 401869 to allow multiple words separated by spaces to match in - * the page title, page url, or bookmark title to be considered a match. All - * terms must match but not all terms need to be in the title, etc. - * - * Test bug 424216 by making sure bookmark titles are always shown if one is - * available. Also bug 425056 makes sure matches aren't found partially in the - * page title and partially in the bookmark. - */ - -// Define some shared uris and titles (each page needs its own uri) -var kURIs = [ - "http://a.b.c/d-e_f/h/t/p", - "http://d.e.f/g-h_i/h/t/p", - "http://g.h.i/j-k_l/h/t/p", - "http://j.k.l/m-n_o/h/t/p", -]; -var kTitles = [ - "f(o)o br", - "b(a)r bz", -]; - -// Regular pages -addPageBook(0, 0); -addPageBook(1, 1); -// Bookmarked pages -addPageBook(2, 0, 0); -addPageBook(3, 0, 1); - -// Provide for each test: description; search terms; array of gPages indices of -// pages that should match; optional function to be run before the test -var gTests = [ - ["0: Match 2 terms all in url", - "c d", [0]], - ["1: Match 1 term in url and 1 term in title", - "b e", [0, 1]], - ["2: Match 3 terms all in title; display bookmark title if matched", - "b a z", [1, 3]], - ["3: Match 2 terms in url and 1 in title; make sure bookmark title is used for search", - "k f t", [2]], - ["4: Match 3 terms in url and 1 in title", - "d i g z", [1]], - ["5: Match nothing", - "m o z i", []], -]; diff --git a/toolkit/components/places/tests/autocomplete/test_special_search.js b/toolkit/components/places/tests/autocomplete/test_special_search.js deleted file mode 100644 index 78bf5a7d6413..000000000000 --- a/toolkit/components/places/tests/autocomplete/test_special_search.js +++ /dev/null @@ -1,183 +0,0 @@ -/* 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/. */ - -/** - * Test for bug 395161 that allows special searches that restrict results to - * history/bookmark/tagged items and title/url matches. - * - * Test 485122 by making sure results don't have tags when restricting result - * to just history either by default behavior or dynamic query restrict. - */ - -// Define some shared uris and titles (each page needs its own uri) -var kURIs = [ - "http://url/", - "http://url/2", - "http://foo.bar/", - "http://foo.bar/2", - "http://url/star", - "http://url/star/2", - "http://foo.bar/star", - "http://foo.bar/star/2", - "http://url/tag", - "http://url/tag/2", - "http://foo.bar/tag", - "http://foo.bar/tag/2", -]; -var kTitles = [ - "title", - "foo.bar", -]; - -// Plain page visits -addPageBook(0, 0); // plain page -addPageBook(1, 1); // title -addPageBook(2, 0); // url -addPageBook(3, 1); // title and url - -// Bookmarked pages (no tag) -addPageBook(4, 0, 0); // bookmarked page -addPageBook(5, 1, 1); // title -addPageBook(6, 0, 0); // url -addPageBook(7, 1, 1); // title and url - -// Tagged pages -addPageBook(8, 0, 0, [1]); // tagged page -addPageBook(9, 1, 1, [1]); // title -addPageBook(10, 0, 0, [1]); // url -addPageBook(11, 1, 1, [1]); // title and url - -// Remove pages from history to treat them as unvisited, so pages that do have -// visits are 0,1,2,3,5,10 -removePages([4, 6, 7, 8, 9, 11]); -// Set some pages as typed -markTyped([0, 10], 0); -markTyped([3], 1); - -// Provide for each test: description; search terms; array of gPages indices of -// pages that should match; optional function to be run before the test -var gTests = [ - // Test restricting searches - ["0: History restrict", - "^", [0, 1, 2, 3, 5, 10]], - ["1: Star restrict", - "*", [4, 5, 6, 7, 8, 9, 10, 11]], - ["2: Tag restrict", - "+", [8, 9, 10, 11]], - - // Test specials as any word position - ["3: Special as first word", - "^ foo bar", [1, 2, 3, 5, 10]], - ["4: Special as middle word", - "foo ^ bar", [1, 2, 3, 5, 10]], - ["5: Special as last word", - "foo bar ^", [1, 2, 3, 5, 10]], - - // Test restricting and matching searches with a term - ["6.1: foo ^ -> history", - "foo ^", [1, 2, 3, 5, 10]], - ["6.2: foo | -> history (change pref)", - "foo |", [1, 2, 3, 5, 10], () => changeRestrict("history", "|")], - ["7.1: foo * -> is star", - "foo *", [5, 6, 7, 8, 9, 10, 11], () => resetRestrict("history")], - ["7.2: foo | -> is star (change pref)", - "foo |", [5, 6, 7, 8, 9, 10, 11], () => changeRestrict("bookmark", "|")], - ["8.1: foo # -> in title", - "foo #", [1, 3, 5, 7, 8, 9, 10, 11], () => resetRestrict("bookmark")], - ["8.2: foo | -> in title (change pref)", - "foo |", [1, 3, 5, 7, 8, 9, 10, 11], () => changeRestrict("title", "|")], - ["9.1: foo @ -> in url", - "foo @", [2, 3, 6, 7, 10, 11], () => resetRestrict("title")], - ["9.2: foo | -> in url (change pref)", - "foo |", [2, 3, 6, 7, 10, 11], () => changeRestrict("url", "|")], - ["10: foo + -> is tag", - "foo +", [8, 9, 10, 11], () => resetRestrict("url")], - ["10.2: foo | -> is tag (change pref)", - "foo |", [8, 9, 10, 11], () => changeRestrict("tag", "|")], - ["10.3: foo ~ -> is typed", - "foo ~", [3, 10], () => resetRestrict("tag")], - ["10.4: foo | -> is typed (change pref)", - "foo |", [3, 10], () => changeRestrict("typed", "|")], - - // Test various pairs of special searches - ["11: foo ^ * -> history, is star", - "foo ^ *", [5, 10], () => resetRestrict("typed")], - ["12: foo ^ # -> history, in title", - "foo ^ #", [1, 3, 5, 10]], - ["13: foo ^ @ -> history, in url", - "foo ^ @", [2, 3, 10]], - ["14: foo ^ + -> history, is tag", - "foo ^ +", [10]], - ["14.1: foo ^ ~ -> history, is typed", - "foo ^ ~", [3, 10]], - ["15: foo * # -> is star, in title", - "foo * #", [5, 7, 8, 9, 10, 11]], - ["16: foo * @ -> is star, in url", - "foo * @", [6, 7, 10, 11]], - ["17: foo * + -> same as +", - "foo * +", [8, 9, 10, 11]], - ["17.1: foo * ~ -> is star, is typed", - "foo * ~", [10]], - ["18: foo # @ -> in title, in url", - "foo # @", [3, 7, 10, 11]], - ["19: foo # + -> in title, is tag", - "foo # +", [8, 9, 10, 11]], - ["19.1: foo # ~ -> in title, is typed", - "foo # ~", [3, 10]], - ["20: foo @ + -> in url, is tag", - "foo @ +", [10, 11]], - ["20.1: foo @ ~ -> in url, is typed", - "foo @ ~", [3, 10]], - ["20.2: foo + ~ -> is tag, is typed", - "foo + ~", [10]], - - // Test default usage by setting certain bits of default.behavior to 1 - ["21: foo -> default history", - "foo", [1, 2, 3, 5, 10], function () { setPref({ history: true }); }], - ["22: foo -> default history or is star", - "foo", [1, 2, 3, 5, 6, 7, 8, 9, 10, 11], () => setPref({ history: true, bookmark: true })], - ["22.1: foo -> default history or is star, is typed", - "foo", [3, 10], () => setPref({ history: true, bookmark: true, "history.onlyTyped": true })], - -]; - -function setPref(aTypes) { - clearSuggestPrefs(); - for (let type in aTypes) { - prefs.setBoolPref("browser.urlbar.suggest." + type, aTypes[type]); - } -} - -function clearSuggestPrefs() { - prefs.setBoolPref("browser.urlbar.suggest.history", false); - prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); - prefs.setBoolPref("browser.urlbar.suggest.history.onlyTyped", false); - prefs.setBoolPref("browser.urlbar.suggest.openpage", false); -} - -function changeRestrict(aType, aChar) -{ - let branch = "browser.urlbar."; - // "title" and "url" are different from everything else, so special case them. - if (aType == "title" || aType == "url") - branch += "match."; - else - branch += "restrict."; - - print("changing restrict for " + aType + " to '" + aChar + "'"); - prefs.setCharPref(branch + aType, aChar); -} - -function resetRestrict(aType) -{ - let branch = "browser.urlbar."; - // "title" and "url" are different from everything else, so special case them. - if (aType == "title" || aType == "url") - branch += "match."; - else - branch += "restrict."; - - if (prefs.prefHasUserValue(branch + aType)) - prefs.clearUserPref(branch + aType); -} diff --git a/toolkit/components/places/tests/autocomplete/test_swap_protocol.js b/toolkit/components/places/tests/autocomplete/test_swap_protocol.js deleted file mode 100644 index 860b722498e6..000000000000 --- a/toolkit/components/places/tests/autocomplete/test_swap_protocol.js +++ /dev/null @@ -1,63 +0,0 @@ -/* 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/. */ - -/** - * Test bug 424717 to make sure searching with an existing location like - * http://site/ also matches https://site/ or ftp://site/. Same thing for - * ftp://site/ and https://site/. - * - * Test bug 461483 to make sure a search for "w" doesn't match the "www." from - * site subdomains. - */ - -// Define some shared uris and titles (each page needs its own uri) -var kURIs = [ - "http://www.site/", - "http://site/", - "ftp://ftp.site/", - "ftp://site/", - "https://www.site/", - "https://site/", - "http://woohoo/", - "http://wwwwwwacko/", -]; -var kTitles = [ - "title", -]; - -// Add various protocols of site -addPageBook(0, 0); -addPageBook(1, 0); -addPageBook(2, 0); -addPageBook(3, 0); -addPageBook(4, 0); -addPageBook(5, 0); -addPageBook(6, 0); -addPageBook(7, 0); - -var allSite = [0, 1, 2, 3, 4, 5]; - -// Provide for each test: description; search terms; array of gPages indices of -// pages that should match; optional function to be run before the test -var gTests = [ - ["0: http://www.site matches all site", "http://www.site", allSite], - ["1: http://site matches all site", "http://site", allSite], - ["2: ftp://ftp.site matches itself", "ftp://ftp.site", [2]], - ["3: ftp://site matches all site", "ftp://site", allSite], - ["4: https://www.site matches all site", "https://www.site", allSite], - ["5: https://site matches all site", "https://site", allSite], - ["6: www.site matches all site", "www.site", allSite], - - ["7: w matches none of www.", "w", [6, 7]], - ["8: http://w matches none of www.", "w", [6, 7]], - ["9: http://www.w matches none of www.", "w", [6, 7]], - - ["10: ww matches none of www.", "ww", [7]], - ["11: http://ww matches none of www.", "http://ww", [7]], - ["12: http://www.ww matches none of www.", "http://www.ww", [7]], - - ["13: www matches none of www.", "www", [7]], - ["14: http://www matches none of www.", "http://www", [7]], - ["15: http://www.www matches none of www.", "http://www.www", [7]], -]; diff --git a/toolkit/components/places/tests/autocomplete/test_tabmatches.js b/toolkit/components/places/tests/autocomplete/test_tabmatches.js deleted file mode 100644 index 98ada6c42e44..000000000000 --- a/toolkit/components/places/tests/autocomplete/test_tabmatches.js +++ /dev/null @@ -1,97 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * vim:set ts=2 sw=2 sts=2 et: - * 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/. */ - -var gTabRestrictChar = "%"; -prefs.setCharPref("browser.urlbar.restrict.openpage", gTabRestrictChar); -do_register_cleanup(() => { - prefs.clearUserPref("browser.urlbar.restrict.openpage"); -}); - -var kSearchParam = "enable-actions"; - -var kURIs = [ - "http://abc.com/", - "moz-action:switchtab,http://abc.com/", - "http://xyz.net/", - "moz-action:switchtab,http://xyz.net/", - "about:mozilla", - "moz-action:switchtab,about:mozilla", - "data:text/html,test", - "moz-action:switchtab,data:text/html,test" -]; - -var kTitles = [ - "ABC rocks", - "xyz.net - we're better than ABC", - "about:mozilla", - "data:text/html,test" -]; - -addPageBook(0, 0); -gPages[1] = [1, 0]; -addPageBook(2, 1); -gPages[3] = [3, 1]; - -addOpenPages(0, 1); - -// PAges that cannot be registered in history. -addOpenPages(4, 1); -gPages[5] = [5, 2]; -addOpenPages(6, 1); -gPages[7] = [7, 3]; - -var gTests = [ - ["0: single result, that is also a tab match", - "abc.com", [1]], - ["1: two results, one tab match", - "abc", [1, 2]], - ["2: two results, both tab matches", - "abc", [1, 3], - function() { - addOpenPages(2, 1); - }], - ["3: two results, both tab matches, one has multiple tabs", - "abc", [1, 3], - function() { - addOpenPages(2, 5); - }], - ["4: two results, no tab matches", - "abc", [0, 2], - function() { - removeOpenPages(0, 1); - removeOpenPages(2, 6); - }], - ["5: tab match search with restriction character", - gTabRestrictChar + " abc", [1], - function() { - addOpenPages(0, 1); - }], - ["6: tab match with not-addable pages", - "mozilla", [5]], - ["7: tab match with not-addable pages and restriction character", - gTabRestrictChar + " mozilla", [5]], - ["8: tab match with not-addable pages and only restriction character", - gTabRestrictChar, [1, 5, 7]], -]; - - -function addOpenPages(aUri, aCount) { - let num = aCount || 1; - let acprovider = Cc["@mozilla.org/autocomplete/search;1?name=history"]. - getService(Ci.mozIPlacesAutoComplete); - for (let i = 0; i < num; i++) { - acprovider.registerOpenPage(toURI(kURIs[aUri])); - } -} - -function removeOpenPages(aUri, aCount) { - let num = aCount || 1; - let acprovider = Cc["@mozilla.org/autocomplete/search;1?name=history"]. - getService(Ci.mozIPlacesAutoComplete); - for (let i = 0; i < num; i++) { - acprovider.unregisterOpenPage(toURI(kURIs[aUri])); - } -} diff --git a/toolkit/components/places/tests/autocomplete/test_word_boundary_search.js b/toolkit/components/places/tests/autocomplete/test_word_boundary_search.js deleted file mode 100644 index b4ae3684911e..000000000000 --- a/toolkit/components/places/tests/autocomplete/test_word_boundary_search.js +++ /dev/null @@ -1,105 +0,0 @@ -/* 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/. */ - -/** - * Test bug 393678 to make sure matches against the url, title, tags are only - * made on word boundaries instead of in the middle of words. - * - * Make sure we don't try matching one after a CamelCase because the upper-case - * isn't really a word boundary. (bug 429498) - * - * Bug 429531 provides switching between "must match on word boundary" and "can - * match," so leverage "must match" pref for checking word boundary logic and - * make sure "can match" matches anywhere. - */ - -var katakana = ["\u30a8", "\u30c9"]; // E, Do -var ideograph = ["\u4efb", "\u5929", "\u5802"]; // Nin Ten Do - -// Define some shared uris and titles (each page needs its own uri) -var kURIs = [ - "http://matchme/", - "http://dontmatchme/", - "http://title/1", - "http://title/2", - "http://tag/1", - "http://tag/2", - "http://crazytitle/", - "http://katakana/", - "http://ideograph/", - "http://camel/pleaseMatchMe/", -]; -var kTitles = [ - "title1", - "matchme2", - "dontmatchme3", - "!@#$%^&*()_+{}|:<>?word", - katakana.join(""), - ideograph.join(""), -]; - -// Boundaries on the url -addPageBook(0, 0); -addPageBook(1, 0); -// Boundaries on the title -addPageBook(2, 1); -addPageBook(3, 2); -// Boundaries on the tag -addPageBook(4, 0, 0, [1]); -addPageBook(5, 0, 0, [2]); -// Lots of word boundaries before a word -addPageBook(6, 3); -// Katakana -addPageBook(7, 4); -// Ideograph -addPageBook(8, 5); -// CamelCase -addPageBook(9, 0); - -// Provide for each test: description; search terms; array of gPages indices of -// pages that should match; optional function to be run before the test -var gTests = [ - // Tests after this one will match only on word boundaries - ["0: Match 'match' at the beginning or after / or on a CamelCase", - "match", [0, 2, 4, 9], - () => setBehavior(2)], - ["1: Match 'dont' at the beginning or after /", - "dont", [1, 3, 5]], - ["2: Match '2' after the slash and after a word (in tags too)", - "2", [2, 3, 4, 5]], - ["3: Match 't' at the beginning or after /", - "t", [0, 1, 2, 3, 4, 5, 9]], - ["4: Match 'word' after many consecutive word boundaries", - "word", [6]], - ["5: Match a word boundary '/' for everything", - "/", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], - ["6: Match word boundaries '()_+' that are among word boundaries", - "()_+", [6]], - - ["7: Katakana characters form a string, so match the beginning", - katakana[0], [7]], - /*["8: Middle of a katakana word shouldn't be matched", - katakana[1], []],*/ - - ["9: Ideographs are treated as words so 'nin' is one word", - ideograph[0], [8]], - ["10: Ideographs are treated as words so 'ten' is another word", - ideograph[1], [8]], - ["11: Ideographs are treated as words so 'do' is yet another", - ideograph[2], [8]], - - ["12: Extra negative assert that we don't match in the middle", - "ch", []], - ["13: Don't match one character after a camel-case word boundary (bug 429498)", - "atch", []], - - // Tests after this one will match against word boundaries and anywhere - ["14: Match on word boundaries as well as anywhere (bug 429531)", - "tch", [0, 1, 2, 3, 4, 5, 9], - () => setBehavior(1)], -]; - -function setBehavior(aType) { - prefs.setIntPref("browser.urlbar.matchBehavior", aType); -} diff --git a/toolkit/components/places/tests/autocomplete/xpcshell.ini b/toolkit/components/places/tests/autocomplete/xpcshell.ini deleted file mode 100644 index 7c018dbcc7b7..000000000000 --- a/toolkit/components/places/tests/autocomplete/xpcshell.ini +++ /dev/null @@ -1,29 +0,0 @@ -[DEFAULT] -head = head_autocomplete.js -tail = -skip-if = toolkit == 'android' || toolkit == 'gonk' - -[test_416211.js] -[test_416214.js] -[test_417798.js] -[test_418257.js] -[test_422277.js] -[test_autocomplete_on_value_removed_479089.js] -# Bug 676989: test fails consistently on Android -fail-if = os == "android" -[test_download_embed_bookmarks.js] -# Bug 676989: test fails consistently on Android -fail-if = os == "android" -[test_empty_search.js] -# Bug 676989: test fails consistently on Android -fail-if = os == "android" -[test_enabled.js] -[test_escape_self.js] -[test_ignore_protocol.js] -[test_keyword_search.js] -[test_match_beginning.js] -[test_multi_word_search.js] -[test_special_search.js] -[test_swap_protocol.js] -[test_tabmatches.js] -[test_word_boundary_search.js] diff --git a/toolkit/components/places/tests/moz.build b/toolkit/components/places/tests/moz.build index d3a2c79fc260..5f9460babfd9 100644 --- a/toolkit/components/places/tests/moz.build +++ b/toolkit/components/places/tests/moz.build @@ -22,11 +22,6 @@ XPCSHELL_TESTS_MANIFESTS += [ 'unit/xpcshell.ini', ] -if CONFIG['MOZ_SUITE']: - XPCSHELL_TESTS_MANIFESTS += [ - 'autocomplete/xpcshell.ini', - ] - BROWSER_CHROME_MANIFESTS += ['browser/browser.ini'] MOCHITEST_CHROME_MANIFESTS += [ 'chrome/chrome.ini',