Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: chrome/browser/renderer_context_menu/spelling_options_submenu_observer_browsertest.cc

Issue 1647723002: [win/cros/lin] Add back the spellcheck menu. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing includes. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/renderer_context_menu/spelling_options_submenu_observer .h"
6
7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/renderer_context_menu/mock_render_view_context_menu.h"
11 #include "chrome/common/pref_names.h"
12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "content/public/common/context_menu_params.h"
14
15 namespace {
16
17 // A test class used in this file. This test should be a browser test because it
18 // accesses resources.
19 class SpellingOptionsSubMenuObserverTest : public InProcessBrowserTest {
20 public:
21 SpellingOptionsSubMenuObserverTest() {}
22 ~SpellingOptionsSubMenuObserverTest() override {}
23
24 void SetUpOnMainThread() override {
25 menu_.reset(new MockRenderViewContextMenu(false));
26 observer_.reset(
27 new SpellingOptionsSubMenuObserver(menu_.get(), menu_.get(), 1));
28 menu_->SetObserver(observer_.get());
29 }
30
31 void TearDownOnMainThread() override {
32 menu_->SetObserver(nullptr);
33 observer_.reset();
34 menu_.reset();
35 }
36
37 void InitMenu(bool enable_spellcheck,
38 const std::string& accept_languages,
39 const std::vector<std::string>& dictionaries) {
40 menu()->GetPrefs()->SetBoolean(prefs::kEnableContinuousSpellcheck,
41 enable_spellcheck);
42 menu()->GetPrefs()->SetString(prefs::kAcceptLanguages, accept_languages);
43 base::ListValue dictionaries_value;
44 dictionaries_value.AppendStrings(dictionaries);
45 menu()->GetPrefs()->Set(prefs::kSpellCheckDictionaries, dictionaries_value);
46 observer()->InitMenu(content::ContextMenuParams());
47 }
48
49 void ExpectPreferences(bool spellcheck_enabled,
50 const std::vector<std::string>& dictionaries) {
51 EXPECT_EQ(spellcheck_enabled, menu()->GetPrefs()->GetBoolean(
52 prefs::kEnableContinuousSpellcheck));
53 base::ListValue dictionaries_value;
54 for (const auto& dict : dictionaries) {
55 dictionaries_value.AppendString(dict);
lazyboy 2016/02/01 19:23:33 Could use AppendStrings here too.
please use gerrit instead 2016/02/01 20:20:57 Done.
56 }
57 EXPECT_TRUE(dictionaries_value.Equals(
58 menu()->GetPrefs()->GetList(prefs::kSpellCheckDictionaries)));
59 }
60
61 MockRenderViewContextMenu* menu() { return menu_.get(); }
62 SpellingOptionsSubMenuObserver* observer() { return observer_.get(); }
63
64 private:
65 scoped_ptr<MockRenderViewContextMenu> menu_;
66 scoped_ptr<SpellingOptionsSubMenuObserver> observer_;
67
68 DISALLOW_COPY_AND_ASSIGN(SpellingOptionsSubMenuObserverTest);
69 };
70
71 // Tests that selecting the "Check Spelling While Typing" item toggles the value
72 // of the "browser.enable_spellchecking" profile.
73 IN_PROC_BROWSER_TEST_F(SpellingOptionsSubMenuObserverTest, ToggleSpelling) {
74 InitMenu(true, "en-US", std::vector<std::string>(1, "en-US"));
75
76 // Verify this menu has the "Check Spelling While Typing" item and this item
77 // is checked.
78 EXPECT_TRUE(menu()->IsCommandIdEnabled(IDC_CHECK_SPELLING_WHILE_TYPING));
79 EXPECT_TRUE(menu()->IsCommandIdChecked(IDC_CHECK_SPELLING_WHILE_TYPING));
80
81 // Select this item and verify that the "Check Spelling While Typing" item is
82 // not checked. Also, verify that the value of "browser.enable_spellchecking"
83 // is now false.
84 menu()->ExecuteCommand(IDC_CHECK_SPELLING_WHILE_TYPING, 0);
85 ExpectPreferences(false, std::vector<std::string>(1, "en-US"));
86 EXPECT_FALSE(menu()->IsCommandIdChecked(IDC_CHECK_SPELLING_WHILE_TYPING));
87 }
88
89 // Single accept language is selected based on the dictionaries preference.
90 // Consequently selecting multilingual spellcheck should copy all accept
91 // languages into spellcheck dictionaries preference.
92 IN_PROC_BROWSER_TEST_F(SpellingOptionsSubMenuObserverTest, SelectMultilingual) {
93 InitMenu(true, "en-US,es", std::vector<std::string>(1, "en-US"));
94 EXPECT_FALSE(menu()->IsCommandIdChecked(IDC_SPELLCHECK_MULTI_LINGUAL));
95 EXPECT_TRUE(menu()->IsCommandIdChecked(IDC_SPELLCHECK_LANGUAGES_FIRST));
96 EXPECT_FALSE(menu()->IsCommandIdChecked(IDC_SPELLCHECK_LANGUAGES_FIRST + 1));
97
98 menu()->ExecuteCommand(IDC_SPELLCHECK_MULTI_LINGUAL, 0);
99 std::vector<std::string> dictionaries;
100 dictionaries.push_back("en-US");
101 dictionaries.push_back("es");
102 ExpectPreferences(true, dictionaries);
103 }
104
105 // Multilingual spellcheck is selected when all dictionaries are used for
106 // spellcheck. Consequently selecting "English (United States)" should set
107 // spellcheck dictionaries preferences to ["en-US"].
108 IN_PROC_BROWSER_TEST_F(SpellingOptionsSubMenuObserverTest,
109 SelectFirstLanguage) {
110 std::vector<std::string> dictionaries;
111 dictionaries.push_back("en-US");
112 dictionaries.push_back("es");
113 InitMenu(true, "en-US,es", dictionaries);
114 EXPECT_TRUE(menu()->IsCommandIdChecked(IDC_SPELLCHECK_MULTI_LINGUAL));
115 EXPECT_FALSE(menu()->IsCommandIdChecked(IDC_SPELLCHECK_LANGUAGES_FIRST));
116 EXPECT_FALSE(menu()->IsCommandIdChecked(IDC_SPELLCHECK_LANGUAGES_FIRST + 1));
117
118 menu()->ExecuteCommand(IDC_SPELLCHECK_LANGUAGES_FIRST, 0);
119 ExpectPreferences(true, std::vector<std::string>(1, "en-US"));
120 }
121
122 // Single dictionary should be selected based on preferences.
123 IN_PROC_BROWSER_TEST_F(SpellingOptionsSubMenuObserverTest,
124 SingleLanguageSelected) {
125 InitMenu(true, "en-US", std::vector<std::string>(1, "en-US"));
126 EXPECT_TRUE(menu()->IsCommandIdChecked(IDC_SPELLCHECK_LANGUAGES_FIRST));
127 }
128
129 // Single dictionary should be deselected based on preferences. Selecting the
130 // dictionary should update the preference.
131 IN_PROC_BROWSER_TEST_F(SpellingOptionsSubMenuObserverTest,
132 SelectTheOnlyLanguage) {
133 InitMenu(true, "en-US", std::vector<std::string>());
134 EXPECT_FALSE(menu()->IsCommandIdChecked(IDC_SPELLCHECK_LANGUAGES_FIRST));
135
136 menu()->ExecuteCommand(IDC_SPELLCHECK_LANGUAGES_FIRST, 0);
137 ExpectPreferences(true, std::vector<std::string>(1, "en-US"));
138 }
139
140 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698