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

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

Issue 17127002: Correctly integrate StoragePartition into TestingProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix InstantNTP test. Created 7 years, 5 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
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/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/command_line.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 const string16& label, 55 const string16& label,
56 ui::MenuModel* model) OVERRIDE; 56 ui::MenuModel* model) OVERRIDE;
57 virtual void UpdateMenuItem(int command_id, 57 virtual void UpdateMenuItem(int command_id,
58 bool enabled, 58 bool enabled,
59 bool hidden, 59 bool hidden,
60 const string16& title) OVERRIDE; 60 const string16& title) OVERRIDE;
61 virtual RenderViewHost* GetRenderViewHost() const OVERRIDE; 61 virtual RenderViewHost* GetRenderViewHost() const OVERRIDE;
62 virtual WebContents* GetWebContents() const OVERRIDE; 62 virtual WebContents* GetWebContents() const OVERRIDE;
63 virtual Profile* GetProfile() const OVERRIDE; 63 virtual Profile* GetProfile() const OVERRIDE;
64 64
65 // Create a testing URL request context.
66 void CreateRequestContext() {
67 profile_->CreateRequestContext();
68 }
69
70 // Attaches a RenderViewContextMenuObserver to be tested. 65 // Attaches a RenderViewContextMenuObserver to be tested.
71 void SetObserver(RenderViewContextMenuObserver* observer); 66 void SetObserver(RenderViewContextMenuObserver* observer);
72 67
73 // Returns the number of items added by the test. 68 // Returns the number of items added by the test.
74 size_t GetMenuSize() const; 69 size_t GetMenuSize() const;
75 70
76 // Returns the i-th item. 71 // Returns the i-th item.
77 bool GetMenuItem(size_t i, MockMenuItem* item) const; 72 bool GetMenuItem(size_t i, MockMenuItem* item) const;
78 73
79 // Returns the writable profile used in this test. 74 // Returns the writable profile used in this test.
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 EXPECT_FALSE(item.hidden); 315 EXPECT_FALSE(item.hidden);
321 } 316 }
322 317
323 // Test that there will be a separator after "no suggestions" if 318 // Test that there will be a separator after "no suggestions" if
324 // SpellingServiceClient::SUGGEST is on. 319 // SpellingServiceClient::SUGGEST is on.
325 IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, SeparatorAfterSuggestions) { 320 IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, SeparatorAfterSuggestions) {
326 menu()->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, true); 321 menu()->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, true);
327 CommandLine* command_line = CommandLine::ForCurrentProcess(); 322 CommandLine* command_line = CommandLine::ForCurrentProcess();
328 command_line->AppendSwitch(switches::kUseSpellingSuggestions); 323 command_line->AppendSwitch(switches::kUseSpellingSuggestions);
329 324
330 // Make sure we can pretend to handle the JSON request.
331 menu()->CreateRequestContext();
332
333 // Force a non-empty locale so SUGGEST is available. 325 // Force a non-empty locale so SUGGEST is available.
334 menu()->GetPrefs()->SetString(prefs::kSpellCheckDictionary, "en"); 326 menu()->GetPrefs()->SetString(prefs::kSpellCheckDictionary, "en");
335 EXPECT_TRUE(SpellingServiceClient::IsAvailable(menu()->GetProfile(), 327 EXPECT_TRUE(SpellingServiceClient::IsAvailable(menu()->GetProfile(),
336 SpellingServiceClient::SUGGEST)); 328 SpellingServiceClient::SUGGEST));
337 329
338 InitMenu("jhhj", NULL); 330 InitMenu("jhhj", NULL);
339 331
340 // The test should see a top separator, "No spelling suggestions", 332 // The test should see a top separator, "No spelling suggestions",
341 // "No more Google suggestions" (from SpellingService) and a separator 333 // "No more Google suggestions" (from SpellingService) and a separator
342 // as the first four items, then possibly more (not relevant here). 334 // as the first four items, then possibly more (not relevant here).
(...skipping 20 matching lines...) Expand all
363 EXPECT_FALSE(item.enabled); 355 EXPECT_FALSE(item.enabled);
364 EXPECT_FALSE(item.hidden); 356 EXPECT_FALSE(item.hidden);
365 } 357 }
366 358
367 // Test that we don't show "No more suggestions from Google" if the spelling 359 // Test that we don't show "No more suggestions from Google" if the spelling
368 // service is enabled and that there is only one suggestion. 360 // service is enabled and that there is only one suggestion.
369 IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, 361 IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest,
370 NoMoreSuggestionsNotDisplayed) { 362 NoMoreSuggestionsNotDisplayed) {
371 menu()->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, true); 363 menu()->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, true);
372 364
373 // Make sure we can pretend to handle the JSON request.
374 menu()->CreateRequestContext();
375
376 // Force a non-empty locale so SPELLCHECK is available. 365 // Force a non-empty locale so SPELLCHECK is available.
377 menu()->GetPrefs()->SetString(prefs::kSpellCheckDictionary, "en"); 366 menu()->GetPrefs()->SetString(prefs::kSpellCheckDictionary, "en");
378 EXPECT_TRUE(SpellingServiceClient::IsAvailable(menu()->GetProfile(), 367 EXPECT_TRUE(SpellingServiceClient::IsAvailable(menu()->GetProfile(),
379 SpellingServiceClient::SPELLCHECK)); 368 SpellingServiceClient::SPELLCHECK));
380 InitMenu("asdfkj", "asdf"); 369 InitMenu("asdfkj", "asdf");
381 370
382 // The test should see a separator, a suggestion and another separator 371 // The test should see a separator, a suggestion and another separator
383 // as the first two items, then possibly more (not relevant here). 372 // as the first two items, then possibly more (not relevant here).
384 EXPECT_LT(3U, menu()->GetMenuSize()); 373 EXPECT_LT(3U, menu()->GetMenuSize());
385 374
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 EXPECT_LT(static_cast<size_t>(5), menu()->GetMenuSize()); 460 EXPECT_LT(static_cast<size_t>(5), menu()->GetMenuSize());
472 // This test only cares that the first one is a separator. 461 // This test only cares that the first one is a separator.
473 menu()->GetMenuItem(0, &item); 462 menu()->GetMenuItem(0, &item);
474 EXPECT_EQ(-1, item.command_id); 463 EXPECT_EQ(-1, item.command_id);
475 464
476 // Case #3. Misspelled word, suggestion service is on. 465 // Case #3. Misspelled word, suggestion service is on.
477 Reset(); 466 Reset();
478 menu()->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, true); 467 menu()->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, true);
479 CommandLine* command_line = CommandLine::ForCurrentProcess(); 468 CommandLine* command_line = CommandLine::ForCurrentProcess();
480 command_line->AppendSwitch(switches::kUseSpellingSuggestions); 469 command_line->AppendSwitch(switches::kUseSpellingSuggestions);
481 menu()->CreateRequestContext();
482 InitMenu("asdfkj", NULL); 470 InitMenu("asdfkj", NULL);
483 471
484 // Should have at least 2 entries. Separator, suggestion. 472 // Should have at least 2 entries. Separator, suggestion.
485 EXPECT_LT(2U, menu()->GetMenuSize()); 473 EXPECT_LT(2U, menu()->GetMenuSize());
486 menu()->GetMenuItem(0, &item); 474 menu()->GetMenuItem(0, &item);
487 EXPECT_EQ(-1, item.command_id); 475 EXPECT_EQ(-1, item.command_id);
488 menu()->GetMenuItem(1, &item); 476 menu()->GetMenuItem(1, &item);
489 EXPECT_EQ(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, item.command_id); 477 EXPECT_EQ(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, item.command_id);
490 } 478 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698