OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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. |
| 4 |
| 5 #include <string> |
| 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/notifications/message_center_settings_controller.h" |
| 9 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 10 #include "chrome/browser/profiles/profile_info_cache.h" |
| 11 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "chrome/test/base/testing_browser_process.h" |
| 13 #include "chrome/test/base/testing_profile_manager.h" |
| 14 #include "content/public/test/test_browser_thread_bundle.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "ui/message_center/notifier_settings.h" |
| 17 |
| 18 class MessageCenterSettingsControllerTest : public testing::Test { |
| 19 protected: |
| 20 MessageCenterSettingsControllerTest() |
| 21 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {}; |
| 22 virtual ~MessageCenterSettingsControllerTest() {}; |
| 23 |
| 24 base::FilePath GetProfilePath(const std::string& base_name) { |
| 25 return testing_profile_manager_.profile_manager()->user_data_dir() |
| 26 .AppendASCII(base_name); |
| 27 } |
| 28 |
| 29 virtual void SetUp() OVERRIDE { |
| 30 ASSERT_TRUE(testing_profile_manager_.SetUp()); |
| 31 } |
| 32 |
| 33 ProfileInfoCache* GetCache() { |
| 34 return testing_profile_manager_.profile_info_cache(); |
| 35 } |
| 36 |
| 37 void ResetCache() { testing_profile_manager_.DeleteProfileInfoCache(); } |
| 38 |
| 39 void CreateProfile(const std::string& name, const string16& login_info) { |
| 40 testing_profile_manager_.CreateTestingProfile( |
| 41 name, scoped_ptr<PrefServiceSyncable>(), login_info, 0, false); |
| 42 } |
| 43 |
| 44 TestingProfileManager testing_profile_manager_; |
| 45 |
| 46 private: |
| 47 content::TestBrowserThreadBundle thread_bundle_; |
| 48 }; |
| 49 |
| 50 TEST_F(MessageCenterSettingsControllerTest, NotifierGroups) { |
| 51 CreateProfile("Profile-1", UTF8ToUTF16("email@one.com")); |
| 52 CreateProfile("Profile-2", UTF8ToUTF16("email@two.com")); |
| 53 |
| 54 scoped_ptr<MessageCenterSettingsController> controller( |
| 55 new MessageCenterSettingsController(GetCache())); |
| 56 |
| 57 EXPECT_EQ(controller->GetNotifierGroupCount(), 2); |
| 58 |
| 59 EXPECT_EQ(controller->GetNotifierGroupAt(0).name, UTF8ToUTF16("Profile-1")); |
| 60 EXPECT_EQ(controller->GetNotifierGroupAt(0).login_info, |
| 61 UTF8ToUTF16("email@one.com")); |
| 62 EXPECT_EQ(controller->GetNotifierGroupAt(0).index, 0); |
| 63 |
| 64 EXPECT_EQ(controller->GetNotifierGroupAt(1).name, UTF8ToUTF16("Profile-2")); |
| 65 EXPECT_EQ(controller->GetNotifierGroupAt(1).login_info, |
| 66 UTF8ToUTF16("email@two.com")); |
| 67 EXPECT_EQ(controller->GetNotifierGroupAt(1).index, 1); |
| 68 |
| 69 EXPECT_EQ(controller->GetActiveNotifierGroup().name, |
| 70 UTF8ToUTF16("Profile-1")); |
| 71 EXPECT_EQ(controller->GetActiveNotifierGroup().login_info, |
| 72 UTF8ToUTF16("email@one.com")); |
| 73 EXPECT_EQ(controller->GetActiveNotifierGroup().index, 0); |
| 74 |
| 75 controller->SwitchToNotifierGroup(1); |
| 76 EXPECT_EQ(controller->GetActiveNotifierGroup().name, |
| 77 UTF8ToUTF16("Profile-2")); |
| 78 EXPECT_EQ(controller->GetActiveNotifierGroup().login_info, |
| 79 UTF8ToUTF16("email@two.com")); |
| 80 EXPECT_EQ(controller->GetActiveNotifierGroup().index, 1); |
| 81 |
| 82 controller->SwitchToNotifierGroup(0); |
| 83 EXPECT_EQ(controller->GetActiveNotifierGroup().name, |
| 84 UTF8ToUTF16("Profile-1")); |
| 85 } |
OLD | NEW |