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

Side by Side Diff: chrome/browser/spellchecker/spellcheck_service_browsertest.cc

Issue 2828313002: Convert render process component common Spellcheck IPC to mojo (Closed)
Patch Set: Build fix. Created 3 years, 7 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/spellchecker/spellcheck_service.h" 5 #include "chrome/browser/spellchecker/spellcheck_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string> 9 #include <string>
10 #include <tuple> 10 #include <tuple>
(...skipping 11 matching lines...) Expand all
22 #include "base/values.h" 22 #include "base/values.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/spellchecker/spellcheck_factory.h" 24 #include "chrome/browser/spellchecker/spellcheck_factory.h"
25 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
26 #include "chrome/common/chrome_paths.h" 26 #include "chrome/common/chrome_paths.h"
27 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
28 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
29 #include "chrome/test/base/in_process_browser_test.h" 29 #include "chrome/test/base/in_process_browser_test.h"
30 #include "components/prefs/pref_service.h" 30 #include "components/prefs/pref_service.h"
31 #include "components/spellcheck/browser/pref_names.h" 31 #include "components/spellcheck/browser/pref_names.h"
32 #include "components/spellcheck/common/spellcheck.mojom.h"
32 #include "components/spellcheck/common/spellcheck_common.h" 33 #include "components/spellcheck/common/spellcheck_common.h"
33 #include "components/spellcheck/common/spellcheck_messages.h"
34 #include "components/user_prefs/user_prefs.h" 34 #include "components/user_prefs/user_prefs.h"
35 #include "content/public/test/mock_render_process_host.h" 35 #include "content/public/test/mock_render_process_host.h"
36 #include "content/public/test/test_utils.h" 36 #include "content/public/test/test_utils.h"
37 #include "url/gurl.h" 37 #include "url/gurl.h"
38 38
39 using content::BrowserContext; 39 using content::BrowserContext;
40 40
41 namespace { 41 namespace {
42 42
43 // A corrupted BDICT data used in DeleteCorruptedBDICT. Please do not use this 43 // A corrupted BDICT data used in DeleteCorruptedBDICT. Please do not use this
44 // BDICT data for other tests. 44 // BDICT data for other tests.
45 const uint8_t kCorruptedBDICT[] = { 45 const uint8_t kCorruptedBDICT[] = {
46 0x42, 0x44, 0x69, 0x63, 0x02, 0x00, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 46 0x42, 0x44, 0x69, 0x63, 0x02, 0x00, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00,
47 0x3b, 0x00, 0x00, 0x00, 0x65, 0x72, 0xe0, 0xac, 0x27, 0xc7, 0xda, 0x66, 47 0x3b, 0x00, 0x00, 0x00, 0x65, 0x72, 0xe0, 0xac, 0x27, 0xc7, 0xda, 0x66,
48 0x6d, 0x1e, 0xa6, 0x35, 0xd1, 0xf6, 0xb7, 0x35, 0x32, 0x00, 0x00, 0x00, 48 0x6d, 0x1e, 0xa6, 0x35, 0xd1, 0xf6, 0xb7, 0x35, 0x32, 0x00, 0x00, 0x00,
49 0x38, 0x00, 0x00, 0x00, 0x39, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 49 0x38, 0x00, 0x00, 0x00, 0x39, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00,
50 0x0a, 0x0a, 0x41, 0x46, 0x20, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe6, 50 0x0a, 0x0a, 0x41, 0x46, 0x20, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe6,
51 0x49, 0x00, 0x68, 0x02, 0x73, 0x06, 0x74, 0x0b, 0x77, 0x11, 0x79, 0x15, 51 0x49, 0x00, 0x68, 0x02, 0x73, 0x06, 0x74, 0x0b, 0x77, 0x11, 0x79, 0x15,
52 }; 52 };
53 53
54 // Clears IPC messages before a preference change. Runs the runloop after the
55 // preference change.
56 class ScopedPreferenceChange {
57 public:
58 explicit ScopedPreferenceChange(IPC::TestSink* sink) {
59 sink->ClearMessages();
60 }
61
62 ~ScopedPreferenceChange() {
63 base::RunLoop().RunUntilIdle();
64 }
65
66 private:
67 DISALLOW_COPY_AND_ASSIGN(ScopedPreferenceChange);
68 };
69
70 } // namespace 54 } // namespace
71 55
72 class SpellcheckServiceBrowserTest : public InProcessBrowserTest { 56 class SpellcheckServiceBrowserTest : public InProcessBrowserTest,
57 public spellcheck::mojom::SpellChecker {
73 public: 58 public:
59 SpellcheckServiceBrowserTest() : binding_(this) {}
60
74 void SetUpOnMainThread() override { 61 void SetUpOnMainThread() override {
75 renderer_.reset(new content::MockRenderProcessHost(GetContext())); 62 renderer_.reset(new content::MockRenderProcessHost(GetContext()));
76 prefs_ = user_prefs::UserPrefs::Get(GetContext()); 63 prefs_ = user_prefs::UserPrefs::Get(GetContext());
77 } 64 }
78 65
79 void TearDownOnMainThread() override { 66 void TearDownOnMainThread() override {
67 binding_.Close();
80 prefs_ = nullptr; 68 prefs_ = nullptr;
81 renderer_.reset(); 69 renderer_.reset();
82 } 70 }
83 71
84 BrowserContext* GetContext() { 72 BrowserContext* GetContext() {
85 return static_cast<BrowserContext*>(browser()->profile()); 73 return static_cast<BrowserContext*>(browser()->profile());
86 } 74 }
87 75
88 PrefService* GetPrefs() { 76 PrefService* GetPrefs() {
89 return prefs_; 77 return prefs_;
90 } 78 }
91 79
92 void InitSpellcheck(bool enable_spellcheck, 80 void InitSpellcheck(bool enable_spellcheck,
93 const std::string& single_dictionary, 81 const std::string& single_dictionary,
94 const std::string& multiple_dictionaries) { 82 const std::string& multiple_dictionaries) {
95 prefs_->SetBoolean(spellcheck::prefs::kEnableSpellcheck, 83 prefs_->SetBoolean(spellcheck::prefs::kEnableSpellcheck,
96 enable_spellcheck); 84 enable_spellcheck);
97 prefs_->SetString(spellcheck::prefs::kSpellCheckDictionary, 85 prefs_->SetString(spellcheck::prefs::kSpellCheckDictionary,
98 single_dictionary); 86 single_dictionary);
99 base::ListValue dictionaries_value; 87 base::ListValue dictionaries_value;
100 dictionaries_value.AppendStrings( 88 dictionaries_value.AppendStrings(
101 base::SplitString(multiple_dictionaries, ",", base::TRIM_WHITESPACE, 89 base::SplitString(multiple_dictionaries, ",", base::TRIM_WHITESPACE,
102 base::SPLIT_WANT_NONEMPTY)); 90 base::SPLIT_WANT_NONEMPTY));
103 prefs_->Set(spellcheck::prefs::kSpellCheckDictionaries, dictionaries_value); 91 prefs_->Set(spellcheck::prefs::kSpellCheckDictionaries, dictionaries_value);
92
104 SpellcheckService* spellcheck = 93 SpellcheckService* spellcheck =
105 SpellcheckServiceFactory::GetForRenderProcessId(renderer_->GetID()); 94 SpellcheckServiceFactory::GetForRenderProcessId(renderer_->GetID());
106 ASSERT_NE(nullptr, spellcheck); 95 ASSERT_NE(nullptr, spellcheck);
107 spellcheck->InitForRenderer(renderer_.get()); 96
97 // Override |renderer_| requests for the spellcheck::mojom::SpellChecker
98 // interface so we can test the SpellChecker request flow.
99 renderer_->OverrideBinderForTesting(
100 spellcheck::mojom::SpellChecker::Name_,
101 base::Bind(&SpellcheckServiceBrowserTest::Bind,
102 base::Unretained(this)));
108 } 103 }
109 104
110 void EnableSpellcheck(bool enable_spellcheck) { 105 void EnableSpellcheck(bool enable_spellcheck) {
111 ScopedPreferenceChange scope(&renderer_->sink());
112 prefs_->SetBoolean(spellcheck::prefs::kEnableSpellcheck, 106 prefs_->SetBoolean(spellcheck::prefs::kEnableSpellcheck,
113 enable_spellcheck); 107 enable_spellcheck);
114 } 108 }
115 109
110 void ChangeCustomDictionary() {
111 SpellcheckService* spellcheck =
112 SpellcheckServiceFactory::GetForRenderProcessId(renderer_->GetID());
113 ASSERT_NE(nullptr, spellcheck);
114
115 SpellcheckCustomDictionary::Change change;
116 change.RemoveWord("1");
117 change.AddWord("2");
118 change.AddWord("3");
119
120 spellcheck->OnCustomDictionaryChanged(change);
121 }
122
116 void SetSingleLanguageDictionary(const std::string& single_dictionary) { 123 void SetSingleLanguageDictionary(const std::string& single_dictionary) {
117 ScopedPreferenceChange scope(&renderer_->sink());
118 prefs_->SetString(spellcheck::prefs::kSpellCheckDictionary, 124 prefs_->SetString(spellcheck::prefs::kSpellCheckDictionary,
119 single_dictionary); 125 single_dictionary);
120 } 126 }
121 127
122 void SetMultiLingualDictionaries(const std::string& multiple_dictionaries) { 128 void SetMultiLingualDictionaries(const std::string& multiple_dictionaries) {
123 ScopedPreferenceChange scope(&renderer_->sink());
124 base::ListValue dictionaries_value; 129 base::ListValue dictionaries_value;
125 dictionaries_value.AppendStrings( 130 dictionaries_value.AppendStrings(
126 base::SplitString(multiple_dictionaries, ",", base::TRIM_WHITESPACE, 131 base::SplitString(multiple_dictionaries, ",", base::TRIM_WHITESPACE,
127 base::SPLIT_WANT_NONEMPTY)); 132 base::SPLIT_WANT_NONEMPTY));
128 prefs_->Set(spellcheck::prefs::kSpellCheckDictionaries, dictionaries_value); 133 prefs_->Set(spellcheck::prefs::kSpellCheckDictionaries, dictionaries_value);
129 } 134 }
130 135
131 std::string GetMultilingualDictionaries() { 136 std::string GetMultilingualDictionaries() {
132 const base::ListValue* list_value = 137 const base::ListValue* list_value =
133 prefs_->GetList(spellcheck::prefs::kSpellCheckDictionaries); 138 prefs_->GetList(spellcheck::prefs::kSpellCheckDictionaries);
134 std::vector<base::StringPiece> dictionaries; 139 std::vector<base::StringPiece> dictionaries;
135 for (const auto& item_value : *list_value) { 140 for (const auto& item_value : *list_value) {
136 base::StringPiece dictionary; 141 base::StringPiece dictionary;
137 EXPECT_TRUE(item_value.GetAsString(&dictionary)); 142 EXPECT_TRUE(item_value.GetAsString(&dictionary));
138 dictionaries.push_back(dictionary); 143 dictionaries.push_back(dictionary);
139 } 144 }
140 return base::JoinString(dictionaries, ","); 145 return base::JoinString(dictionaries, ",");
141 } 146 }
142 147
143 void SetAcceptLanguages(const std::string& accept_languages) { 148 void SetAcceptLanguages(const std::string& accept_languages) {
144 ScopedPreferenceChange scope(&renderer_->sink());
145 prefs_->SetString(prefs::kAcceptLanguages, accept_languages); 149 prefs_->SetString(prefs::kAcceptLanguages, accept_languages);
146 } 150 }
147 151
148 // Returns the boolean parameter sent in the first 152 bool GetEnableSpellcheckState(bool initial_state = false) {
149 // SpellCheckMsg_EnableSpellCheck message. For example, if spellcheck service 153 spellcheck_enabled_state_ = initial_state;
150 // sent the SpellCheckMsg_EnableSpellCheck(true) message, then this method 154 RunTestRunLoop();
151 // returns true. 155 EXPECT_TRUE(initialize_spellcheck_called_);
152 bool GetFirstEnableSpellcheckMessageParam() { 156 EXPECT_TRUE(bound_connection_closed_);
153 const IPC::Message* message = renderer_->sink().GetFirstMessageMatching( 157 return spellcheck_enabled_state_;
154 SpellCheckMsg_EnableSpellCheck::ID); 158 }
155 EXPECT_NE(nullptr, message);
156 if (!message)
157 return false;
158 159
159 SpellCheckMsg_EnableSpellCheck::Param param; 160 bool GetCustomDictionaryChangedState() {
160 bool ok = SpellCheckMsg_EnableSpellCheck::Read(message, &param); 161 RunTestRunLoop();
161 EXPECT_TRUE(ok); 162 EXPECT_TRUE(bound_connection_closed_);
162 if (!ok) 163 return custom_dictionary_changed_called_;
163 return false;
164
165 return std::get<0>(param);
166 } 164 }
167 165
168 private: 166 private:
167 // Spins a RunLoop to deliver the Mojo SpellChecker request flow.
168 void RunTestRunLoop() {
169 bound_connection_closed_ = false;
170 initialize_spellcheck_called_ = false;
171 custom_dictionary_changed_called_ = false;
172
173 base::RunLoop run_loop;
174 quit_ = run_loop.QuitClosure();
175 run_loop.Run();
176 }
177
178 // Binds requests for the SpellChecker interface.
179 void Bind(mojo::ScopedMessagePipeHandle handle) {
180 binding_.Bind(std::move(handle));
181 binding_.set_connection_error_handler(
182 base::Bind(&SpellcheckServiceBrowserTest::BoundConnectionClosed,
183 base::Unretained(this)));
184 }
185
186 // The requester closes (disconnects) when done.
187 void BoundConnectionClosed() {
188 bound_connection_closed_ = true;
189 binding_.Close();
190 if (quit_)
191 std::move(quit_).Run();
192 }
193
194 // spellcheck::mojom::SpellChecker:
195 void Initialize(
196 std::vector<spellcheck::mojom::SpellCheckBDictLanguagePtr> dictionaries,
197 const std::vector<std::string>& custom_words,
198 bool enable) override {
199 initialize_spellcheck_called_ = true;
200 spellcheck_enabled_state_ = enable;
201 }
202
203 void CustomDictionaryChanged(
204 const std::vector<std::string>& words_added,
205 const std::vector<std::string>& words_removed) override {
206 custom_dictionary_changed_called_ = true;
207 EXPECT_EQ(1u, words_removed.size());
208 EXPECT_EQ(2u, words_added.size());
209 }
210
211 // Mocked RenderProcessHost.
169 std::unique_ptr<content::MockRenderProcessHost> renderer_; 212 std::unique_ptr<content::MockRenderProcessHost> renderer_;
170 213
171 // Not owned preferences service. 214 // Not owned preferences service.
172 PrefService* prefs_; 215 PrefService* prefs_;
216
217 // Binding to receive the SpellChecker request flow.
218 mojo::Binding<spellcheck::mojom::SpellChecker> binding_;
219
220 // Quits the RunLoop on SpellChecker request flow completion.
221 base::OnceClosure quit_;
222
223 // Used to verify the SpellChecker request flow.
224 bool bound_connection_closed_;
225 bool custom_dictionary_changed_called_;
226 bool initialize_spellcheck_called_;
227 bool spellcheck_enabled_state_;
228
229 DISALLOW_COPY_AND_ASSIGN(SpellcheckServiceBrowserTest);
173 }; 230 };
174 231
175 // Removing a spellcheck language from accept languages should remove it from 232 // Removing a spellcheck language from accept languages should remove it from
176 // spellcheck languages list as well. 233 // spellcheck languages list as well.
177 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, 234 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest,
178 RemoveSpellcheckLanguageFromAcceptLanguages) { 235 RemoveSpellcheckLanguageFromAcceptLanguages) {
179 InitSpellcheck(true, "", "en-US,fr"); 236 InitSpellcheck(true, "", "en-US,fr");
180 SetAcceptLanguages("en-US,es,ru"); 237 SetAcceptLanguages("en-US,es,ru");
181 EXPECT_EQ("en-US", GetMultilingualDictionaries()); 238 EXPECT_EQ("en-US", GetMultilingualDictionaries());
182 } 239 }
183 240
184 // Keeping spellcheck languages in accept languages should not alter spellcheck 241 // Keeping spellcheck languages in accept languages should not alter spellcheck
185 // languages list. 242 // languages list.
186 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, 243 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest,
187 KeepSpellcheckLanguagesInAcceptLanguages) { 244 KeepSpellcheckLanguagesInAcceptLanguages) {
188 InitSpellcheck(true, "", "en-US,fr"); 245 InitSpellcheck(true, "", "en-US,fr");
189 SetAcceptLanguages("en-US,fr,es"); 246 SetAcceptLanguages("en-US,fr,es");
190 EXPECT_EQ("en-US,fr", GetMultilingualDictionaries()); 247 EXPECT_EQ("en-US,fr", GetMultilingualDictionaries());
191 } 248 }
192 249
193 // Starting with spellcheck enabled should send the 'enable spellcheck' message 250 // Starting with spellcheck enabled should send the 'enable spellcheck' message
194 // to the renderer. Consequently disabling spellcheck should send the 'disable 251 // to the renderer. Consequently disabling spellcheck should send the 'disable
195 // spellcheck' message to the renderer. 252 // spellcheck' message to the renderer.
196 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, StartWithSpellcheck) { 253 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, StartWithSpellcheck) {
197 InitSpellcheck(true, "", "en-US,fr"); 254 InitSpellcheck(true, "", "en-US,fr");
198 EXPECT_TRUE(GetFirstEnableSpellcheckMessageParam()); 255 EXPECT_TRUE(GetEnableSpellcheckState());
199 256
200 EnableSpellcheck(false); 257 EnableSpellcheck(false);
201 EXPECT_FALSE(GetFirstEnableSpellcheckMessageParam()); 258 EXPECT_FALSE(GetEnableSpellcheckState(true));
202 } 259 }
203 260
204 // Starting with only a single-language spellcheck setting should send the 261 // Starting with only a single-language spellcheck setting should send the
205 // 'enable spellcheck' message to the renderer. Consequently removing spellcheck 262 // 'enable spellcheck' message to the renderer. Consequently removing spellcheck
206 // languages should disable spellcheck. 263 // languages should disable spellcheck.
207 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, 264 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest,
208 StartWithSingularLanguagePreference) { 265 StartWithSingularLanguagePreference) {
209 InitSpellcheck(true, "en-US", ""); 266 InitSpellcheck(true, "en-US", "");
210 EXPECT_TRUE(GetFirstEnableSpellcheckMessageParam()); 267 EXPECT_TRUE(GetEnableSpellcheckState());
211 268
212 SetMultiLingualDictionaries(""); 269 SetMultiLingualDictionaries("");
213 EXPECT_FALSE(GetFirstEnableSpellcheckMessageParam()); 270 EXPECT_FALSE(GetEnableSpellcheckState(true));
214 } 271 }
215 272
216 // Starting with a multi-language spellcheck setting should send the 'enable 273 // Starting with a multi-language spellcheck setting should send the 'enable
217 // spellcheck' message to the renderer. Consequently removing spellcheck 274 // spellcheck' message to the renderer. Consequently removing spellcheck
218 // languages should disable spellcheck. 275 // languages should disable spellcheck.
219 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, 276 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest,
220 StartWithMultiLanguagePreference) { 277 StartWithMultiLanguagePreference) {
221 InitSpellcheck(true, "", "en-US,fr"); 278 InitSpellcheck(true, "", "en-US,fr");
222 EXPECT_TRUE(GetFirstEnableSpellcheckMessageParam()); 279 EXPECT_TRUE(GetEnableSpellcheckState());
223 280
224 SetMultiLingualDictionaries(""); 281 SetMultiLingualDictionaries("");
225 EXPECT_FALSE(GetFirstEnableSpellcheckMessageParam()); 282 EXPECT_FALSE(GetEnableSpellcheckState(true));
226 } 283 }
227 284
228 // Starting with both single-language and multi-language spellcheck settings 285 // Starting with both single-language and multi-language spellcheck settings
229 // should send the 'enable spellcheck' message to the renderer. Consequently 286 // should send the 'enable spellcheck' message to the renderer. Consequently
230 // removing spellcheck languages should disable spellcheck. 287 // removing spellcheck languages should disable spellcheck.
231 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, 288 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest,
232 StartWithBothLanguagePreferences) { 289 StartWithBothLanguagePreferences) {
233 InitSpellcheck(true, "en-US", "en-US,fr"); 290 InitSpellcheck(true, "en-US", "en-US,fr");
234 EXPECT_TRUE(GetFirstEnableSpellcheckMessageParam()); 291 EXPECT_TRUE(GetEnableSpellcheckState());
235 292
236 SetMultiLingualDictionaries(""); 293 SetMultiLingualDictionaries("");
237 EXPECT_FALSE(GetFirstEnableSpellcheckMessageParam()); 294 EXPECT_FALSE(GetEnableSpellcheckState(true));
238 } 295 }
239 296
240 // Starting without spellcheck languages should send the 'disable spellcheck' 297 // Starting without spellcheck languages should send the 'disable spellcheck'
241 // message to the renderer. Consequently adding spellchecking languages should 298 // message to the renderer. Consequently adding spellchecking languages should
242 // enable spellcheck. 299 // enable spellcheck.
243 // Flaky, see https://crbug.com/600153 300 // Flaky, see https://crbug.com/600153
244 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, 301 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest,
245 DISABLED_StartWithoutLanguages) { 302 DISABLED_StartWithoutLanguages) {
246 InitSpellcheck(true, "", ""); 303 InitSpellcheck(true, "", "");
247 EXPECT_FALSE(GetFirstEnableSpellcheckMessageParam()); 304 EXPECT_FALSE(GetEnableSpellcheckState(true));
248 305
249 SetMultiLingualDictionaries("en-US"); 306 SetMultiLingualDictionaries("en-US");
250 EXPECT_TRUE(GetFirstEnableSpellcheckMessageParam()); 307 EXPECT_TRUE(GetEnableSpellcheckState());
251 } 308 }
252 309
253 // Starting with spellcheck disabled should send the 'disable spellcheck' 310 // Starting with spellcheck disabled should send the 'disable spellcheck'
254 // message to the renderer. Consequently enabling spellcheck should send the 311 // message to the renderer. Consequently enabling spellcheck should send the
255 // 'enable spellcheck' message to the renderer. 312 // 'enable spellcheck' message to the renderer.
256 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, StartWithoutSpellcheck) { 313 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, StartWithoutSpellcheck) {
257 InitSpellcheck(false, "", "en-US,fr"); 314 InitSpellcheck(false, "", "en-US,fr");
258 EXPECT_FALSE(GetFirstEnableSpellcheckMessageParam()); 315 EXPECT_FALSE(GetEnableSpellcheckState(true));
259 316
260 EnableSpellcheck(true); 317 EnableSpellcheck(true);
261 EXPECT_TRUE(GetFirstEnableSpellcheckMessageParam()); 318 EXPECT_TRUE(GetEnableSpellcheckState());
319 }
320
321 // A custom dictionary state change should send a 'custom dictionary changed'
322 // message to the renderer, regardless of the spellcheck enabled state.
323 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, CustomDictionaryChanged) {
324 InitSpellcheck(true, "en-US", "");
325 EXPECT_TRUE(GetEnableSpellcheckState());
326
327 ChangeCustomDictionary();
328 EXPECT_TRUE(GetCustomDictionaryChangedState());
329
330 EnableSpellcheck(false);
331 EXPECT_FALSE(GetEnableSpellcheckState(true));
332
333 ChangeCustomDictionary();
334 EXPECT_TRUE(GetCustomDictionaryChangedState());
262 } 335 }
263 336
264 // Tests that we can delete a corrupted BDICT file used by hunspell. We do not 337 // Tests that we can delete a corrupted BDICT file used by hunspell. We do not
265 // run this test on Mac because Mac does not use hunspell by default. 338 // run this test on Mac because Mac does not use hunspell by default.
266 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, DeleteCorruptedBDICT) { 339 IN_PROC_BROWSER_TEST_F(SpellcheckServiceBrowserTest, DeleteCorruptedBDICT) {
267 // Write the corrupted BDICT data to create a corrupted BDICT file. 340 // Write the corrupted BDICT data to create a corrupted BDICT file.
268 base::FilePath dict_dir; 341 base::FilePath dict_dir;
269 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir)); 342 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir));
270 base::FilePath bdict_path = 343 base::FilePath bdict_path =
271 spellcheck::GetVersionedFileName("en-US", dict_dir); 344 spellcheck::GetVersionedFileName("en-US", dict_dir);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 std::string pref; 466 std::string pref;
394 ASSERT_TRUE(GetPrefs() 467 ASSERT_TRUE(GetPrefs()
395 ->GetList(spellcheck::prefs::kSpellCheckDictionaries) 468 ->GetList(spellcheck::prefs::kSpellCheckDictionaries)
396 ->GetString(0, &pref)); 469 ->GetString(0, &pref));
397 EXPECT_EQ("en-US", pref); 470 EXPECT_EQ("en-US", pref);
398 ASSERT_TRUE(GetPrefs() 471 ASSERT_TRUE(GetPrefs()
399 ->GetList(spellcheck::prefs::kSpellCheckDictionaries) 472 ->GetList(spellcheck::prefs::kSpellCheckDictionaries)
400 ->GetString(1, &pref)); 473 ->GetString(1, &pref));
401 EXPECT_EQ("fr", pref); 474 EXPECT_EQ("fr", pref);
402 } 475 }
OLDNEW
« no previous file with comments | « chrome/browser/spellchecker/spellcheck_service.cc ('k') | components/spellcheck/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698