diff options
author | rlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-04 20:13:18 +0000 |
---|---|---|
committer | rlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-04 20:13:18 +0000 |
commit | 90bfb100cfdd2077dfd248b240c06d2374f66bcc (patch) | |
tree | 225db63342fa336c524b345dc4e05dd703c6d33a /chrome/browser/tab_contents | |
parent | e9c360128b5b74d10879c30d2f1ad9399c425613 (diff) | |
download | chromium_src-90bfb100cfdd2077dfd248b240c06d2374f66bcc.zip chromium_src-90bfb100cfdd2077dfd248b240c06d2374f66bcc.tar.gz chromium_src-90bfb100cfdd2077dfd248b240c06d2374f66bcc.tar.bz2 |
[Spellcheck] Removing the "no more suggestions from Google" line when using the spelling service
When using the spelling service, we should not show the "no more suggestions from Google" since that should intelligently figure out the correct suggestion.
BUG=119483
TEST=run using --use-spelling-service and observe that it shows only the single suggestion. run without that flag and observe that it will still show "no more suggestions from Google"
Review URL: https://chromiumcodereview.appspot.com/11635063
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175178 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
3 files changed, 64 insertions, 16 deletions
diff --git a/chrome/browser/tab_contents/spelling_menu_observer.cc b/chrome/browser/tab_contents/spelling_menu_observer.cc index 29ba61d..8e3b340 100644 --- a/chrome/browser/tab_contents/spelling_menu_observer.cc +++ b/chrome/browser/tab_contents/spelling_menu_observer.cc @@ -90,9 +90,10 @@ void SpellingMenuObserver::InitMenu(const content::ContextMenuParams& params) { // item now since Chrome will call IsCommandIdEnabled() and disable it.) loading_message_ = l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLING_CHECKING); - proxy_->AddMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, - loading_message_); - + if (!useSpellingService) { + proxy_->AddMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, + loading_message_); + } // Invoke a JSON-RPC call to the Spelling service in the background so we // can update the placeholder item when we receive its response. It also // starts the animation timer so we can show animation until we receive @@ -102,9 +103,9 @@ void SpellingMenuObserver::InitMenu(const content::ContextMenuParams& params) { type = SpellingServiceClient::SPELLCHECK; client_.reset(new SpellingServiceClient); bool result = client_->RequestTextCheck( - profile, 0, type, params.misspelled_word, + profile, type, params.misspelled_word, base::Bind(&SpellingMenuObserver::OnTextCheckComplete, - base::Unretained(this))); + base::Unretained(this), type)); if (result) { loading_frame_ = 0; animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), @@ -303,7 +304,7 @@ void SpellingMenuObserver::ExecuteCommand(int command_id) { } void SpellingMenuObserver::OnTextCheckComplete( - int tag, + SpellingServiceClient::ServiceType type, bool success, const string16& text, const std::vector<SpellCheckResult>& results) { @@ -331,15 +332,17 @@ void SpellingMenuObserver::OnTextCheckComplete( } } } - if (!succeeded_) { - result_ = l10n_util::GetStringUTF16( - IDS_CONTENT_CONTEXT_SPELLING_NO_SUGGESTIONS_FROM_GOOGLE); - } + if (type != SpellingServiceClient::SPELLCHECK) { + if (!succeeded_) { + result_ = l10n_util::GetStringUTF16( + IDS_CONTENT_CONTEXT_SPELLING_NO_SUGGESTIONS_FROM_GOOGLE); + } - // Update the menu item with the result text. We disable this item and hide it - // when the spelling service does not provide valid suggestions. - proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, succeeded_, - false, result_); + // Update the menu item with the result text. We disable this item and hide + // it when the spelling service does not provide valid suggestions. + proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, succeeded_, + false, result_); + } } void SpellingMenuObserver::OnAnimationTimerExpired() { diff --git a/chrome/browser/tab_contents/spelling_menu_observer.h b/chrome/browser/tab_contents/spelling_menu_observer.h index 53af3b5..e78d9d3 100644 --- a/chrome/browser/tab_contents/spelling_menu_observer.h +++ b/chrome/browser/tab_contents/spelling_menu_observer.h @@ -12,11 +12,11 @@ #include "base/prefs/public/pref_member.h" #include "base/string16.h" #include "base/timer.h" +#include "chrome/browser/spellchecker/spelling_service_client.h" #include "chrome/browser/tab_contents/render_view_context_menu_observer.h" class RenderViewContextMenuProxy; struct SpellCheckResult; -class SpellingServiceClient; // An observer that listens to events from the RenderViewContextMenu class and // shows suggestions from the Spelling ("do you mean") service to a context menu @@ -52,7 +52,7 @@ class SpellingMenuObserver : public RenderViewContextMenuObserver { // A callback function called when the Spelling service finishes checking a // misspelled word. void OnTextCheckComplete( - int tag, + SpellingServiceClient::ServiceType type, bool success, const string16& text, const std::vector<SpellCheckResult>& results); diff --git a/chrome/browser/tab_contents/spelling_menu_observer_browsertest.cc b/chrome/browser/tab_contents/spelling_menu_observer_browsertest.cc index e48bad9..2d8c5e7 100644 --- a/chrome/browser/tab_contents/spelling_menu_observer_browsertest.cc +++ b/chrome/browser/tab_contents/spelling_menu_observer_browsertest.cc @@ -6,12 +6,14 @@ #include <vector> +#include "base/command_line.h" #include "base/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/spellchecker/spelling_service_client.h" #include "chrome/browser/tab_contents/render_view_context_menu.h" #include "chrome/browser/tab_contents/render_view_context_menu_observer.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/testing_profile.h" @@ -360,3 +362,46 @@ IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, SeparatorAfterSuggestions) { EXPECT_FALSE(item.enabled); EXPECT_FALSE(item.hidden); } + +// Test that we don't show "No more suggestions from Google" if the spelling +// service is enabled and that there is only one suggestion. +IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, + NoMoreSuggestionsNotDisplayed) { + scoped_ptr<MockRenderViewContextMenu> menu(new MockRenderViewContextMenu); + scoped_ptr<SpellingMenuObserver> observer( + new SpellingMenuObserver(menu.get())); + menu->SetObserver(observer.get()); + menu->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, true); + CommandLine* command_line = CommandLine::ForCurrentProcess(); + command_line->AppendSwitch(switches::kUseSpellingService); + + // Make sure we can pretend to handle the JSON request. + menu->CreateRequestContext(); + + // Force a non-empty locale so SPELLCHECK is available. + menu->GetPrefs()->SetString(prefs::kSpellCheckDictionary, "en"); + EXPECT_TRUE(SpellingServiceClient::IsAvailable(menu->GetProfile(), + SpellingServiceClient::SPELLCHECK)); + + content::ContextMenuParams params; + params.is_editable = true; + params.misspelled_word = ASCIIToUTF16("asdfkj"); + params.dictionary_suggestions.push_back(ASCIIToUTF16("asdf")); + observer->InitMenu(params); + + // The test should see a suggestion (from SpellingService) and a separator + // as the first two items, then possibly more (not relevant here). + EXPECT_LT(2U, menu->GetMenuSize()); + + MockRenderViewContextMenu::MockMenuItem item; + menu->GetMenuItem(0, &item); + EXPECT_EQ(IDC_SPELLCHECK_SUGGESTION_0, item.command_id); + EXPECT_TRUE(item.enabled); + EXPECT_FALSE(item.hidden); + + menu->GetMenuItem(1, &item); + EXPECT_NE(IDC_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS, item.command_id); + EXPECT_EQ(-1, item.command_id); + EXPECT_FALSE(item.enabled); + EXPECT_FALSE(item.hidden); +} |