diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-15 23:18:45 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-15 23:18:45 +0000 |
commit | 57a285f81ba56ce409afc3e0b2a074d096c1d3e0 (patch) | |
tree | 7400de360dc1466533b17cd8d053e22396b25318 /chrome/browser/instant | |
parent | 0ade4abb90cc4daf5cba9b355ea1b7944aab077b (diff) | |
download | chromium_src-57a285f81ba56ce409afc3e0b2a074d096c1d3e0.zip chromium_src-57a285f81ba56ce409afc3e0b2a074d096c1d3e0.tar.gz chromium_src-57a285f81ba56ce409afc3e0b2a074d096c1d3e0.tar.bz2 |
Makes instant not suggest string that look like urls.
BUG=66887
TEST=see bug
Review URL: http://codereview.chromium.org/5787008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69343 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/instant')
-rw-r--r-- | chrome/browser/instant/instant_browsertest.cc | 28 | ||||
-rw-r--r-- | chrome/browser/instant/instant_controller.cc | 5 | ||||
-rw-r--r-- | chrome/browser/instant/instant_controller.h | 4 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader.cc | 10 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader.h | 5 |
5 files changed, 52 insertions, 0 deletions
diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc index 8fb61f8..45867c4 100644 --- a/chrome/browser/instant/instant_browsertest.cc +++ b/chrome/browser/instant/instant_browsertest.cc @@ -468,3 +468,31 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnCancelEvent) { EXPECT_NO_FATAL_FAILURE(CheckIntValueFromJavascript( 1, "window.oncancelcalls", contents)); } + +// Verify that suggestion that looks like a url ('www.google.com' in this case) +// is not shown. +IN_PROC_BROWSER_TEST_F(InstantTest, DontShowURLSuggest) { + ASSERT_TRUE(test_server()->Start()); + ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("suggest_google.html")); + ASSERT_NO_FATAL_FAILURE(FindLocationBar()); + location_bar_->location_entry()->SetUserText(L"w"); + InstantController* instant = browser()->instant(); + ASSERT_TRUE(instant); + ASSERT_TRUE(instant->IsShowingInstant()); + ASSERT_TRUE(instant->GetPreviewContents()); + ui_test_utils::WaitForNavigation( + &(instant->GetPreviewContents()->controller())); + ASSERT_NO_FATAL_FAILURE(WaitForMessageToBeProcessedByRenderer( + instant->GetPreviewContents())); + // TODO: remove this second change when 66104 is fixed. + location_bar_->location_entry()->SetUserText(L"ww"); + ASSERT_NO_FATAL_FAILURE(WaitForMessageToBeProcessedByRenderer( + instant->GetPreviewContents())); + ASSERT_TRUE(instant->is_displayable()); + + location_bar_->location_entry()->SetUserText(L"www"); + ASSERT_NO_FATAL_FAILURE(WaitForMessageToBeProcessedByRenderer( + instant->GetPreviewContents())); + ASSERT_EQ(UTF16ToWide(string16()), + UTF16ToWide(instant->GetCompleteSuggestedText())); +} diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index 4e02f28..78e95b0 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -337,6 +337,11 @@ bool InstantController::IsShowingInstant() { loader_manager_->current_loader()->is_showing_instant(); } +string16 InstantController::GetCompleteSuggestedText() { + return loader_manager_.get() && loader_manager_->active_loader() ? + loader_manager_->active_loader()->complete_suggested_text() : string16(); +} + bool InstantController::MightSupportInstant() { return loader_manager_.get() && loader_manager_->active_loader() && loader_manager_->active_loader()->is_showing_instant(); diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h index 1482481..66ced18 100644 --- a/chrome/browser/instant/instant_controller.h +++ b/chrome/browser/instant/instant_controller.h @@ -167,6 +167,10 @@ class InstantController : public InstantLoaderDelegate { return last_transition_type_; } + // Returns the current complete suggested text, or an empty string if there is + // no suggestion. + string16 GetCompleteSuggestedText(); + // Returns true if we're showing results from a provider that supports the // instant API. See description of |MightSupportInstant| for how this // differs from actual loading state. diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc index 2210677..46b5351 100644 --- a/chrome/browser/instant/instant_loader.cc +++ b/chrome/browser/instant/instant_loader.cc @@ -13,6 +13,7 @@ #include "base/timer.h" #include "base/utf_string_conversions.h" #include "base/values.h" +#include "chrome/browser/autocomplete/autocomplete.h" #include "chrome/browser/favicon_service.h" #include "chrome/browser/history/history_marshaling.h" #include "chrome/browser/instant/instant_loader_delegate.h" @@ -667,6 +668,15 @@ void InstantLoader::SetCompleteSuggestedText( return; } + AutocompleteInput::Type type = + AutocompleteInput::Parse(UTF16ToWide(complete_suggested_text), + std::wstring(), NULL, NULL); + if (type == AutocompleteInput::URL) { + // Ignore suggestions that look like urls. Otherwise the omnibox ends up + // showing what looks like a url but the page shows search results. + return; + } + string16 user_text_lower = l10n_util::ToLower(user_text_); string16 complete_suggested_text_lower = l10n_util::ToLower( complete_suggested_text); diff --git a/chrome/browser/instant/instant_loader.h b/chrome/browser/instant/instant_loader.h index 8be48af..070290b 100644 --- a/chrome/browser/instant/instant_loader.h +++ b/chrome/browser/instant/instant_loader.h @@ -92,6 +92,11 @@ class InstantLoader : public NotificationObserver { // See description above field. const string16& user_text() const { return user_text_; } + // See description above field. + const string16& complete_suggested_text() const { + return complete_suggested_text_; + } + private: friend class InstantLoaderManagerTest; class FrameLoadObserver; |