Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 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. |
| 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 CreateProfile(const std::string& name) { |
| 38 | testing_profile_manager_.CreateTestingProfile(name); |
| 39 | } |
| 40 | |
| 41 | TestingProfileManager testing_profile_manager_; |
| 42 | }; |
| 43 | |
| 44 | TEST_F(MessageCenterSettingsControllerTest, NotifierGroups) { |
| 45 | CreateProfile("Profile-1"); |
| 46 | CreateProfile("Profile-2"); |
| 47 | |
| 48 | scoped_ptr<MessageCenterSettingsController> controller( |
| 49 | new MessageCenterSettingsController(GetCache())); |
| 50 | |
| 51 | EXPECT_EQ(controller->GetNotifierGroupCount(), 2u); |
| 52 | |
| 53 | EXPECT_EQ(controller->GetNotifierGroupAt(0).name, UTF8ToUTF16("Profile-1")); |
| 54 | EXPECT_EQ(controller->GetNotifierGroupAt(0).index, 0u); |
| 55 | |
| 56 | EXPECT_EQ(controller->GetNotifierGroupAt(1).name, UTF8ToUTF16("Profile-2")); |
| 57 | EXPECT_EQ(controller->GetNotifierGroupAt(1).index, 1u); |
| 58 | |
| 59 | EXPECT_EQ(controller->GetActiveNotifierGroup().name, |
| 60 | UTF8ToUTF16("Profile-1")); |
| 61 | EXPECT_EQ(controller->GetActiveNotifierGroup().index, 0u); |
| 62 | |
| 63 | controller->SwitchToNotifierGroup(1); |
| 64 | EXPECT_EQ(controller->GetActiveNotifierGroup().name, |
| 65 | UTF8ToUTF16("Profile-2")); |
| 66 | EXPECT_EQ(controller->GetActiveNotifierGroup().index, 1u); |
| 67 | |
| 68 | controller->SwitchToNotifierGroup(0); |
| 69 | EXPECT_EQ(controller->GetActiveNotifierGroup().name, |
| 70 | UTF8ToUTF16("Profile-1")); |
| 71 | } |