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" |
11 #include "chrome/browser/renderer_context_menu/mock_render_view_context_menu.h" | 11 #include "chrome/browser/renderer_context_menu/mock_render_view_context_menu.h" |
12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
13 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
14 #include "components/prefs/pref_service.h" | 14 #include "components/prefs/pref_service.h" |
| 15 #include "components/spellcheck/browser/pref_names.h" |
15 #include "content/public/common/context_menu_params.h" | 16 #include "content/public/common/context_menu_params.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 // A test class used in this file. This test should be a browser test because it | 21 // A test class used in this file. This test should be a browser test because it |
21 // accesses resources. | 22 // accesses resources. |
22 class SpellingOptionsSubMenuObserverTest : public InProcessBrowserTest { | 23 class SpellingOptionsSubMenuObserverTest : public InProcessBrowserTest { |
23 public: | 24 public: |
24 SpellingOptionsSubMenuObserverTest() {} | 25 SpellingOptionsSubMenuObserverTest() {} |
(...skipping 10 matching lines...) Expand all Loading... |
35 | 36 |
36 void TearDownOnMainThread() override { | 37 void TearDownOnMainThread() override { |
37 menu_->SetObserver(nullptr); | 38 menu_->SetObserver(nullptr); |
38 observer_.reset(); | 39 observer_.reset(); |
39 menu_.reset(); | 40 menu_.reset(); |
40 } | 41 } |
41 | 42 |
42 void InitMenu(bool enable_spellcheck, | 43 void InitMenu(bool enable_spellcheck, |
43 const std::string& accept_languages, | 44 const std::string& accept_languages, |
44 const std::vector<std::string>& dictionaries) { | 45 const std::vector<std::string>& dictionaries) { |
45 menu()->GetPrefs()->SetBoolean(prefs::kEnableContinuousSpellcheck, | 46 menu()->GetPrefs()->SetBoolean( |
46 enable_spellcheck); | 47 spellcheck::prefs::kEnableContinuousSpellcheck, enable_spellcheck); |
47 menu()->GetPrefs()->SetString(prefs::kAcceptLanguages, accept_languages); | 48 menu()->GetPrefs()->SetString(prefs::kAcceptLanguages, accept_languages); |
48 base::ListValue dictionaries_value; | 49 base::ListValue dictionaries_value; |
49 dictionaries_value.AppendStrings(dictionaries); | 50 dictionaries_value.AppendStrings(dictionaries); |
50 menu()->GetPrefs()->Set(prefs::kSpellCheckDictionaries, dictionaries_value); | 51 menu()->GetPrefs()->Set(spellcheck::prefs::kSpellCheckDictionaries, |
| 52 dictionaries_value); |
51 observer()->InitMenu(content::ContextMenuParams()); | 53 observer()->InitMenu(content::ContextMenuParams()); |
52 } | 54 } |
53 | 55 |
54 void ExpectPreferences(bool spellcheck_enabled, | 56 void ExpectPreferences(bool spellcheck_enabled, |
55 const std::vector<std::string>& dictionaries) { | 57 const std::vector<std::string>& dictionaries) { |
56 EXPECT_EQ(spellcheck_enabled, menu()->GetPrefs()->GetBoolean( | 58 EXPECT_EQ(spellcheck_enabled, |
57 prefs::kEnableContinuousSpellcheck)); | 59 menu()->GetPrefs()->GetBoolean( |
| 60 spellcheck::prefs::kEnableContinuousSpellcheck)); |
58 base::ListValue dictionaries_value; | 61 base::ListValue dictionaries_value; |
59 dictionaries_value.AppendStrings(dictionaries); | 62 dictionaries_value.AppendStrings(dictionaries); |
60 EXPECT_TRUE(dictionaries_value.Equals( | 63 EXPECT_TRUE(dictionaries_value.Equals(menu()->GetPrefs()->GetList( |
61 menu()->GetPrefs()->GetList(prefs::kSpellCheckDictionaries))); | 64 spellcheck::prefs::kSpellCheckDictionaries))); |
62 } | 65 } |
63 | 66 |
64 MockRenderViewContextMenu* menu() { return menu_.get(); } | 67 MockRenderViewContextMenu* menu() { return menu_.get(); } |
65 SpellingOptionsSubMenuObserver* observer() { return observer_.get(); } | 68 SpellingOptionsSubMenuObserver* observer() { return observer_.get(); } |
66 | 69 |
67 private: | 70 private: |
68 std::unique_ptr<MockRenderViewContextMenu> menu_; | 71 std::unique_ptr<MockRenderViewContextMenu> menu_; |
69 std::unique_ptr<SpellingOptionsSubMenuObserver> observer_; | 72 std::unique_ptr<SpellingOptionsSubMenuObserver> observer_; |
70 | 73 |
71 DISALLOW_COPY_AND_ASSIGN(SpellingOptionsSubMenuObserverTest); | 74 DISALLOW_COPY_AND_ASSIGN(SpellingOptionsSubMenuObserverTest); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 IN_PROC_BROWSER_TEST_F(SpellingOptionsSubMenuObserverTest, | 137 IN_PROC_BROWSER_TEST_F(SpellingOptionsSubMenuObserverTest, |
135 SelectTheOnlyLanguage) { | 138 SelectTheOnlyLanguage) { |
136 InitMenu(true, "en-US", std::vector<std::string>()); | 139 InitMenu(true, "en-US", std::vector<std::string>()); |
137 EXPECT_FALSE(menu()->IsCommandIdChecked(IDC_SPELLCHECK_LANGUAGES_FIRST)); | 140 EXPECT_FALSE(menu()->IsCommandIdChecked(IDC_SPELLCHECK_LANGUAGES_FIRST)); |
138 | 141 |
139 menu()->ExecuteCommand(IDC_SPELLCHECK_LANGUAGES_FIRST, 0); | 142 menu()->ExecuteCommand(IDC_SPELLCHECK_LANGUAGES_FIRST, 0); |
140 ExpectPreferences(true, std::vector<std::string>(1, "en-US")); | 143 ExpectPreferences(true, std::vector<std::string>(1, "en-US")); |
141 } | 144 } |
142 | 145 |
143 } // namespace | 146 } // namespace |
OLD | NEW |