OLD | NEW |
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/tab_contents/spelling_menu_observer.h" | 5 #include "chrome/browser/tab_contents/spelling_menu_observer.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
| 9 #include "base/command_line.h" |
9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
10 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
11 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
12 #include "chrome/browser/spellchecker/spelling_service_client.h" | 13 #include "chrome/browser/spellchecker/spelling_service_client.h" |
13 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 14 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
14 #include "chrome/browser/tab_contents/render_view_context_menu_observer.h" | 15 #include "chrome/browser/tab_contents/render_view_context_menu_observer.h" |
| 16 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
16 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
17 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
18 | 20 |
19 using content::RenderViewHost; | 21 using content::RenderViewHost; |
20 using content::WebContents; | 22 using content::WebContents; |
21 | 23 |
22 namespace { | 24 namespace { |
23 | 25 |
24 // A mock context menu used in this test. This class overrides virtual methods | 26 // A mock context menu used in this test. This class overrides virtual methods |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 menu->GetMenuItem(1, &item); | 355 menu->GetMenuItem(1, &item); |
354 EXPECT_EQ(IDC_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS, item.command_id); | 356 EXPECT_EQ(IDC_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS, item.command_id); |
355 EXPECT_FALSE(item.enabled); | 357 EXPECT_FALSE(item.enabled); |
356 EXPECT_FALSE(item.hidden); | 358 EXPECT_FALSE(item.hidden); |
357 | 359 |
358 menu->GetMenuItem(2, &item); | 360 menu->GetMenuItem(2, &item); |
359 EXPECT_EQ(-1, item.command_id); | 361 EXPECT_EQ(-1, item.command_id); |
360 EXPECT_FALSE(item.enabled); | 362 EXPECT_FALSE(item.enabled); |
361 EXPECT_FALSE(item.hidden); | 363 EXPECT_FALSE(item.hidden); |
362 } | 364 } |
| 365 |
| 366 // Test that we don't show "No more suggestions from Google" if the spelling |
| 367 // service is enabled and that there is only one suggestion. |
| 368 IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, |
| 369 NoMoreSuggestionsNotDisplayed) { |
| 370 scoped_ptr<MockRenderViewContextMenu> menu(new MockRenderViewContextMenu); |
| 371 scoped_ptr<SpellingMenuObserver> observer( |
| 372 new SpellingMenuObserver(menu.get())); |
| 373 menu->SetObserver(observer.get()); |
| 374 menu->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, true); |
| 375 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 376 command_line->AppendSwitch(switches::kUseSpellingService); |
| 377 |
| 378 // Make sure we can pretend to handle the JSON request. |
| 379 menu->CreateRequestContext(); |
| 380 |
| 381 // Force a non-empty locale so SPELLCHECK is available. |
| 382 menu->GetPrefs()->SetString(prefs::kSpellCheckDictionary, "en"); |
| 383 EXPECT_TRUE(SpellingServiceClient::IsAvailable(menu->GetProfile(), |
| 384 SpellingServiceClient::SPELLCHECK)); |
| 385 |
| 386 content::ContextMenuParams params; |
| 387 params.is_editable = true; |
| 388 params.misspelled_word = ASCIIToUTF16("asdfkj"); |
| 389 params.dictionary_suggestions.push_back(ASCIIToUTF16("asdf")); |
| 390 observer->InitMenu(params); |
| 391 |
| 392 // The test should see a suggestion (from SpellingService) and a separator |
| 393 // as the first two items, then possibly more (not relevant here). |
| 394 EXPECT_LT(2U, menu->GetMenuSize()); |
| 395 |
| 396 MockRenderViewContextMenu::MockMenuItem item; |
| 397 menu->GetMenuItem(0, &item); |
| 398 EXPECT_EQ(IDC_SPELLCHECK_SUGGESTION_0, item.command_id); |
| 399 EXPECT_TRUE(item.enabled); |
| 400 EXPECT_FALSE(item.hidden); |
| 401 |
| 402 menu->GetMenuItem(1, &item); |
| 403 EXPECT_NE(IDC_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS, item.command_id); |
| 404 EXPECT_EQ(-1, item.command_id); |
| 405 EXPECT_FALSE(item.enabled); |
| 406 EXPECT_FALSE(item.hidden); |
| 407 } |
OLD | NEW |