| 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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/prefs/pref_service_syncable.h" | 11 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 12 #include "chrome/browser/profiles/avatar_menu_model_observer.h" | 12 #include "chrome/browser/profiles/avatar_menu_model_observer.h" |
| 13 #include "chrome/browser/profiles/profile_info_cache.h" | 13 #include "chrome/browser/profiles/profile_info_cache.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profiles_state.h" |
| 15 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
| 16 #include "chrome/test/base/testing_profile_manager.h" | 16 #include "chrome/test/base/testing_profile_manager.h" |
| 17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 class MockObserver : public AvatarMenuModelObserver { | 23 class MockObserver : public AvatarMenuModelObserver { |
| 24 public: | 24 public: |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 EXPECT_EQ(name2, item2.name); | 175 EXPECT_EQ(name2, item2.name); |
| 176 | 176 |
| 177 const AvatarMenuModel::Item& item3 = model.GetItemAt(2); | 177 const AvatarMenuModel::Item& item3 = model.GetItemAt(2); |
| 178 EXPECT_EQ(2U, item3.model_index); | 178 EXPECT_EQ(2U, item3.model_index); |
| 179 EXPECT_EQ(name3, item3.name); | 179 EXPECT_EQ(name3, item3.name); |
| 180 } | 180 } |
| 181 | 181 |
| 182 TEST_F(AvatarMenuModelTest, ShowAvatarMenuInTrial) { | 182 TEST_F(AvatarMenuModelTest, ShowAvatarMenuInTrial) { |
| 183 // If multiprofile mode is not enabled, the trial will not be enabled, so it | 183 // If multiprofile mode is not enabled, the trial will not be enabled, so it |
| 184 // isn't tested. | 184 // isn't tested. |
| 185 if (!ProfileManager::IsMultipleProfilesEnabled()) | 185 if (!profiles::IsMultipleProfilesEnabled()) |
| 186 return; | 186 return; |
| 187 | 187 |
| 188 base::FieldTrialList field_trial_list_(NULL); | 188 base::FieldTrialList field_trial_list_(NULL); |
| 189 base::FieldTrialList::CreateFieldTrial("ShowProfileSwitcher", "AlwaysShow"); | 189 base::FieldTrialList::CreateFieldTrial("ShowProfileSwitcher", "AlwaysShow"); |
| 190 | 190 |
| 191 #if defined(OS_CHROMEOS) | 191 #if defined(OS_CHROMEOS) |
| 192 EXPECT_FALSE(AvatarMenuModel::ShouldShowAvatarMenu()); | 192 EXPECT_FALSE(AvatarMenuModel::ShouldShowAvatarMenu()); |
| 193 #else | 193 #else |
| 194 EXPECT_TRUE(AvatarMenuModel::ShouldShowAvatarMenu()); | 194 EXPECT_TRUE(AvatarMenuModel::ShouldShowAvatarMenu()); |
| 195 #endif | 195 #endif |
| 196 } | 196 } |
| 197 | 197 |
| 198 TEST_F(AvatarMenuModelTest, DontShowAvatarMenu) { | 198 TEST_F(AvatarMenuModelTest, DontShowAvatarMenu) { |
| 199 string16 name1(ASCIIToUTF16("Test 1")); | 199 string16 name1(ASCIIToUTF16("Test 1")); |
| 200 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), | 200 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), |
| 201 name1, 0); | 201 name1, 0); |
| 202 | 202 |
| 203 EXPECT_FALSE(AvatarMenuModel::ShouldShowAvatarMenu()); | 203 EXPECT_FALSE(AvatarMenuModel::ShouldShowAvatarMenu()); |
| 204 | 204 |
| 205 // If multiprofile mode is enabled, there are no other cases when we wouldn't | 205 // If multiprofile mode is enabled, there are no other cases when we wouldn't |
| 206 // show the menu. | 206 // show the menu. |
| 207 if (ProfileManager::IsMultipleProfilesEnabled()) | 207 if (profiles::IsMultipleProfilesEnabled()) |
| 208 return; | 208 return; |
| 209 | 209 |
| 210 string16 name2(ASCIIToUTF16("Test 2")); | 210 string16 name2(ASCIIToUTF16("Test 2")); |
| 211 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), | 211 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), |
| 212 name2, 0); | 212 name2, 0); |
| 213 | 213 |
| 214 EXPECT_FALSE(AvatarMenuModel::ShouldShowAvatarMenu()); | 214 EXPECT_FALSE(AvatarMenuModel::ShouldShowAvatarMenu()); |
| 215 } | 215 } |
| 216 | 216 |
| 217 TEST_F(AvatarMenuModelTest, ShowAvatarMenu) { | 217 TEST_F(AvatarMenuModelTest, ShowAvatarMenu) { |
| 218 // If multiprofile mode is not enabled then the menu is never shown. | 218 // If multiprofile mode is not enabled then the menu is never shown. |
| 219 if (!ProfileManager::IsMultipleProfilesEnabled()) | 219 if (!profiles::IsMultipleProfilesEnabled()) |
| 220 return; | 220 return; |
| 221 | 221 |
| 222 string16 name1(ASCIIToUTF16("Test 1")); | 222 string16 name1(ASCIIToUTF16("Test 1")); |
| 223 string16 name2(ASCIIToUTF16("Test 2")); | 223 string16 name2(ASCIIToUTF16("Test 2")); |
| 224 | 224 |
| 225 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), | 225 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), |
| 226 name1, 0); | 226 name1, 0); |
| 227 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), | 227 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), |
| 228 name2, 0); | 228 name2, 0); |
| 229 | 229 |
| 230 #if defined(OS_CHROMEOS) | 230 #if defined(OS_CHROMEOS) |
| 231 EXPECT_FALSE(AvatarMenuModel::ShouldShowAvatarMenu()); | 231 EXPECT_FALSE(AvatarMenuModel::ShouldShowAvatarMenu()); |
| 232 #else | 232 #else |
| 233 EXPECT_TRUE(AvatarMenuModel::ShouldShowAvatarMenu()); | 233 EXPECT_TRUE(AvatarMenuModel::ShouldShowAvatarMenu()); |
| 234 #endif | 234 #endif |
| 235 } | 235 } |
| 236 | 236 |
| 237 TEST_F(AvatarMenuModelTest, SyncState) { | 237 TEST_F(AvatarMenuModelTest, SyncState) { |
| 238 // If multiprofile mode is not enabled then the menu is never shown. | 238 // If multiprofile mode is not enabled then the menu is never shown. |
| 239 if (!ProfileManager::IsMultipleProfilesEnabled()) | 239 if (!profiles::IsMultipleProfilesEnabled()) |
| 240 return; | 240 return; |
| 241 | 241 |
| 242 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), | 242 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), |
| 243 ASCIIToUTF16("Test 1"), 0); | 243 ASCIIToUTF16("Test 1"), 0); |
| 244 | 244 |
| 245 // Add a managed user profile. | 245 // Add a managed user profile. |
| 246 ProfileInfoCache* cache = manager()->profile_info_cache(); | 246 ProfileInfoCache* cache = manager()->profile_info_cache(); |
| 247 manager()->profile_info_cache()->AddProfileToCache( | 247 manager()->profile_info_cache()->AddProfileToCache( |
| 248 cache->GetUserDataDir().AppendASCII("p2"), ASCIIToUTF16("Test 2"), | 248 cache->GetUserDataDir().AppendASCII("p2"), ASCIIToUTF16("Test 2"), |
| 249 string16(), 0, true); | 249 string16(), 0, true); |
| 250 MockObserver observer; | 250 MockObserver observer; |
| 251 AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser()); | 251 AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser()); |
| 252 EXPECT_EQ(2U, model.GetNumberOfItems()); | 252 EXPECT_EQ(2U, model.GetNumberOfItems()); |
| 253 | 253 |
| 254 // Now check that the sync_state of a managed user shows the managed user | 254 // Now check that the sync_state of a managed user shows the managed user |
| 255 // avatar label instead. | 255 // avatar label instead. |
| 256 base::string16 managed_user_label = | 256 base::string16 managed_user_label = |
| 257 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL); | 257 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL); |
| 258 const AvatarMenuModel::Item& item1 = model.GetItemAt(0); | 258 const AvatarMenuModel::Item& item1 = model.GetItemAt(0); |
| 259 EXPECT_NE(item1.sync_state, managed_user_label); | 259 EXPECT_NE(item1.sync_state, managed_user_label); |
| 260 | 260 |
| 261 const AvatarMenuModel::Item& item2 = model.GetItemAt(1); | 261 const AvatarMenuModel::Item& item2 = model.GetItemAt(1); |
| 262 EXPECT_EQ(item2.sync_state, managed_user_label); | 262 EXPECT_EQ(item2.sync_state, managed_user_label); |
| 263 } | 263 } |
| 264 | 264 |
| 265 } // namespace | 265 } // namespace |
| OLD | NEW |