diff options
author | rlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-26 02:09:36 +0000 |
---|---|---|
committer | rlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-26 02:09:36 +0000 |
commit | 2211d40ceadceb25f57324751007eeedffe68d0d (patch) | |
tree | 0e52dd18c095e6194a7d90b74c271d2832d587a2 /chrome/browser/tab_contents | |
parent | 2f01ea3e9245ac28d7cd706abb31b63c917ecc36 (diff) | |
download | chromium_src-2211d40ceadceb25f57324751007eeedffe68d0d.zip chromium_src-2211d40ceadceb25f57324751007eeedffe68d0d.tar.gz chromium_src-2211d40ceadceb25f57324751007eeedffe68d0d.tar.bz2 |
[Spellcheck] Turning off server spellcheck for off the record profiles.
BUG=171016
Review URL: https://chromiumcodereview.appspot.com/12052046
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178993 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
3 files changed, 65 insertions, 6 deletions
diff --git a/chrome/browser/tab_contents/spellchecker_submenu_observer_hunspell.cc b/chrome/browser/tab_contents/spellchecker_submenu_observer_hunspell.cc index 27f04d2..7a59632 100644 --- a/chrome/browser/tab_contents/spellchecker_submenu_observer_hunspell.cc +++ b/chrome/browser/tab_contents/spellchecker_submenu_observer_hunspell.cc @@ -104,7 +104,6 @@ bool SpellCheckerSubMenuObserver::IsCommandIdSupported(int command_id) { case IDC_CHECK_SPELLING_WHILE_TYPING: case IDC_SPELLPANEL_TOGGLE: case IDC_SPELLCHECK_MENU: - case IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE: return true; } @@ -144,7 +143,6 @@ bool SpellCheckerSubMenuObserver::IsCommandIdEnabled(int command_id) { case IDC_CHECK_SPELLING_WHILE_TYPING: case IDC_SPELLPANEL_TOGGLE: case IDC_SPELLCHECK_MENU: - case IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE: return true; } diff --git a/chrome/browser/tab_contents/spelling_menu_observer.cc b/chrome/browser/tab_contents/spelling_menu_observer.cc index 8e3b340..229c373 100644 --- a/chrome/browser/tab_contents/spelling_menu_observer.cc +++ b/chrome/browser/tab_contents/spelling_menu_observer.cc @@ -172,9 +172,11 @@ bool SpellingMenuObserver::IsCommandIdChecked(int command_id) { DCHECK(IsCommandIdSupported(command_id)); if (command_id == IDC_CONTENT_CONTEXT_SPELLING_TOGGLE) - return integrate_spelling_service_.GetValue(); + return integrate_spelling_service_.GetValue() && + !proxy_->GetProfile()->IsOffTheRecord(); else if (command_id == IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE) - return autocorrect_spelling_.GetValue(); + return autocorrect_spelling_.GetValue() && + !proxy_->GetProfile()->IsOffTheRecord(); return false; } @@ -196,10 +198,12 @@ bool SpellingMenuObserver::IsCommandIdEnabled(int command_id) { return succeeded_; case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE: - return integrate_spelling_service_.IsUserModifiable(); + return integrate_spelling_service_.IsUserModifiable() && + !proxy_->GetProfile()->IsOffTheRecord(); case IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE: - return integrate_spelling_service_.IsUserModifiable(); + return integrate_spelling_service_.IsUserModifiable() && + !proxy_->GetProfile()->IsOffTheRecord(); default: return false; diff --git a/chrome/browser/tab_contents/spelling_menu_observer_browsertest.cc b/chrome/browser/tab_contents/spelling_menu_observer_browsertest.cc index c796928..79004fc 100644 --- a/chrome/browser/tab_contents/spelling_menu_observer_browsertest.cc +++ b/chrome/browser/tab_contents/spelling_menu_observer_browsertest.cc @@ -405,3 +405,60 @@ IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, EXPECT_FALSE(item.enabled); EXPECT_FALSE(item.hidden); } + +// Test that "Ask Google For Suggestions" is grayed out when using an +// off the record profile. +// TODO(rlp): Include graying out of autocorrect in this test when autocorrect +// is functional. +IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, + NoSpellingServiceWhenOffTheRecord) { + scoped_ptr<MockRenderViewContextMenu> menu(new MockRenderViewContextMenu); + menu->GetProfile()->AsTestingProfile()->set_incognito(true); + scoped_ptr<SpellingMenuObserver> observer( + new SpellingMenuObserver(menu.get())); + menu->SetObserver(observer.get()); + + // This means spellchecking is allowed. Default is that the service is + // contacted but this test makes sure that if profile is incognito, that + // is not an option. + menu->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, true); + + // Force a non-empty locale so SUGGEST normally would be available. + menu->GetPrefs()->SetString(prefs::kSpellCheckDictionary, "en"); + EXPECT_FALSE(SpellingServiceClient::IsAvailable(menu->GetProfile(), + SpellingServiceClient::SUGGEST)); + EXPECT_FALSE(SpellingServiceClient::IsAvailable(menu->GetProfile(), + SpellingServiceClient::SPELLCHECK)); + + content::ContextMenuParams params; + params.is_editable = true; + params.misspelled_word = ASCIIToUTF16("sjxdjiiiiii"); + observer->InitMenu(params); + + // The test should see "No spelling suggestions" (from system checker). + // They should not see "No more Google suggestions" (from SpellingService) or + // a separator. The next 2 items should be "Add to Dictionary" followed + // by "Ask Google for suggestions" which should be disabled. + // TODO(rlp): add autocorrect here when it is functional. + EXPECT_LT(3U, menu->GetMenuSize()); + + MockRenderViewContextMenu::MockMenuItem item; + menu->GetMenuItem(0, &item); + EXPECT_EQ(IDC_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS, item.command_id); + EXPECT_FALSE(item.enabled); + EXPECT_FALSE(item.hidden); + + menu->GetMenuItem(1, &item); + EXPECT_EQ(IDC_SPELLCHECK_ADD_TO_DICTIONARY, item.command_id); + EXPECT_TRUE(item.enabled); + EXPECT_FALSE(item.hidden); + + menu->GetMenuItem(2, &item); + EXPECT_EQ(IDC_CONTENT_CONTEXT_SPELLING_TOGGLE, item.command_id); + EXPECT_FALSE(item.enabled); + EXPECT_FALSE(item.hidden); + + // Set incognito back to false to allow appropriate test cleanup. + menu->GetProfile()->AsTestingProfile()->set_incognito(false); +} + |