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