Update mojo surfaces bindings and mojo/cc/ glue
[chromium-blink-merge.git] / chrome / browser / notifications / message_center_settings_controller_unittest.cc
blob750f29f47c5fbfcc37485bd2d16b7ceee19a460a
1 // Copyright 2013 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 <string>
7 #include "base/command_line.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/notifications/message_center_settings_controller.h"
10 #include "chrome/browser/prefs/pref_service_syncable.h"
11 #include "chrome/browser/profiles/profile_info_cache.h"
12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/test/base/testing_browser_process.h"
14 #include "chrome/test/base/testing_profile_manager.h"
15 #include "content/public/test/test_browser_thread_bundle.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "ui/message_center/notifier_settings.h"
19 #if defined(OS_CHROMEOS)
20 #include "chrome/browser/chromeos/login/users/fake_user_manager.h"
21 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
22 #endif
24 class MessageCenterSettingsControllerTest : public testing::Test {
25 protected:
26 MessageCenterSettingsControllerTest()
27 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {};
28 virtual ~MessageCenterSettingsControllerTest() {};
30 base::FilePath GetProfilePath(const std::string& base_name) {
31 return testing_profile_manager_.profile_manager()->user_data_dir()
32 .AppendASCII(base_name);
35 virtual void SetUp() OVERRIDE {
36 ASSERT_TRUE(testing_profile_manager_.SetUp());
39 virtual void CreateProfile(const std::string& name) {
40 testing_profile_manager_.CreateTestingProfile(name);
43 void CreateController() {
44 controller_.reset(new MessageCenterSettingsController(
45 testing_profile_manager_.profile_info_cache()));
48 void ResetController() {
49 controller_.reset();
52 MessageCenterSettingsController* controller() { return controller_.get(); }
54 private:
55 TestingProfileManager testing_profile_manager_;
56 scoped_ptr<MessageCenterSettingsController> controller_;
57 content::TestBrowserThreadBundle thread_bundle_;
59 DISALLOW_COPY_AND_ASSIGN(MessageCenterSettingsControllerTest);
62 #if defined(OS_CHROMEOS)
63 // This value should be same as the one in fake_user_manager.cc
64 static const char kUserIdHashSuffix[] = "-hash";
66 class MessageCenterSettingsControllerChromeOSTest
67 : public MessageCenterSettingsControllerTest {
68 protected:
69 MessageCenterSettingsControllerChromeOSTest() {}
70 virtual ~MessageCenterSettingsControllerChromeOSTest() {}
72 virtual void SetUp() OVERRIDE {
73 MessageCenterSettingsControllerTest::SetUp();
75 // Initialize the UserManager singleton to a fresh FakeUserManager instance.
76 user_manager_enabler_.reset(
77 new chromeos::ScopedUserManagerEnabler(new chromeos::FakeUserManager));
80 virtual void TearDown() OVERRIDE {
81 ResetController();
82 MessageCenterSettingsControllerTest::TearDown();
85 virtual void CreateProfile(const std::string& name) OVERRIDE {
86 MessageCenterSettingsControllerTest::CreateProfile(name);
88 GetFakeUserManager()->AddUser(name);
89 GetFakeUserManager()->UserLoggedIn(name, name + kUserIdHashSuffix, false);
92 void SwitchActiveUser(const std::string& name) {
93 GetFakeUserManager()->SwitchActiveUser(name);
94 controller()->ActiveUserChanged(GetFakeUserManager()->GetActiveUser());
97 private:
98 chromeos::FakeUserManager* GetFakeUserManager() {
99 return static_cast<chromeos::FakeUserManager*>(
100 user_manager::UserManager::Get());
103 scoped_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_;
105 DISALLOW_COPY_AND_ASSIGN(MessageCenterSettingsControllerChromeOSTest);
107 #endif // OS_CHROMEOS
109 #if !defined(OS_CHROMEOS)
110 TEST_F(MessageCenterSettingsControllerTest, NotifierGroups) {
111 CreateProfile("Profile-1");
112 CreateProfile("Profile-2");
113 CreateController();
115 EXPECT_EQ(controller()->GetNotifierGroupCount(), 2u);
117 EXPECT_EQ(controller()->GetNotifierGroupAt(0).name,
118 base::UTF8ToUTF16("Profile-1"));
119 EXPECT_EQ(controller()->GetNotifierGroupAt(0).index, 0u);
121 EXPECT_EQ(controller()->GetNotifierGroupAt(1).name,
122 base::UTF8ToUTF16("Profile-2"));
123 EXPECT_EQ(controller()->GetNotifierGroupAt(1).index, 1u);
125 EXPECT_EQ(controller()->GetActiveNotifierGroup().name,
126 base::UTF8ToUTF16("Profile-1"));
127 EXPECT_EQ(controller()->GetActiveNotifierGroup().index, 0u);
129 controller()->SwitchToNotifierGroup(1);
130 EXPECT_EQ(controller()->GetActiveNotifierGroup().name,
131 base::UTF8ToUTF16("Profile-2"));
132 EXPECT_EQ(controller()->GetActiveNotifierGroup().index, 1u);
134 controller()->SwitchToNotifierGroup(0);
135 EXPECT_EQ(controller()->GetActiveNotifierGroup().name,
136 base::UTF8ToUTF16("Profile-1"));
138 #else
139 TEST_F(MessageCenterSettingsControllerChromeOSTest, NotifierGroups) {
140 CreateProfile("Profile-1");
141 CreateProfile("Profile-2");
142 CreateController();
144 EXPECT_EQ(controller()->GetNotifierGroupCount(), 1u);
146 EXPECT_EQ(controller()->GetNotifierGroupAt(0).name,
147 base::UTF8ToUTF16("Profile-1"));
148 EXPECT_EQ(controller()->GetNotifierGroupAt(0).index, 0u);
150 SwitchActiveUser("Profile-2");
151 EXPECT_EQ(controller()->GetNotifierGroupCount(), 1u);
152 EXPECT_EQ(controller()->GetNotifierGroupAt(0).name,
153 base::UTF8ToUTF16("Profile-2"));
154 EXPECT_EQ(controller()->GetNotifierGroupAt(0).index, 1u);
156 SwitchActiveUser("Profile-1");
157 EXPECT_EQ(controller()->GetNotifierGroupCount(), 1u);
158 EXPECT_EQ(controller()->GetNotifierGroupAt(0).name,
159 base::UTF8ToUTF16("Profile-1"));
160 EXPECT_EQ(controller()->GetNotifierGroupAt(0).index, 0u);
162 #endif
164 // TODO(mukai): write a test case to reproduce the actual guest session scenario
165 // in ChromeOS -- no profiles in the profile_info_cache.