diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-15 14:51:55 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-15 14:51:55 +0000 |
commit | 33b8b8e68843131c6f81c47a0d0c0c616a01b355 (patch) | |
tree | 37a3722b10fa9cfdaa5cb24eaa124f1943446fbf /chrome/browser/instant | |
parent | 5976255eccb8c585c4e5ed0fefe4144d62bd1f74 (diff) | |
download | chromium_src-33b8b8e68843131c6f81c47a0d0c0c616a01b355.zip chromium_src-33b8b8e68843131c6f81c47a0d0c0c616a01b355.tar.gz chromium_src-33b8b8e68843131c6f81c47a0d0c0c616a01b355.tar.bz2 |
Wires up ability for page to specify instant auto complete
behavior. The choices are:
. immediately (current behavior and is the default).
. delayed (transitions to autocompleted after a delay).
. never (only show the suggestion, but never autocomplete it).
I'm doing this so we can collect some data to help understand which is
the less error prone of the 3. The data collection is all done on the
server side.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6685002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78211 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/instant')
-rw-r--r-- | chrome/browser/instant/instant_browsertest.cc | 35 | ||||
-rw-r--r-- | chrome/browser/instant/instant_controller.cc | 8 | ||||
-rw-r--r-- | chrome/browser/instant/instant_controller.h | 4 | ||||
-rw-r--r-- | chrome/browser/instant/instant_delegate.h | 4 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader.cc | 31 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader.h | 4 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader_delegate.h | 7 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader_manager_unittest.cc | 17 |
8 files changed, 83 insertions, 27 deletions
diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc index c175eb6..1ecce31 100644 --- a/chrome/browser/instant/instant_browsertest.cc +++ b/chrome/browser/instant/instant_browsertest.cc @@ -5,6 +5,7 @@ #include "base/command_line.h" #include "base/stringprintf.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/autocomplete/autocomplete_edit.h" #include "chrome/browser/autocomplete/autocomplete_edit_view.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_window.h" @@ -690,3 +691,37 @@ IN_PROC_BROWSER_TEST_F(InstantTest, ShowAboutCrash) { // If we get here it means the preview was shown. If we time out, it means the // preview was never shown. } + +IN_PROC_BROWSER_TEST_F(InstantTest, InstantCompleteNever) { + ASSERT_TRUE(test_server()->Start()); + EnableInstant(); + ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); + ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); + ASSERT_NO_FATAL_FAILURE(SetupPreview()); + + SetSuggestionsJavascriptArgument( + preview_, + "{suggestions:[{value:'defghij'}],complete_behavior:'never'}"); + ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def")); + EXPECT_STR_EQ("defghij", GetSuggestion()); + AutocompleteEditModel* edit_model = location_bar_->location_entry()->model(); + EXPECT_EQ(INSTANT_COMPLETE_NEVER, edit_model->instant_complete_behavior()); + ASSERT_EQ(ASCIIToUTF16("def"), location_bar_->location_entry()->GetText()); +} + +IN_PROC_BROWSER_TEST_F(InstantTest, InstantCompleteDelayed) { + ASSERT_TRUE(test_server()->Start()); + EnableInstant(); + ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); + ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); + ASSERT_NO_FATAL_FAILURE(SetupPreview()); + + SetSuggestionsJavascriptArgument( + preview_, + "{suggestions:[{value:'defghij'}],complete_behavior:'delayed'}"); + ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def")); + EXPECT_STR_EQ("defghij", GetSuggestion()); + AutocompleteEditModel* edit_model = location_bar_->location_entry()->model(); + EXPECT_EQ(INSTANT_COMPLETE_DELAYED, edit_model->instant_complete_behavior()); + ASSERT_EQ(ASCIIToUTF16("def"), location_bar_->location_entry()->GetText()); +} diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index c556dff..50f833b 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -388,10 +388,12 @@ void InstantController::ShowInstantLoader(InstantLoader* loader) { NotificationService::NoDetails()); } -void InstantController::SetSuggestedTextFor(InstantLoader* loader, - const string16& text) { +void InstantController::SetSuggestedTextFor( + InstantLoader* loader, + const string16& text, + InstantCompleteBehavior behavior) { if (loader_manager_->current_loader() == loader) - delegate_->SetSuggestedText(text); + delegate_->SetSuggestedText(text, behavior); } gfx::Rect InstantController::GetInstantBounds() { diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h index bc535f8..6e1d619 100644 --- a/chrome/browser/instant/instant_controller.h +++ b/chrome/browser/instant/instant_controller.h @@ -18,6 +18,7 @@ #include "chrome/browser/instant/instant_commit_type.h" #include "chrome/browser/instant/instant_loader_delegate.h" #include "chrome/browser/search_engines/template_url_id.h" +#include "chrome/common/instant_types.h" #include "chrome/common/page_transition_types.h" #include "googleurl/src/gurl.h" #include "ui/gfx/native_widget_types.h" @@ -174,7 +175,8 @@ class InstantController : public InstantLoaderDelegate { // InstantLoaderDelegate virtual void ShowInstantLoader(InstantLoader* loader) OVERRIDE; virtual void SetSuggestedTextFor(InstantLoader* loader, - const string16& text) OVERRIDE; + const string16& text, + InstantCompleteBehavior behavior) OVERRIDE; virtual gfx::Rect GetInstantBounds() OVERRIDE; virtual bool ShouldCommitInstantOnMouseUp() OVERRIDE; virtual void CommitInstantLoader(InstantLoader* loader) OVERRIDE; diff --git a/chrome/browser/instant/instant_delegate.h b/chrome/browser/instant/instant_delegate.h index a908981..b459d61 100644 --- a/chrome/browser/instant/instant_delegate.h +++ b/chrome/browser/instant/instant_delegate.h @@ -7,6 +7,7 @@ #pragma once #include "base/string16.h" +#include "chrome/common/instant_types.h" class TabContentsWrapper; @@ -37,7 +38,8 @@ class InstantDelegate { virtual void CommitInstant(TabContentsWrapper* preview_contents) = 0; // Invoked when the suggested text is to change to |text|. - virtual void SetSuggestedText(const string16& text) = 0; + virtual void SetSuggestedText(const string16& text, + InstantCompleteBehavior behavior) = 0; // Returns the bounds instant will be placed at in screen coordinates. virtual gfx::Rect GetInstantBounds() = 0; diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc index 7a058a5..a22e1c4 100644 --- a/chrome/browser/instant/instant_loader.cc +++ b/chrome/browser/instant/instant_loader.cc @@ -530,11 +530,10 @@ void InstantLoader::TabContentsDelegateImpl::OnSetSuggestions( page_id != source->controller().GetActiveEntry()->page_id()) return; - // TODO: pass in behavior to SetCompleteSuggestedText. if (suggestions.empty()) - loader_->SetCompleteSuggestedText(string16()); + loader_->SetCompleteSuggestedText(string16(), behavior); else - loader_->SetCompleteSuggestedText(UTF8ToUTF16(suggestions[0])); + loader_->SetCompleteSuggestedText(UTF8ToUTF16(suggestions[0]), behavior); } void InstantLoader::TabContentsDelegateImpl::OnInstantSupportDetermined( @@ -779,7 +778,8 @@ void InstantLoader::CommitInstantLoader() { } void InstantLoader::SetCompleteSuggestedText( - const string16& complete_suggested_text) { + const string16& complete_suggested_text, + InstantCompleteBehavior behavior) { if (!is_showing_instant()) { // We're not trying to use the instant API with this page. Ignore it. return; @@ -804,18 +804,25 @@ void InstantLoader::SetCompleteSuggestedText( 0, user_text_lower.size())) { // The user text no longer contains the suggested text, ignore it. complete_suggested_text_.clear(); - delegate_->SetSuggestedTextFor(this, string16()); + delegate_->SetSuggestedTextFor(this, string16(), behavior); return; } complete_suggested_text_ = complete_suggested_text; - // We are effectively showing complete_suggested_text_ now. Update user_text_ - // so we don't notify the page again if Update happens to be invoked (which is - // more than likely if this callback completes before the omnibox is done). - string16 suggestion = complete_suggested_text_.substr(user_text_.size()); - user_text_ = complete_suggested_text_; - last_suggestion_.clear(); - delegate_->SetSuggestedTextFor(this, suggestion); + if (behavior == INSTANT_COMPLETE_NOW) { + // We are effectively showing complete_suggested_text_ now. Update + // user_text_ so we don't notify the page again if Update happens to be + // invoked (which is more than likely if this callback completes before the + // omnibox is done). + string16 suggestion = complete_suggested_text_.substr(user_text_.size()); + user_text_ = complete_suggested_text_; + delegate_->SetSuggestedTextFor(this, suggestion, behavior); + } else { + DCHECK((behavior == INSTANT_COMPLETE_DELAYED) || + (behavior == INSTANT_COMPLETE_NEVER)); + last_suggestion_ = complete_suggested_text_.substr(user_text_.size()); + delegate_->SetSuggestedTextFor(this, last_suggestion_, behavior); + } } void InstantLoader::PreviewPainted() { diff --git a/chrome/browser/instant/instant_loader.h b/chrome/browser/instant/instant_loader.h index aaae7bf..f18d454 100644 --- a/chrome/browser/instant/instant_loader.h +++ b/chrome/browser/instant/instant_loader.h @@ -12,6 +12,7 @@ #include "base/timer.h" #include "chrome/browser/instant/instant_commit_type.h" #include "chrome/browser/search_engines/template_url_id.h" +#include "chrome/common/instant_types.h" #include "chrome/common/page_transition_types.h" #include "content/common/notification_observer.h" #include "content/common/notification_registrar.h" @@ -103,7 +104,8 @@ class InstantLoader : public NotificationObserver { // Invoked when the page wants to update the suggested text. If |user_text_| // starts with |suggested_text|, then the delegate is notified of the change, // which results in updating the omnibox. - void SetCompleteSuggestedText(const string16& suggested_text); + void SetCompleteSuggestedText(const string16& suggested_text, + InstantCompleteBehavior behavior); // Invoked when the page paints. void PreviewPainted(); diff --git a/chrome/browser/instant/instant_loader_delegate.h b/chrome/browser/instant/instant_loader_delegate.h index bfe1518..6e3232a 100644 --- a/chrome/browser/instant/instant_loader_delegate.h +++ b/chrome/browser/instant/instant_loader_delegate.h @@ -7,6 +7,7 @@ #pragma once #include "base/string16.h" +#include "chrome/common/instant_types.h" class GURL; @@ -23,8 +24,10 @@ class InstantLoaderDelegate { virtual void ShowInstantLoader(InstantLoader* loader) = 0; // Invoked when the loader has suggested text. - virtual void SetSuggestedTextFor(InstantLoader* loader, - const string16& text) = 0; + virtual void SetSuggestedTextFor( + InstantLoader* loader, + const string16& text, + InstantCompleteBehavior behavior) = 0; // Returns the bounds of instant. virtual gfx::Rect GetInstantBounds() = 0; diff --git a/chrome/browser/instant/instant_loader_manager_unittest.cc b/chrome/browser/instant/instant_loader_manager_unittest.cc index 98af6da..ec3e2a2 100644 --- a/chrome/browser/instant/instant_loader_manager_unittest.cc +++ b/chrome/browser/instant/instant_loader_manager_unittest.cc @@ -14,26 +14,29 @@ class InstantLoaderDelegateImpl : public InstantLoaderDelegate { public: InstantLoaderDelegateImpl() {} - virtual void ShowInstantLoader(InstantLoader* loader) {} + virtual void ShowInstantLoader(InstantLoader* loader) OVERRIDE {} virtual void SetSuggestedTextFor(InstantLoader* loader, - const string16& text) {} + const string16& text, + InstantCompleteBehavior behavior) OVERRIDE {} - virtual gfx::Rect GetInstantBounds() { + virtual gfx::Rect GetInstantBounds() OVERRIDE { return gfx::Rect(); } - virtual bool ShouldCommitInstantOnMouseUp() { + virtual bool ShouldCommitInstantOnMouseUp() OVERRIDE { return false; } - virtual void CommitInstantLoader(InstantLoader* loader) { + virtual void CommitInstantLoader(InstantLoader* loader) OVERRIDE { } - virtual void InstantLoaderDoesntSupportInstant(InstantLoader* loader) { + virtual void InstantLoaderDoesntSupportInstant( + InstantLoader* loader) OVERRIDE { } - virtual void AddToBlacklist(InstantLoader* loader, const GURL& url) { + virtual void AddToBlacklist(InstantLoader* loader, + const GURL& url) OVERRIDE { } private: |