Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / chromeos / preferences_unittest.cc
blobab02c749351ac103a073abde2110ec308a5586c9
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/chromeos/login/fake_user_manager.h"
10 #include "chrome/browser/chromeos/login/user_manager.h"
11 #include "chrome/browser/download/download_prefs.h"
12 #include "chrome/common/pref_names.h"
13 #include "chrome/test/base/testing_pref_service_syncable.h"
14 #include "components/user_prefs/pref_registry_syncable.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace chromeos {
18 namespace {
20 class MyMockInputMethodManager : public input_method::MockInputMethodManager {
21 public:
22 MyMockInputMethodManager(StringPrefMember* previous,
23 StringPrefMember* current)
24 : previous_(previous),
25 current_(current) {
27 virtual ~MyMockInputMethodManager() {
30 virtual void ChangeInputMethod(const std::string& input_method_id) OVERRIDE {
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);
40 std::string last_input_method_id_;
42 private:
43 StringPrefMember* previous_;
44 StringPrefMember* current_;
47 } // anonymous namespace
49 TEST(PreferencesTest, TestUpdatePrefOnBrowserScreenDetails) {
50 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager();
51 chromeos::ScopedUserManagerEnabler user_manager_enabler(user_manager);
52 const char test_user_email[] = "test_user@example.com";
53 const User* test_user = user_manager->AddUser(test_user_email);
54 user_manager->LoginUser(test_user_email);
56 TestingPrefServiceSyncable prefs;
57 Preferences::RegisterProfilePrefs(prefs.registry());
58 DownloadPrefs::RegisterProfilePrefs(prefs.registry());
59 // kSelectFileLastDirectory is registered for Profile. Here we register it for
60 // testing.
61 prefs.registry()->RegisterStringPref(
62 prefs::kSelectFileLastDirectory,
63 std::string(),
64 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
66 StringPrefMember previous;
67 previous.Init(prefs::kLanguagePreviousInputMethod, &prefs);
68 previous.SetValue("KeyboardA");
69 StringPrefMember current;
70 current.Init(prefs::kLanguageCurrentInputMethod, &prefs);
71 current.SetValue("KeyboardB");
73 MyMockInputMethodManager mock_manager(&previous, &current);
74 Preferences testee(&mock_manager);
75 testee.InitUserPrefsForTesting(&prefs, test_user);
76 testee.SetInputMethodListForTesting();
78 // Confirm they're unchanged.
79 EXPECT_EQ("KeyboardA", previous.GetValue());
80 EXPECT_EQ("KeyboardB", current.GetValue());
81 EXPECT_EQ("KeyboardB", mock_manager.last_input_method_id_);
84 } // namespace chromeos