From 6ab3daf47c305fdd2f03ea092cd5b78066725976 Mon Sep 17 00:00:00 2001 From: Blair McBride Date: Tue, 30 Sep 2014 15:04:58 +1300 Subject: [PATCH] Bug 1073846 - Wrong URL loads after autofill of a hostname that matches a search engine. r=mak --HG-- extra : transplant_source : %ABR%7F%94S%92%FD%B5%0B%1D%2B%CBc%7D-%7B%F6%D0%0C%13 --- toolkit/components/places/UnifiedComplete.js | 11 ++-- .../data/engine-rel-searchform.xml | 5 ++ .../unifiedcomplete/test_searchEngine_host.js | 58 ++++++++++++++++++- .../places/tests/unifiedcomplete/xpcshell.ini | 3 + 4 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 toolkit/components/places/tests/unifiedcomplete/data/engine-rel-searchform.xml diff --git a/toolkit/components/places/UnifiedComplete.js b/toolkit/components/places/UnifiedComplete.js index 245eb79b95df..5b3e54f319e0 100644 --- a/toolkit/components/places/UnifiedComplete.js +++ b/toolkit/components/places/UnifiedComplete.js @@ -712,12 +712,8 @@ Search.prototype = { // with an alias - which works like a keyword. hasFirstResult = yield this._matchSearchEngineAlias(); } - let shouldAutofill = this._shouldAutofill; - if (this.pending && !hasFirstResult && shouldAutofill) { - // Or it may look like a URL we know about from search engines. - hasFirstResult = yield this._matchSearchEngineUrl(); - } + let shouldAutofill = this._shouldAutofill; if (this.pending && !hasFirstResult && shouldAutofill) { // It may also look like a URL we know from the database. // Here we can only try to predict whether the URL autofill query is @@ -726,6 +722,11 @@ Search.prototype = { hasFirstResult = yield this._matchKnownUrl(conn, queries); } + if (this.pending && !hasFirstResult && shouldAutofill) { + // Or it may look like a URL we know about from search engines. + hasFirstResult = yield this._matchSearchEngineUrl(); + } + if (this.pending && this._enableActions && !hasFirstResult) { // If we don't have a result that matches what we know about, then // we use a fallback for things we don't know about. diff --git a/toolkit/components/places/tests/unifiedcomplete/data/engine-rel-searchform.xml b/toolkit/components/places/tests/unifiedcomplete/data/engine-rel-searchform.xml new file mode 100644 index 000000000000..f4baad28ab18 --- /dev/null +++ b/toolkit/components/places/tests/unifiedcomplete/data/engine-rel-searchform.xml @@ -0,0 +1,5 @@ + + +engine-rel-searchform.xml + + diff --git a/toolkit/components/places/tests/unifiedcomplete/test_searchEngine_host.js b/toolkit/components/places/tests/unifiedcomplete/test_searchEngine_host.js index 4192ca785862..1ed30e4b549e 100644 --- a/toolkit/components/places/tests/unifiedcomplete/test_searchEngine_host.js +++ b/toolkit/components/places/tests/unifiedcomplete/test_searchEngine_host.js @@ -1,6 +1,42 @@ /* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ +Cu.import("resource://testing-common/httpd.js"); + +function* addTestEngines(items) { + let httpServer = new HttpServer(); + httpServer.start(-1); + httpServer.registerDirectory("/", do_get_cwd()); + let gDataUrl = "http://localhost:" + httpServer.identity.primaryPort + "/data/"; + do_register_cleanup(() => httpServer.stop(() => {})); + + let engines = []; + + for (let item of items) { + do_print("Adding engine: " + item); + yield new Promise(resolve => { + Services.obs.addObserver(function obs(subject, topic, data) { + let engine = subject.QueryInterface(Ci.nsISearchEngine); + do_print("Observed " + data + " for " + engine.name); + if (data != "engine-added" || engine.name != item) { + return; + } + + Services.obs.removeObserver(obs, "browser-search-engine-modified"); + engines.push(engine); + resolve(); + }, "browser-search-engine-modified", false); + + do_print("`Adding engine from URL: " + gDataUrl + item); + Services.search.addEngine(gDataUrl + item, + Ci.nsISearchEngine.DATA_XML, null, false); + }); + } + + return engines; +} + + add_task(function* test_searchEngine_autoFill() { Services.search.addEngineWithDetails("MySearchEngine", "", "", "", "GET", "http://my.search.com/"); @@ -15,7 +51,7 @@ add_task(function* test_searchEngine_autoFill() { } yield promiseAddVisits(visits); addBookmark({ uri: uri, title: "Example bookmark" }); - Assert.ok(frecencyForUrl(uri) > 10000); + ok(frecencyForUrl(uri) > 10000, "Adeded URI should have expected high frecency"); do_log_info("Check search domain is autoFilled even if there's an higher frecency match"); yield check_autocomplete({ @@ -26,3 +62,23 @@ add_task(function* test_searchEngine_autoFill() { yield cleanup(); }); + +add_task(function* test_searchEngine_noautoFill() { + let engineName = "engine-rel-searchform.xml"; + let [engine] = yield addTestEngines([engineName]); + do_register_cleanup(() => Services.search.removeEngine(engine)); + equal(engine.searchForm, "http://example.com/?search"); + + Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false); + yield promiseAddVisits(NetUtil.newURI("http://example.com/my/")); + + do_print("Check search domain is not autoFilled if it matches a visited domain"); + yield check_autocomplete({ + search: "example", + autofilled: "example.com/", + completed: "example.com/" + }); + + yield cleanup(); +}); + diff --git a/toolkit/components/places/tests/unifiedcomplete/xpcshell.ini b/toolkit/components/places/tests/unifiedcomplete/xpcshell.ini index ae7fbd63c8c9..f05a175f7cb9 100644 --- a/toolkit/components/places/tests/unifiedcomplete/xpcshell.ini +++ b/toolkit/components/places/tests/unifiedcomplete/xpcshell.ini @@ -1,6 +1,9 @@ [DEFAULT] head = head_autocomplete.js tail = +support-files = + data/engine-rel-searchform.xml + [test_416211.js] [test_416214.js]