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/preferences.h" | 5 #include "chrome/browser/chromeos/preferences.h" |
6 | 6 |
7 #include "base/prefs/pref_member.h" | 7 #include "base/prefs/pref_member.h" |
8 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" | 8 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" |
9 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" | 9 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" |
10 #include "chrome/browser/chromeos/login/users/user_manager.h" | 10 #include "chrome/browser/chromeos/login/users/user_manager.h" |
11 #include "chrome/browser/download/download_prefs.h" | 11 #include "chrome/browser/download/download_prefs.h" |
12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
13 #include "chrome/test/base/testing_pref_service_syncable.h" | 13 #include "chrome/test/base/testing_pref_service_syncable.h" |
14 #include "components/pref_registry/pref_registry_syncable.h" | 14 #include "components/pref_registry/pref_registry_syncable.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 namespace chromeos { | 17 namespace chromeos { |
18 namespace { | 18 namespace { |
19 | 19 |
20 class MyMockInputMethodManager : public input_method::MockInputMethodManager { | 20 class MyMockInputMethodManager : public input_method::MockInputMethodManager { |
21 public: | 21 public: |
| 22 class State : public MockInputMethodManager::State { |
| 23 public: |
| 24 explicit State(MyMockInputMethodManager* manager) : manager_(manager) {}; |
| 25 virtual ~State() {}; |
| 26 |
| 27 virtual void ChangeInputMethod(const std::string& input_method_id, |
| 28 bool show_message) OVERRIDE { |
| 29 manager_->last_input_method_id_ = input_method_id; |
| 30 // Do the same thing as BrowserStateMonitor::UpdateUserPreferences. |
| 31 const std::string current_input_method_on_pref = |
| 32 manager_->current_->GetValue(); |
| 33 if (current_input_method_on_pref == input_method_id) |
| 34 return; |
| 35 manager_->previous_->SetValue(current_input_method_on_pref); |
| 36 manager_->current_->SetValue(input_method_id); |
| 37 } |
| 38 |
| 39 private: |
| 40 MyMockInputMethodManager* const manager_; |
| 41 }; |
| 42 |
22 MyMockInputMethodManager(StringPrefMember* previous, | 43 MyMockInputMethodManager(StringPrefMember* previous, |
23 StringPrefMember* current) | 44 StringPrefMember* current) |
24 : previous_(previous), | 45 : previous_(previous), |
25 current_(current) { | 46 current_(current) { |
26 } | 47 state_ = new State(this); |
27 virtual ~MyMockInputMethodManager() { | |
28 } | 48 } |
29 | 49 |
30 virtual void ChangeInputMethod(const std::string& input_method_id) OVERRIDE { | 50 virtual ~MyMockInputMethodManager() {} |
31 last_input_method_id_ = input_method_id; | |
32 // Do the same thing as BrowserStateMonitor::UpdateUserPreferences. | |
33 const std::string current_input_method_on_pref = current_->GetValue(); | |
34 if (current_input_method_on_pref == input_method_id) | |
35 return; | |
36 previous_->SetValue(current_input_method_on_pref); | |
37 current_->SetValue(input_method_id); | |
38 } | |
39 | 51 |
40 std::string last_input_method_id_; | 52 std::string last_input_method_id_; |
41 | 53 |
42 private: | 54 private: |
43 StringPrefMember* previous_; | 55 StringPrefMember* previous_; |
44 StringPrefMember* current_; | 56 StringPrefMember* current_; |
45 }; | 57 }; |
46 | 58 |
47 } // anonymous namespace | 59 } // anonymous namespace |
48 | 60 |
(...skipping 26 matching lines...) Expand all Loading... |
75 testee.InitUserPrefsForTesting(&prefs, test_user); | 87 testee.InitUserPrefsForTesting(&prefs, test_user); |
76 testee.SetInputMethodListForTesting(); | 88 testee.SetInputMethodListForTesting(); |
77 | 89 |
78 // Confirm they're unchanged. | 90 // Confirm they're unchanged. |
79 EXPECT_EQ("KeyboardA", previous.GetValue()); | 91 EXPECT_EQ("KeyboardA", previous.GetValue()); |
80 EXPECT_EQ("KeyboardB", current.GetValue()); | 92 EXPECT_EQ("KeyboardB", current.GetValue()); |
81 EXPECT_EQ("KeyboardB", mock_manager.last_input_method_id_); | 93 EXPECT_EQ("KeyboardB", mock_manager.last_input_method_id_); |
82 } | 94 } |
83 | 95 |
84 } // namespace chromeos | 96 } // namespace chromeos |
OLD | NEW |