| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/renderer_context_menu/spelling_options_submenu_observer
.h" | 5 #include "chrome/browser/renderer_context_menu/spelling_options_submenu_observer
.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 void TearDownOnMainThread() override { | 37 void TearDownOnMainThread() override { |
| 38 menu_->SetObserver(nullptr); | 38 menu_->SetObserver(nullptr); |
| 39 observer_.reset(); | 39 observer_.reset(); |
| 40 menu_.reset(); | 40 menu_.reset(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void InitMenu(bool enable_spellcheck, | 43 void InitMenu(bool enable_spellcheck, |
| 44 const std::string& accept_languages, | 44 const std::string& accept_languages, |
| 45 const std::vector<std::string>& dictionaries) { | 45 const std::vector<std::string>& dictionaries) { |
| 46 menu()->GetPrefs()->SetBoolean( | 46 menu()->GetPrefs()->SetBoolean( |
| 47 spellcheck::prefs::kEnableContinuousSpellcheck, enable_spellcheck); | 47 spellcheck::prefs::kEnableSpellcheck, enable_spellcheck); |
| 48 menu()->GetPrefs()->SetString(prefs::kAcceptLanguages, accept_languages); | 48 menu()->GetPrefs()->SetString(prefs::kAcceptLanguages, accept_languages); |
| 49 base::ListValue dictionaries_value; | 49 base::ListValue dictionaries_value; |
| 50 dictionaries_value.AppendStrings(dictionaries); | 50 dictionaries_value.AppendStrings(dictionaries); |
| 51 menu()->GetPrefs()->Set(spellcheck::prefs::kSpellCheckDictionaries, | 51 menu()->GetPrefs()->Set(spellcheck::prefs::kSpellCheckDictionaries, |
| 52 dictionaries_value); | 52 dictionaries_value); |
| 53 observer()->InitMenu(content::ContextMenuParams()); | 53 observer()->InitMenu(content::ContextMenuParams()); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void ExpectPreferences(bool spellcheck_enabled, | 56 void ExpectPreferences(bool spellcheck_enabled, |
| 57 const std::vector<std::string>& dictionaries) { | 57 const std::vector<std::string>& dictionaries) { |
| 58 EXPECT_EQ(spellcheck_enabled, | 58 EXPECT_EQ(spellcheck_enabled, |
| 59 menu()->GetPrefs()->GetBoolean( | 59 menu()->GetPrefs()->GetBoolean( |
| 60 spellcheck::prefs::kEnableContinuousSpellcheck)); | 60 spellcheck::prefs::kEnableSpellcheck)); |
| 61 base::ListValue dictionaries_value; | 61 base::ListValue dictionaries_value; |
| 62 dictionaries_value.AppendStrings(dictionaries); | 62 dictionaries_value.AppendStrings(dictionaries); |
| 63 EXPECT_TRUE(dictionaries_value.Equals(menu()->GetPrefs()->GetList( | 63 EXPECT_TRUE(dictionaries_value.Equals(menu()->GetPrefs()->GetList( |
| 64 spellcheck::prefs::kSpellCheckDictionaries))); | 64 spellcheck::prefs::kSpellCheckDictionaries))); |
| 65 } | 65 } |
| 66 | 66 |
| 67 MockRenderViewContextMenu* menu() { return menu_.get(); } | 67 MockRenderViewContextMenu* menu() { return menu_.get(); } |
| 68 SpellingOptionsSubMenuObserver* observer() { return observer_.get(); } | 68 SpellingOptionsSubMenuObserver* observer() { return observer_.get(); } |
| 69 | 69 |
| 70 private: | 70 private: |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 IN_PROC_BROWSER_TEST_F(SpellingOptionsSubMenuObserverTest, | 137 IN_PROC_BROWSER_TEST_F(SpellingOptionsSubMenuObserverTest, |
| 138 SelectTheOnlyLanguage) { | 138 SelectTheOnlyLanguage) { |
| 139 InitMenu(true, "en-US", std::vector<std::string>()); | 139 InitMenu(true, "en-US", std::vector<std::string>()); |
| 140 EXPECT_FALSE(menu()->IsCommandIdChecked(IDC_SPELLCHECK_LANGUAGES_FIRST)); | 140 EXPECT_FALSE(menu()->IsCommandIdChecked(IDC_SPELLCHECK_LANGUAGES_FIRST)); |
| 141 | 141 |
| 142 menu()->ExecuteCommand(IDC_SPELLCHECK_LANGUAGES_FIRST, 0); | 142 menu()->ExecuteCommand(IDC_SPELLCHECK_LANGUAGES_FIRST, 0); |
| 143 ExpectPreferences(true, std::vector<std::string>(1, "en-US")); | 143 ExpectPreferences(true, std::vector<std::string>(1, "en-US")); |
| 144 } | 144 } |
| 145 | 145 |
| 146 } // namespace | 146 } // namespace |
| OLD | NEW |