OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/profiles/avatar_menu_model.h" | 5 #include "chrome/browser/profiles/avatar_menu_model.h" |
6 | 6 |
| 7 #include "base/metrics/field_trial.h" |
7 #include "base/string16.h" | 8 #include "base/string16.h" |
8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/profiles/avatar_menu_model_observer.h" | 10 #include "chrome/browser/profiles/avatar_menu_model_observer.h" |
10 #include "chrome/browser/profiles/profile_info_cache.h" | 11 #include "chrome/browser/profiles/profile_info_cache.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" |
11 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
12 #include "chrome/test/base/testing_profile_manager.h" | 14 #include "chrome/test/base/testing_profile_manager.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 class MockObserver : public AvatarMenuModelObserver { | 19 class MockObserver : public AvatarMenuModelObserver { |
18 public: | 20 public: |
19 MockObserver() : count_(0) {} | 21 MockObserver() : count_(0) {} |
20 virtual ~MockObserver() {} | 22 virtual ~MockObserver() {} |
(...skipping 16 matching lines...) Expand all Loading... |
37 } | 39 } |
38 | 40 |
39 virtual void SetUp() { | 41 virtual void SetUp() { |
40 ASSERT_TRUE(manager_.SetUp()); | 42 ASSERT_TRUE(manager_.SetUp()); |
41 #if defined(OS_CHROMEOS) | 43 #if defined(OS_CHROMEOS) |
42 // AvatarMenu and multiple profiles works after user logged in. | 44 // AvatarMenu and multiple profiles works after user logged in. |
43 manager_.SetLoggedIn(true); | 45 manager_.SetLoggedIn(true); |
44 #endif | 46 #endif |
45 } | 47 } |
46 | 48 |
| 49 virtual void TearDown() { |
| 50 // Some tests force IsMultipleProfilesEnabled to return a particular |
| 51 // value. We make sure it's always set back to a normal state. |
| 52 ProfileManager::UnforceMultipleProfilesForTests(); |
| 53 } |
| 54 |
47 Browser* browser() { return NULL; } | 55 Browser* browser() { return NULL; } |
48 | 56 |
49 TestingProfileManager* manager() { return &manager_; } | 57 TestingProfileManager* manager() { return &manager_; } |
50 | 58 |
51 private: | 59 private: |
52 TestingProfileManager manager_; | 60 TestingProfileManager manager_; |
53 }; | 61 }; |
54 | 62 |
55 TEST_F(AvatarMenuModelTest, InitialCreation) { | 63 TEST_F(AvatarMenuModelTest, InitialCreation) { |
56 string16 name1(ASCIIToUTF16("Test 1")); | 64 string16 name1(ASCIIToUTF16("Test 1")); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 165 |
158 const AvatarMenuModel::Item& item2 = model.GetItemAt(1); | 166 const AvatarMenuModel::Item& item2 = model.GetItemAt(1); |
159 EXPECT_EQ(1U, item2.model_index); | 167 EXPECT_EQ(1U, item2.model_index); |
160 EXPECT_EQ(name2, item2.name); | 168 EXPECT_EQ(name2, item2.name); |
161 | 169 |
162 const AvatarMenuModel::Item& item3 = model.GetItemAt(2); | 170 const AvatarMenuModel::Item& item3 = model.GetItemAt(2); |
163 EXPECT_EQ(2U, item3.model_index); | 171 EXPECT_EQ(2U, item3.model_index); |
164 EXPECT_EQ(name3, item3.name); | 172 EXPECT_EQ(name3, item3.name); |
165 } | 173 } |
166 | 174 |
| 175 // Tests for ShouldShowAvatarMenu are only applicable when multiple profiles is |
| 176 // enabled, so for these tests we force it to be enabled. |
| 177 TEST_F(AvatarMenuModelTest, ShowAvatarMenuInTrial) { |
| 178 ProfileManager::ForceMultipleProfilesForTests(true); |
| 179 base::FieldTrialList field_trial_list_(NULL); |
| 180 base::FieldTrialList::CreateFieldTrial("ShowProfileSwitcher", "AlwaysShow"); |
| 181 |
| 182 EXPECT_TRUE(AvatarMenuModel::ShouldShowAvatarMenu()); |
| 183 } |
| 184 |
| 185 TEST_F(AvatarMenuModelTest, DontShowAvatarMenu) { |
| 186 ProfileManager::ForceMultipleProfilesForTests(true); |
| 187 string16 name1(ASCIIToUTF16("Test 1")); |
| 188 manager()->CreateTestingProfile("p1", name1, 0); |
| 189 |
| 190 EXPECT_FALSE(AvatarMenuModel::ShouldShowAvatarMenu()); |
| 191 |
| 192 ProfileManager::ForceMultipleProfilesForTests(false); |
| 193 string16 name2(ASCIIToUTF16("Test 2")); |
| 194 manager()->CreateTestingProfile("p2", name2, 0); |
| 195 |
| 196 EXPECT_FALSE(AvatarMenuModel::ShouldShowAvatarMenu()); |
| 197 } |
| 198 |
| 199 TEST_F(AvatarMenuModelTest, ShowAvatarMenu) { |
| 200 ProfileManager::ForceMultipleProfilesForTests(true); |
| 201 string16 name1(ASCIIToUTF16("Test 1")); |
| 202 string16 name2(ASCIIToUTF16("Test 2")); |
| 203 |
| 204 manager()->CreateTestingProfile("p1", name1, 0); |
| 205 manager()->CreateTestingProfile("p2", name2, 0); |
| 206 |
| 207 EXPECT_TRUE(AvatarMenuModel::ShouldShowAvatarMenu()); |
| 208 } |
| 209 |
167 } // namespace | 210 } // namespace |
OLD | NEW |