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

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

Issue 252643004: Remove --use-spelling-suggestions flag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Force suggest mode in a function. Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/spellchecker/spelling_service_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_menu_observer.h" 5 #include "chrome/browser/renderer_context_menu/spelling_menu_observer.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 void InitMenu(const char* word, const char* suggestion) { 225 void InitMenu(const char* word, const char* suggestion) {
226 content::ContextMenuParams params; 226 content::ContextMenuParams params;
227 params.is_editable = true; 227 params.is_editable = true;
228 params.misspelled_word = base::ASCIIToUTF16(word); 228 params.misspelled_word = base::ASCIIToUTF16(word);
229 params.dictionary_suggestions.clear(); 229 params.dictionary_suggestions.clear();
230 if (suggestion) 230 if (suggestion)
231 params.dictionary_suggestions.push_back(base::ASCIIToUTF16(suggestion)); 231 params.dictionary_suggestions.push_back(base::ASCIIToUTF16(suggestion));
232 observer_->InitMenu(params); 232 observer_->InitMenu(params);
233 } 233 }
234 234
235 void ForceSuggestMode() {
236 menu()->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, true);
237 // Force a non-empty and non-"en" locale so SUGGEST is available.
238 menu()->GetPrefs()->SetString(prefs::kSpellCheckDictionary, "fr");
239 ASSERT_TRUE(SpellingServiceClient::IsAvailable(
240 menu()->GetProfile(), SpellingServiceClient::SUGGEST));
241 ASSERT_FALSE(SpellingServiceClient::IsAvailable(
242 menu()->GetProfile(), SpellingServiceClient::SPELLCHECK));
243 }
244
235 virtual ~SpellingMenuObserverTest(); 245 virtual ~SpellingMenuObserverTest();
236 MockRenderViewContextMenu* menu() { return menu_.get(); } 246 MockRenderViewContextMenu* menu() { return menu_.get(); }
237 SpellingMenuObserver* observer() { return observer_.get(); } 247 SpellingMenuObserver* observer() { return observer_.get(); }
238 private: 248 private:
239 scoped_ptr<SpellingMenuObserver> observer_; 249 scoped_ptr<SpellingMenuObserver> observer_;
240 scoped_ptr<MockRenderViewContextMenu> menu_; 250 scoped_ptr<MockRenderViewContextMenu> menu_;
241 DISALLOW_COPY_AND_ASSIGN(SpellingMenuObserverTest); 251 DISALLOW_COPY_AND_ASSIGN(SpellingMenuObserverTest);
242 }; 252 };
243 253
244 SpellingMenuObserverTest::SpellingMenuObserverTest() { 254 SpellingMenuObserverTest::SpellingMenuObserverTest() {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 menu()->GetMenuItem(2, &item); 326 menu()->GetMenuItem(2, &item);
317 EXPECT_EQ(IDC_CONTENT_CONTEXT_SPELLING_TOGGLE, item.command_id); 327 EXPECT_EQ(IDC_CONTENT_CONTEXT_SPELLING_TOGGLE, item.command_id);
318 EXPECT_TRUE(item.enabled); 328 EXPECT_TRUE(item.enabled);
319 EXPECT_TRUE(item.checked); 329 EXPECT_TRUE(item.checked);
320 EXPECT_FALSE(item.hidden); 330 EXPECT_FALSE(item.hidden);
321 } 331 }
322 332
323 // Test that there will be a separator after "no suggestions" if 333 // Test that there will be a separator after "no suggestions" if
324 // SpellingServiceClient::SUGGEST is on. 334 // SpellingServiceClient::SUGGEST is on.
325 IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, SeparatorAfterSuggestions) { 335 IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, SeparatorAfterSuggestions) {
326 menu()->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, true); 336 ForceSuggestMode();
327 CommandLine* command_line = CommandLine::ForCurrentProcess();
328 command_line->AppendSwitch(switches::kUseSpellingSuggestions);
329
330 // Force a non-empty locale so SUGGEST is available.
331 menu()->GetPrefs()->SetString(prefs::kSpellCheckDictionary, "en");
332 EXPECT_TRUE(SpellingServiceClient::IsAvailable(menu()->GetProfile(),
333 SpellingServiceClient::SUGGEST));
334
335 InitMenu("jhhj", NULL); 337 InitMenu("jhhj", NULL);
336 338
337 // The test should see a top separator, "No spelling suggestions", 339 // The test should see a top separator, "No spelling suggestions",
338 // "No more Google suggestions" (from SpellingService) and a separator 340 // "No more Google suggestions" (from SpellingService) and a separator
339 // as the first four items, then possibly more (not relevant here). 341 // as the first four items, then possibly more (not relevant here).
340 EXPECT_LT(4U, menu()->GetMenuSize()); 342 EXPECT_LT(4U, menu()->GetMenuSize());
341 343
342 MockRenderViewContextMenu::MockMenuItem item; 344 MockRenderViewContextMenu::MockMenuItem item;
343 menu()->GetMenuItem(0, &item); 345 menu()->GetMenuItem(0, &item);
344 EXPECT_EQ(-1, item.command_id); 346 EXPECT_EQ(-1, item.command_id);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 InitMenu("asdfkj", "asdf"); 462 InitMenu("asdfkj", "asdf");
461 463
462 // Expect at least separator and 4 default entries. 464 // Expect at least separator and 4 default entries.
463 EXPECT_LT(static_cast<size_t>(5), menu()->GetMenuSize()); 465 EXPECT_LT(static_cast<size_t>(5), menu()->GetMenuSize());
464 // This test only cares that the first one is a separator. 466 // This test only cares that the first one is a separator.
465 menu()->GetMenuItem(0, &item); 467 menu()->GetMenuItem(0, &item);
466 EXPECT_EQ(-1, item.command_id); 468 EXPECT_EQ(-1, item.command_id);
467 469
468 // Case #3. Misspelled word, suggestion service is on. 470 // Case #3. Misspelled word, suggestion service is on.
469 Reset(false); 471 Reset(false);
470 menu()->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, true); 472 ForceSuggestMode();
471 CommandLine* command_line = CommandLine::ForCurrentProcess();
472 command_line->AppendSwitch(switches::kUseSpellingSuggestions);
473 InitMenu("asdfkj", NULL); 473 InitMenu("asdfkj", NULL);
474 474
475 // Should have at least 2 entries. Separator, suggestion. 475 // Should have at least 2 entries. Separator, suggestion.
476 EXPECT_LT(2U, menu()->GetMenuSize()); 476 EXPECT_LT(2U, menu()->GetMenuSize());
477 menu()->GetMenuItem(0, &item); 477 menu()->GetMenuItem(0, &item);
478 EXPECT_EQ(-1, item.command_id); 478 EXPECT_EQ(-1, item.command_id);
479 menu()->GetMenuItem(1, &item); 479 menu()->GetMenuItem(1, &item);
480 EXPECT_EQ(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, item.command_id); 480 EXPECT_EQ(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, item.command_id);
481 } 481 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/spellchecker/spelling_service_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698