diff options
author | bartn@chromium.org <bartn@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-30 00:20:26 +0000 |
---|---|---|
committer | bartn@chromium.org <bartn@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-30 00:20:26 +0000 |
commit | dbff44658056494b320b593c986cd719173681e7 (patch) | |
tree | 123e38ad3214b7f130c9bd53da4fdc1f0d11d960 /chrome/browser | |
parent | 2dbcad1cd7537645456400c42d8b69782f80bfc4 (diff) | |
download | chromium_src-dbff44658056494b320b593c986cd719173681e7.zip chromium_src-dbff44658056494b320b593c986cd719173681e7.tar.gz chromium_src-dbff44658056494b320b593c986cd719173681e7.tar.bz2 |
Initial implementation of dedupping search provider's URLs.
There are two main sources of such URLs:
(1) search provider itself
(2) history URL providers (after visiting a previously suggested URL).
A search provider URL may contain time/position specific CGI params,
which if left, may prevent from dedupping.
BUG=146551
TEST=AutocompleteResultTest::SortAndCullDuplicateSearchURLs
Review URL: https://chromiumcodereview.appspot.com/11198074
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@164790 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
14 files changed, 153 insertions, 35 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_browsertest.cc b/chrome/browser/autocomplete/autocomplete_browsertest.cc index 0c91c9c..ce9675a 100644 --- a/chrome/browser/autocomplete/autocomplete_browsertest.cc +++ b/chrome/browser/autocomplete/autocomplete_browsertest.cc @@ -15,6 +15,7 @@ #include "chrome/browser/history/history.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_tabstrip.h" @@ -48,6 +49,11 @@ string16 AutocompleteResultAsString(const AutocompleteResult& result) { class AutocompleteBrowserTest : public ExtensionBrowserTest { protected: + void WaitForTemplateURLServiceToLoad() { + ui_test_utils::WaitForTemplateURLServiceToLoad( + TemplateURLServiceFactory::GetForProfile(browser()->profile())); + } + LocationBar* GetLocationBar() const { return browser()->window()->GetLocationBar(); } @@ -59,6 +65,7 @@ class AutocompleteBrowserTest : public ExtensionBrowserTest { }; IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, Basic) { + WaitForTemplateURLServiceToLoad(); LocationBar* location_bar = GetLocationBar(); OmniboxView* location_entry = location_bar->GetLocationEntry(); @@ -102,6 +109,7 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, Basic) { #endif IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, MAYBE_Autocomplete) { + WaitForTemplateURLServiceToLoad(); // The results depend on the history backend being loaded. Make sure it is // loaded so that the autocomplete results are consistent. ui_test_utils::WaitForHistoryToLoad( @@ -145,6 +153,7 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, MAYBE_Autocomplete) { } IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, TabAwayRevertSelect) { + WaitForTemplateURLServiceToLoad(); // http://code.google.com/p/chromium/issues/detail?id=38385 // Make sure that tabbing away from an empty omnibar causes a revert // and select all. @@ -165,6 +174,7 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, TabAwayRevertSelect) { } IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) { + WaitForTemplateURLServiceToLoad(); LocationBar* location_bar = GetLocationBar(); OmniboxView* location_entry = location_bar->GetLocationEntry(); @@ -251,6 +261,7 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) { } IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, ExtensionAppProvider) { + WaitForTemplateURLServiceToLoad(); ExtensionService* service = browser()->profile()->GetExtensionService(); size_t extension_count = service->extensions()->size(); diff --git a/chrome/browser/autocomplete/autocomplete_controller.cc b/chrome/browser/autocomplete/autocomplete_controller.cc index 572796d..9c2a406 100644 --- a/chrome/browser/autocomplete/autocomplete_controller.cc +++ b/chrome/browser/autocomplete/autocomplete_controller.cc @@ -278,7 +278,7 @@ void AutocompleteController::OnProviderUpdate(bool updated_matches) { // because results from other providers are stale. result_.Reset(); result_.AppendMatches(zero_suggest_provider_->matches()); - result_.SortAndCull(input_); + result_.SortAndCull(input_, profile_); NotifyChanged(true); } else { CheckIfDone(); @@ -311,7 +311,7 @@ void AutocompleteController::UpdateResult(bool is_synchronous_pass) { result_.AppendMatches((*i)->matches()); // Sort the matches and trim to a small number of "best" matches. - result_.SortAndCull(input_); + result_.SortAndCull(input_, profile_); // Need to validate before invoking CopyOldMatches as the old matches are not // valid against the current input. @@ -322,7 +322,7 @@ void AutocompleteController::UpdateResult(bool is_synchronous_pass) { if (!done_) { // This conditional needs to match the conditional in Start that invokes // StartExpireTimer. - result_.CopyOldMatches(input_, last_result); + result_.CopyOldMatches(input_, last_result, profile_); } UpdateKeywordDescriptions(&result_); @@ -409,7 +409,7 @@ void AutocompleteController::UpdateAssistedQueryStats( // Go over all matches and set AQS if the match supports it. for (size_t index = 0; index < result->size(); ++index) { AutocompleteMatch* match = result->match_at(index); - const TemplateURL* template_url = match->GetTemplateURL(profile_); + const TemplateURL* template_url = match->GetTemplateURL(profile_, false); if (!template_url || !match->search_terms_args.get()) continue; match->search_terms_args->assisted_query_stats = @@ -434,7 +434,7 @@ void AutocompleteController::UpdateKeywordDescriptions( i->description_class.clear(); DCHECK(!i->keyword.empty()); if (i->keyword != last_keyword) { - const TemplateURL* template_url = i->GetTemplateURL(profile_); + const TemplateURL* template_url = i->GetTemplateURL(profile_, false); if (template_url) { i->description = l10n_util::GetStringFUTF16( IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION, diff --git a/chrome/browser/autocomplete/autocomplete_match.cc b/chrome/browser/autocomplete/autocomplete_match.cc index f64d4bb..e3b9d13 100644 --- a/chrome/browser/autocomplete/autocomplete_match.cc +++ b/chrome/browser/autocomplete/autocomplete_match.cc @@ -358,11 +358,27 @@ bool AutocompleteMatch::IsSearchType(Type type) { type == SEARCH_OTHER_ENGINE; } -void AutocompleteMatch::ComputeStrippedDestinationURL() { +void AutocompleteMatch::ComputeStrippedDestinationURL(Profile* profile) { stripped_destination_url = destination_url; if (!stripped_destination_url.is_valid()) return; + // If the destination URL looks like it was generated from a TemplateURL, + // remove all substitutions other than the search terms. This allows us + // to eliminate cases like past search URLs from history that differ only + // by some obscure query param from each other or from the search/keyword + // provider matches. + TemplateURL* template_url = GetTemplateURL(profile, true); + if (template_url != NULL && template_url->SupportsReplacement()) { + string16 search_terms; + if (template_url->ExtractSearchTermsFromURL(stripped_destination_url, + &search_terms)) { + stripped_destination_url = + GURL(template_url->url_ref().ReplaceSearchTerms( + TemplateURLRef::SearchTermsArgs(search_terms))); + } + } + // |replacements| keeps all the substitions we're going to make to // from {destination_url} to {stripped_destination_url}. |need_replacement| // is a helper variable that helps us keep track of whether we need @@ -373,7 +389,7 @@ void AutocompleteMatch::ComputeStrippedDestinationURL() { // Remove the www. prefix from the host. static const char prefix[] = "www."; static const size_t prefix_len = arraysize(prefix) - 1; - std::string host = destination_url.host(); + std::string host = stripped_destination_url.host(); if (host.compare(0, prefix_len, prefix) == 0) { host = host.substr(prefix_len); replacements.SetHostStr(host); @@ -389,7 +405,8 @@ void AutocompleteMatch::ComputeStrippedDestinationURL() { } if (needs_replacement) - stripped_destination_url = destination_url.ReplaceComponents(replacements); + stripped_destination_url = stripped_destination_url.ReplaceComponents( + replacements); } void AutocompleteMatch::GetKeywordUIState(Profile* profile, @@ -404,15 +421,24 @@ string16 AutocompleteMatch::GetSubstitutingExplicitlyInvokedKeyword( Profile* profile) const { if (transition != content::PAGE_TRANSITION_KEYWORD) return string16(); - const TemplateURL* t_url = GetTemplateURL(profile); + const TemplateURL* t_url = GetTemplateURL(profile, false); return (t_url && t_url->SupportsReplacement()) ? keyword : string16(); } -TemplateURL* AutocompleteMatch::GetTemplateURL(Profile* profile) const { +TemplateURL* AutocompleteMatch::GetTemplateURL( + Profile* profile, bool allow_fallback_to_destination_host) const { DCHECK(profile); - return keyword.empty() ? NULL : - TemplateURLServiceFactory::GetForProfile(profile)-> - GetTemplateURLForKeyword(keyword); + TemplateURLService* template_url_service = + TemplateURLServiceFactory::GetForProfile(profile); + if (template_url_service == NULL) + return NULL; + TemplateURL* template_url = keyword.empty() ? NULL : + template_url_service->GetTemplateURLForKeyword(keyword); + if (template_url == NULL && allow_fallback_to_destination_host) { + template_url = template_url_service->GetTemplateURLForHost( + destination_url.host()); + } + return template_url; } void AutocompleteMatch::RecordAdditionalInfo(const std::string& property, diff --git a/chrome/browser/autocomplete/autocomplete_match.h b/chrome/browser/autocomplete/autocomplete_match.h index a587df4..3e7c208 100644 --- a/chrome/browser/autocomplete/autocomplete_match.h +++ b/chrome/browser/autocomplete/autocomplete_match.h @@ -188,7 +188,11 @@ struct AutocompleteMatch { // remove likely duplicates; these URLs are not used as actual // destination URLs. This method is invoked internally by the // AutocompleteResult and does not normally need to be invoked. - void ComputeStrippedDestinationURL(); + // If |profile| is not NULL, it is used to get a template URL corresponding + // to this match. The template is used to strip off query args other than + // the search terms themselves that would otherwise prevent from proper + // deduping. + void ComputeStrippedDestinationURL(Profile* profile); // Gets data relevant to whether there should be any special keyword-related // UI shown for this match. If this match represents a selected keyword, i.e. @@ -217,7 +221,11 @@ struct AutocompleteMatch { // Returns the TemplateURL associated with this match. This may be NULL if // the match has no keyword OR if the keyword no longer corresponds to a valid // TemplateURL. See comments on |keyword| below. - TemplateURL* GetTemplateURL(Profile* profile) const; + // If |allow_fallback_to_destination_host| is true and the keyword does + // not map to a valid TemplateURL, we'll then check for a TemplateURL that + // corresponds to the destination_url's hostname. + TemplateURL* GetTemplateURL(Profile* profile, + bool allow_fallback_to_destination_host) const; // Adds optional information to the |additional_info| dictionary. void RecordAdditionalInfo(const std::string& property, diff --git a/chrome/browser/autocomplete/autocomplete_provider_unittest.cc b/chrome/browser/autocomplete/autocomplete_provider_unittest.cc index 67b2604..8dedc7b 100644 --- a/chrome/browser/autocomplete/autocomplete_provider_unittest.cc +++ b/chrome/browser/autocomplete/autocomplete_provider_unittest.cc @@ -137,7 +137,7 @@ void TestProvider::AddResultsWithSearchTermsArgs( new TemplateURLRef::SearchTermsArgs(search_terms_args)); if (!match_keyword_.empty()) { match.keyword = match_keyword_; - ASSERT_TRUE(match.GetTemplateURL(profile_) != NULL); + ASSERT_TRUE(match.GetTemplateURL(profile_, false) != NULL); } matches_.push_back(match); @@ -199,7 +199,7 @@ class AutocompleteProviderTest : public testing::Test, TestingProfile profile_; }; -void AutocompleteProviderTest:: RegisterTemplateURL( +void AutocompleteProviderTest::RegisterTemplateURL( const string16 keyword, const std::string& template_url) { TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( @@ -212,6 +212,7 @@ void AutocompleteProviderTest:: RegisterTemplateURL( TemplateURLServiceFactory::GetForProfile(&profile_); turl_model->Add(default_t_url); turl_model->SetDefaultSearchProvider(default_t_url); + turl_model->Load(); TemplateURLID default_provider_id = default_t_url->id(); ASSERT_NE(0, default_provider_id); } diff --git a/chrome/browser/autocomplete/autocomplete_result.cc b/chrome/browser/autocomplete/autocomplete_result.cc index 12256e27..3d01ce20 100644 --- a/chrome/browser/autocomplete/autocomplete_result.cc +++ b/chrome/browser/autocomplete/autocomplete_result.cc @@ -47,7 +47,8 @@ void AutocompleteResult::CopyFrom(const AutocompleteResult& rhs) { } void AutocompleteResult::CopyOldMatches(const AutocompleteInput& input, - const AutocompleteResult& old_matches) { + const AutocompleteResult& old_matches, + Profile* profile) { if (old_matches.empty()) return; @@ -82,7 +83,7 @@ void AutocompleteResult::CopyOldMatches(const AutocompleteInput& input, MergeMatchesByProvider(i->second, matches_per_provider[i->first]); } - SortAndCull(input); + SortAndCull(input, profile); } void AutocompleteResult::AppendMatches(const ACMatches& matches) { @@ -112,9 +113,10 @@ void AutocompleteResult::AddMatch(const AutocompleteMatch& match) { default_match_ = begin() + default_offset; } -void AutocompleteResult::SortAndCull(const AutocompleteInput& input) { +void AutocompleteResult::SortAndCull(const AutocompleteInput& input, + Profile* profile) { for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) - i->ComputeStrippedDestinationURL(); + i->ComputeStrippedDestinationURL(profile); // Remove duplicates. std::sort(matches_.begin(), matches_.end(), diff --git a/chrome/browser/autocomplete/autocomplete_result.h b/chrome/browser/autocomplete/autocomplete_result.h index 36b0aa9..6ae7e39 100644 --- a/chrome/browser/autocomplete/autocomplete_result.h +++ b/chrome/browser/autocomplete/autocomplete_result.h @@ -15,6 +15,7 @@ class AutocompleteInput; class AutocompleteProvider; +class Profile; // All matches from all providers for a particular query. This also tracks // what the default match should be if the user doesn't manually select another @@ -71,7 +72,8 @@ class AutocompleteResult { // Copies matches from |old_matches| to provide a consistant result set. See // comments in code for specifics. void CopyOldMatches(const AutocompleteInput& input, - const AutocompleteResult& old_matches); + const AutocompleteResult& old_matches, + Profile* profile); // Adds a single match. The match is inserted at the appropriate position // based on relevancy and display order. This is ONLY for use after @@ -84,7 +86,7 @@ class AutocompleteResult { // Removes duplicates, puts the list in sorted order and culls to leave only // the best kMaxMatches matches. Sets the default match to the best match // and updates the alternate nav URL. - void SortAndCull(const AutocompleteInput& input); + void SortAndCull(const AutocompleteInput& input, Profile* profile); // Returns true if at least one match was copied from the last result. bool HasCopiedMatches() const; diff --git a/chrome/browser/autocomplete/autocomplete_result_unittest.cc b/chrome/browser/autocomplete/autocomplete_result_unittest.cc index 73e9458..788f568 100644 --- a/chrome/browser/autocomplete/autocomplete_result_unittest.cc +++ b/chrome/browser/autocomplete/autocomplete_result_unittest.cc @@ -10,6 +10,10 @@ #include "chrome/browser/autocomplete/autocomplete_input.h" #include "chrome/browser/autocomplete/autocomplete_match.h" #include "chrome/browser/autocomplete/autocomplete_provider.h" +#include "chrome/browser/search_engines/template_url_prepopulate_data.h" +#include "chrome/browser/search_engines/template_url_service.h" +#include "chrome/browser/search_engines/template_url_service_test_util.h" +#include "chrome/test/base/testing_profile.h" #include "testing/gtest/include/gtest/gtest.h" class AutocompleteResultTest : public testing::Test { @@ -28,6 +32,19 @@ class AutocompleteResultTest : public testing::Test { AutocompleteResultTest() {} + virtual void SetUp() OVERRIDE { +#if defined(OS_ANDROID) + TemplateURLPrepopulateData::InitCountryCode( + std::string() /* unknown country code */); +#endif + test_util_.SetUp(); + test_util_.VerifyLoad(); + } + + virtual void TearDown() OVERRIDE { + test_util_.TearDown(); + } + // Configures |match| from |data|. static void PopulateAutocompleteMatch(const TestData& data, AutocompleteMatch* match); @@ -48,6 +65,9 @@ class AutocompleteResultTest : public testing::Test { const TestData* current, size_t current_size, const TestData* expected, size_t expected_size); + protected: + TemplateURLServiceTestUtil test_util_; + private: DISALLOW_COPY_AND_ASSIGN(AutocompleteResultTest); }; @@ -102,14 +122,14 @@ void AutocompleteResultTest::RunCopyOldMatchesTest( PopulateAutocompleteMatches(last, last_size, &last_matches); AutocompleteResult last_result; last_result.AppendMatches(last_matches); - last_result.SortAndCull(input); + last_result.SortAndCull(input, test_util_.profile()); ACMatches current_matches; PopulateAutocompleteMatches(current, current_size, ¤t_matches); AutocompleteResult current_result; current_result.AppendMatches(current_matches); - current_result.SortAndCull(input); - current_result.CopyOldMatches(input, last_result); + current_result.SortAndCull(input, test_util_.profile()); + current_result.CopyOldMatches(input, last_result, test_util_.profile()); AssertResultMatches(current_result, expected, expected_size); } @@ -131,7 +151,7 @@ TEST_F(AutocompleteResultTest, Swap) { AutocompleteInput::ALL_MATCHES); matches.push_back(match); r1.AppendMatches(matches); - r1.SortAndCull(input); + r1.SortAndCull(input, test_util_.profile()); EXPECT_EQ(r1.begin(), r1.default_match()); EXPECT_EQ("http://a/", r1.alternate_nav_url().spec()); r1.Swap(&r2); @@ -210,7 +230,7 @@ TEST_F(AutocompleteResultTest, SortAndCullEmptyDestinationURLs) { result.AppendMatches(matches); AutocompleteInput input(string16(), string16(), false, false, false, AutocompleteInput::ALL_MATCHES); - result.SortAndCull(input); + result.SortAndCull(input, test_util_.profile()); // Of the two results with the same non-empty destination URL, the // lower-relevance one should be dropped. All of the results with empty URLs @@ -225,3 +245,46 @@ TEST_F(AutocompleteResultTest, SortAndCullEmptyDestinationURLs) { EXPECT_EQ("http://b/", result.match_at(3)->destination_url.spec()); EXPECT_EQ(1000, result.match_at(3)->relevance); } + +TEST_F(AutocompleteResultTest, SortAndCullDuplicateSearchURLs) { + // Register a template URL that corresponds to 'foo' search engine. + TemplateURLData url_data; + url_data.short_name = ASCIIToUTF16("unittest"); + url_data.SetKeyword(ASCIIToUTF16("foo")); + url_data.SetURL("http://www.foo.com/s?q={searchTerms}"); + test_util_.model()->Add(new TemplateURL(test_util_.profile(), url_data)); + + TestData data[] = { + { 0, 0, 1300 }, + { 1, 0, 1200 }, + { 2, 0, 1100 }, + { 3, 0, 1000 }, + { 4, 1, 900 }, + }; + + ACMatches matches; + PopulateAutocompleteMatches(data, arraysize(data), &matches); + matches[0].destination_url = GURL("http://www.foo.com/s?q=foo"); + matches[1].destination_url = GURL("http://www.foo.com/s?q=foo2"); + matches[2].destination_url = GURL("http://www.foo.com/s?q=foo&oq=f"); + matches[3].destination_url = GURL("http://www.foo.com/s?q=foo&aqs=0"); + matches[4].destination_url = GURL("http://www.foo.com/"); + + AutocompleteResult result; + result.AppendMatches(matches); + AutocompleteInput input(string16(), string16(), false, false, false, + AutocompleteInput::ALL_MATCHES); + result.SortAndCull(input, test_util_.profile()); + + // We expect the 3rd and 4th results to be removed. + ASSERT_EQ(3U, result.size()); + EXPECT_EQ("http://www.foo.com/s?q=foo", + result.match_at(0)->destination_url.spec()); + EXPECT_EQ(1300, result.match_at(0)->relevance); + EXPECT_EQ("http://www.foo.com/s?q=foo2", + result.match_at(1)->destination_url.spec()); + EXPECT_EQ(1200, result.match_at(1)->relevance); + EXPECT_EQ("http://www.foo.com/", + result.match_at(2)->destination_url.spec()); + EXPECT_EQ(900, result.match_at(2)->relevance); +} diff --git a/chrome/browser/autocomplete/history_url_provider_unittest.cc b/chrome/browser/autocomplete/history_url_provider_unittest.cc index 19f391d..cfbe0d7 100644 --- a/chrome/browser/autocomplete/history_url_provider_unittest.cc +++ b/chrome/browser/autocomplete/history_url_provider_unittest.cc @@ -246,7 +246,7 @@ void HistoryURLProviderTest::RunTest(const string16 text, matches_ = autocomplete_->matches(); if (sort_matches_) { for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) - i->ComputeStrippedDestinationURL(); + i->ComputeStrippedDestinationURL(profile_.get()); std::sort(matches_.begin(), matches_.end(), &AutocompleteMatch::DestinationSortFunc); matches_.erase(std::unique(matches_.begin(), matches_.end(), diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc index f056c26..1f7078e 100644 --- a/chrome/browser/autocomplete/search_provider.cc +++ b/chrome/browser/autocomplete/search_provider.cc @@ -1099,7 +1099,7 @@ void SearchProvider::AddMatchToMap(const string16& query_string, // Bail out now if we don't actually have a valid provider. match.keyword = is_keyword ? providers_.keyword_provider() : providers_.default_provider(); - const TemplateURL* provider_url = match.GetTemplateURL(profile_); + const TemplateURL* provider_url = match.GetTemplateURL(profile_, false); if (provider_url == NULL) return; diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index 3d3279a..cd7686a 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -201,7 +201,8 @@ bool InstantController::Update(const AutocompleteMatch& match, // not valid, it's likely a URL; in EXTENDED mode, try using the default // search engine's TemplateURL instead. const GURL& tab_url = active_tab->web_contents()->GetURL(); - if (GetInstantURL(match.GetTemplateURL(profile), tab_url, &instant_url)) { + if (GetInstantURL(match.GetTemplateURL(profile, false), tab_url, + &instant_url)) { ResetLoader(instant_url, active_tab); } else if (mode_ != EXTENDED || !CreateDefaultLoader()) { Hide(); diff --git a/chrome/browser/popup_blocker_browsertest.cc b/chrome/browser/popup_blocker_browsertest.cc index 231f4ff..4dba5ef 100644 --- a/chrome/browser/popup_blocker_browsertest.cc +++ b/chrome/browser/popup_blocker_browsertest.cc @@ -12,6 +12,7 @@ #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/content_settings/tab_specific_content_settings.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" @@ -26,8 +27,8 @@ #include "chrome/common/chrome_switches.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" -#include "content/public/browser/web_contents.h" #include "content/public/browser/notification_service.h" +#include "content/public/browser/web_contents.h" #include "content/public/common/url_constants.h" #include "content/public/test/browser_test_utils.h" #include "testing/gtest/include/gtest/gtest.h" @@ -161,6 +162,9 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ASSERT_EQ(GURL(search_string), history_urls[0]); ASSERT_EQ(url, history_urls[1]); + TemplateURLService* service = TemplateURLServiceFactory::GetForProfile( + browser()->profile()); + ui_test_utils::WaitForTemplateURLServiceToLoad(service); LocationBar* location_bar = browser()->window()->GetLocationBar(); ui_test_utils::SendToOmniboxAndSubmit(location_bar, search_string); OmniboxEditModel* model = location_bar->GetLocationEntry()->model(); diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.cc b/chrome/browser/ui/omnibox/omnibox_edit_model.cc index 78dae8b..3bfcc22 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc +++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc @@ -527,7 +527,7 @@ void OmniboxEditModel::AcceptInput(WindowOpenDisposition disposition, match.transition = content::PAGE_TRANSITION_LINK; } - const TemplateURL* template_url = match.GetTemplateURL(profile_); + const TemplateURL* template_url = match.GetTemplateURL(profile_, false); if (template_url && template_url->url_ref().HasGoogleBaseURLs()) GoogleURLTracker::GoogleURLSearchCommitted(profile_); @@ -578,7 +578,7 @@ void OmniboxEditModel::OpenMatch(const AutocompleteMatch& match, HISTOGRAM_ENUMERATION("Omnibox.EventCount", 1, 2); } - TemplateURL* template_url = match.GetTemplateURL(profile_); + TemplateURL* template_url = match.GetTemplateURL(profile_, false); if (template_url) { if (match.transition == content::PAGE_TRANSITION_KEYWORD) { // The user is using a non-substituting keyword or is explicitly in diff --git a/chrome/browser/ui/omnibox/omnibox_popup_model.cc b/chrome/browser/ui/omnibox/omnibox_popup_model.cc index 467a903..fd83429 100644 --- a/chrome/browser/ui/omnibox/omnibox_popup_model.cc +++ b/chrome/browser/ui/omnibox/omnibox_popup_model.cc @@ -196,7 +196,7 @@ void OmniboxPopupModel::TryDeletingCurrentItem() { gfx::Image OmniboxPopupModel::GetIconIfExtensionMatch( const AutocompleteMatch& match) const { Profile* profile = edit_model_->profile(); - const TemplateURL* template_url = match.GetTemplateURL(profile); + const TemplateURL* template_url = match.GetTemplateURL(profile, false); if (template_url && template_url->IsExtensionKeyword()) { return profile->GetExtensionService()->GetOmniboxPopupIcon( template_url->GetExtensionId()); |