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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/preferences.h"
7 #include "base/prefs/pref_member.h"
8 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h"
9 #include "chrome/browser/download/download_prefs.h"
10 #include "chrome/common/pref_names.h"
11 #include "chrome/test/base/testing_pref_service_syncable.h"
12 #include "components/user_prefs/pref_registry_syncable.h"
13 #include "testing/gtest/include/gtest/gtest.h"
18 class MyMockInputMethodManager
: public input_method::MockInputMethodManager
{
20 MyMockInputMethodManager(StringPrefMember
* previous
,
21 StringPrefMember
* current
)
22 : previous_(previous
),
25 virtual ~MyMockInputMethodManager() {
28 virtual void ChangeInputMethod(const std::string
& input_method_id
) OVERRIDE
{
29 last_input_method_id_
= input_method_id
;
30 // Do the same thing as BrowserStateMonitor::UpdateUserPreferences.
31 const std::string current_input_method_on_pref
= current_
->GetValue();
32 if (current_input_method_on_pref
== input_method_id
)
34 previous_
->SetValue(current_input_method_on_pref
);
35 current_
->SetValue(input_method_id
);
38 std::string last_input_method_id_
;
41 StringPrefMember
* previous_
;
42 StringPrefMember
* current_
;
45 } // anonymous namespace
47 TEST(PreferencesTest
, TestUpdatePrefOnBrowserScreenDetails
) {
48 TestingPrefServiceSyncable prefs
;
49 Preferences::RegisterProfilePrefs(prefs
.registry());
50 DownloadPrefs::RegisterProfilePrefs(prefs
.registry());
51 // kSelectFileLastDirectory is registered for Profile. Here we register it for
53 prefs
.registry()->RegisterStringPref(
54 prefs::kSelectFileLastDirectory
,
56 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
58 StringPrefMember previous
;
59 previous
.Init(prefs::kLanguagePreviousInputMethod
, &prefs
);
60 previous
.SetValue("KeyboardA");
61 StringPrefMember current
;
62 current
.Init(prefs::kLanguageCurrentInputMethod
, &prefs
);
63 current
.SetValue("KeyboardB");
65 MyMockInputMethodManager
mock_manager(&previous
, ¤t
);
66 Preferences
testee(&mock_manager
);
67 testee
.InitUserPrefsForTesting(&prefs
);
68 testee
.SetInputMethodListForTesting();
70 // Confirm they're unchanged.
71 EXPECT_EQ("KeyboardA", previous
.GetValue());
72 EXPECT_EQ("KeyboardB", current
.GetValue());
73 EXPECT_EQ("KeyboardB", mock_manager
.last_input_method_id_
);
76 } // namespace chromeos