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

Side by Side Diff: chrome/browser/chromeos/input_method/input_method_persistence_unittest.cc

Issue 442043002: ProfileManager doesn't depend on "--login-profile" switch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More tests fixed. Created 6 years, 4 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/chromeos/input_method/input_method_persistence.h" 5 #include "chrome/browser/chromeos/input_method/input_method_persistence.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" 9 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h"
10 #include "chrome/browser/chromeos/language_preferences.h" 10 #include "chrome/browser/chromeos/language_preferences.h"
11 #include "chrome/browser/chromeos/login/users/fake_user_manager.h"
12 #include "chrome/browser/chromeos/profiles/profile_helper.h"
11 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/common/chrome_constants.h" 14 #include "chrome/common/chrome_constants.h"
13 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
15 #include "chrome/test/base/testing_browser_process.h" 17 #include "chrome/test/base/testing_browser_process.h"
16 #include "chrome/test/base/testing_pref_service_syncable.h" 18 #include "chrome/test/base/testing_pref_service_syncable.h"
17 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
18 #include "chrome/test/base/testing_profile_manager.h" 20 #include "chrome/test/base/testing_profile_manager.h"
19 #include "chromeos/chromeos_switches.h" 21 #include "chromeos/chromeos_switches.h"
20 22
21 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
22 24
23 namespace chromeos { 25 namespace chromeos {
24 namespace input_method { 26 namespace input_method {
25 27
26 namespace { 28 namespace {
27 const char kInputId1[] = "xkb:us:dvorak:eng"; 29 const char kInputId1[] = "xkb:us:dvorak:eng";
28 const char kInputId2[] = "xkb:us:colemak:eng"; 30 const char kInputId2[] = "xkb:us:colemak:eng";
29 } 31 }
30 32
31 class InputMethodPersistenceTest : public testing::Test { 33 class InputMethodPersistenceTest : public testing::Test {
32 protected: 34 protected:
33 InputMethodPersistenceTest() 35 InputMethodPersistenceTest()
34 : mock_profile_manager_(TestingBrowserProcess::GetGlobal()) {} 36 : mock_profile_manager_(TestingBrowserProcess::GetGlobal()),
37 fake_user_manager_(new chromeos::FakeUserManager()),
38 user_manager_enabler_(fake_user_manager_) {}
35 39
36 virtual void SetUp() OVERRIDE { 40 virtual void SetUp() OVERRIDE {
37 // Set up a valid profile for our test.
38 ASSERT_TRUE(mock_profile_manager_.SetUp()); 41 ASSERT_TRUE(mock_profile_manager_.SetUp());
42
43 // Add a user.
44 const char kTestUserName[] = "test-user@example.com";
45 fake_user_manager_->AddUser(kTestUserName);
46 fake_user_manager_->LoginUser(kTestUserName);
47
48 // Create a valid profile for the user.
39 TestingProfile* mock_profile = 49 TestingProfile* mock_profile =
40 mock_profile_manager_.CreateTestingProfile(chrome::kTestUserProfileDir); 50 mock_profile_manager_.CreateTestingProfile(kTestUserName);
41 CommandLine *cl = CommandLine::ForCurrentProcess();
42 cl->AppendSwitchASCII(switches::kLoginProfile, chrome::kTestUserProfileDir);
43 mock_profile_manager_.SetLoggedIn(true); 51 mock_profile_manager_.SetLoggedIn(true);
44 EXPECT_TRUE(ProfileManager::GetActiveUserProfile() != NULL); 52 EXPECT_TRUE(ProfileManager::GetActiveUserProfile() == mock_profile);
53
45 mock_user_prefs_ = mock_profile->GetTestingPrefService(); 54 mock_user_prefs_ = mock_profile->GetTestingPrefService();
46 } 55 }
47 56
48 // Verifies that the user and system prefs contain the expected values. 57 // Verifies that the user and system prefs contain the expected values.
49 void VerifyPrefs(const std::string& current_input_method, 58 void VerifyPrefs(const std::string& current_input_method,
50 const std::string& previous_input_method, 59 const std::string& previous_input_method,
51 const std::string& preferred_keyboard_layout) { 60 const std::string& preferred_keyboard_layout) {
52 EXPECT_EQ(current_input_method, 61 EXPECT_EQ(current_input_method,
53 mock_user_prefs_->GetString(prefs::kLanguageCurrentInputMethod)); 62 mock_user_prefs_->GetString(prefs::kLanguageCurrentInputMethod));
54 EXPECT_EQ(previous_input_method, 63 EXPECT_EQ(previous_input_method,
55 mock_user_prefs_->GetString(prefs::kLanguagePreviousInputMethod)); 64 mock_user_prefs_->GetString(prefs::kLanguagePreviousInputMethod));
56 EXPECT_EQ(preferred_keyboard_layout, 65 EXPECT_EQ(preferred_keyboard_layout,
57 g_browser_process->local_state()->GetString( 66 g_browser_process->local_state()->GetString(
58 language_prefs::kPreferredKeyboardLayout)); 67 language_prefs::kPreferredKeyboardLayout));
59 } 68 }
60 69
61 TestingPrefServiceSyncable* mock_user_prefs_; 70 TestingPrefServiceSyncable* mock_user_prefs_;
62 MockInputMethodManager mock_manager_; 71 MockInputMethodManager mock_manager_;
63 TestingProfileManager mock_profile_manager_; 72 TestingProfileManager mock_profile_manager_;
73 chromeos::FakeUserManager* fake_user_manager_;
74 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
64 }; 75 };
65 76
66 TEST_F(InputMethodPersistenceTest, TestLifetime) { 77 TEST_F(InputMethodPersistenceTest, TestLifetime) {
67 { 78 {
68 InputMethodPersistence persistence(&mock_manager_); 79 InputMethodPersistence persistence(&mock_manager_);
69 EXPECT_EQ(1, mock_manager_.add_observer_count_); 80 EXPECT_EQ(1, mock_manager_.add_observer_count_);
70 } 81 }
71 EXPECT_EQ(1, mock_manager_.remove_observer_count_); 82 EXPECT_EQ(1, mock_manager_.remove_observer_count_);
72 } 83 }
73 84
(...skipping 26 matching lines...) Expand all
100 VerifyPrefs(kInputId2, "", kInputId2); 111 VerifyPrefs(kInputId2, "", kInputId2);
101 112
102 persistence.OnSessionStateChange(InputMethodManager::STATE_BROWSER_SCREEN); 113 persistence.OnSessionStateChange(InputMethodManager::STATE_BROWSER_SCREEN);
103 mock_manager_.SetCurrentInputMethodId(kInputId1); 114 mock_manager_.SetCurrentInputMethodId(kInputId1);
104 persistence.InputMethodChanged(&mock_manager_, false); 115 persistence.InputMethodChanged(&mock_manager_, false);
105 VerifyPrefs(kInputId1, kInputId2, kInputId2); 116 VerifyPrefs(kInputId1, kInputId2, kInputId2);
106 } 117 }
107 118
108 } // namespace input_method 119 } // namespace input_method
109 } // namespace chromeos 120 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698