OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #import "chrome/browser/ui/cocoa/profiles/profile_menu_controller.h" | 5 #import "chrome/browser/ui/cocoa/profiles/profile_menu_controller.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 // BrowserWindow, so it is called manually. | 198 // BrowserWindow, so it is called manually. |
199 TEST_F(ProfileMenuControllerTest, SetActiveAndRemove) { | 199 TEST_F(ProfileMenuControllerTest, SetActiveAndRemove) { |
200 NSMenu* menu = [controller() menu]; | 200 NSMenu* menu = [controller() menu]; |
201 TestingProfileManager* manager = testing_profile_manager(); | 201 TestingProfileManager* manager = testing_profile_manager(); |
202 TestingProfile* profile2 = manager->CreateTestingProfile("Profile 2"); | 202 TestingProfile* profile2 = manager->CreateTestingProfile("Profile 2"); |
203 TestingProfile* profile3 = manager->CreateTestingProfile("Profile 3"); | 203 TestingProfile* profile3 = manager->CreateTestingProfile("Profile 3"); |
204 ASSERT_EQ(7, [menu numberOfItems]); | 204 ASSERT_EQ(7, [menu numberOfItems]); |
205 | 205 |
206 // Create a browser and "show" it. | 206 // Create a browser and "show" it. |
207 Browser::CreateParams profile2_params(profile2); | 207 Browser::CreateParams profile2_params(profile2); |
208 scoped_ptr<Browser> p2_browser( | 208 std::unique_ptr<Browser> p2_browser( |
209 chrome::CreateBrowserWithTestWindowForParams(&profile2_params)); | 209 chrome::CreateBrowserWithTestWindowForParams(&profile2_params)); |
210 BrowserList::SetLastActive(p2_browser.get()); | 210 BrowserList::SetLastActive(p2_browser.get()); |
211 VerifyProfileNamedIsActive(@"Profile 2", __LINE__); | 211 VerifyProfileNamedIsActive(@"Profile 2", __LINE__); |
212 | 212 |
213 // Close the browser and make sure it's still active. | 213 // Close the browser and make sure it's still active. |
214 p2_browser.reset(); | 214 p2_browser.reset(); |
215 VerifyProfileNamedIsActive(@"Profile 2", __LINE__); | 215 VerifyProfileNamedIsActive(@"Profile 2", __LINE__); |
216 | 216 |
217 // Open a new browser and make sure it takes effect. | 217 // Open a new browser and make sure it takes effect. |
218 Browser::CreateParams profile3_params(profile3); | 218 Browser::CreateParams profile3_params(profile3); |
219 scoped_ptr<Browser> p3_browser( | 219 std::unique_ptr<Browser> p3_browser( |
220 chrome::CreateBrowserWithTestWindowForParams(&profile3_params)); | 220 chrome::CreateBrowserWithTestWindowForParams(&profile3_params)); |
221 BrowserList::SetLastActive(p3_browser.get()); | 221 BrowserList::SetLastActive(p3_browser.get()); |
222 VerifyProfileNamedIsActive(@"Profile 3", __LINE__); | 222 VerifyProfileNamedIsActive(@"Profile 3", __LINE__); |
223 | 223 |
224 p3_browser.reset(); | 224 p3_browser.reset(); |
225 VerifyProfileNamedIsActive(@"Profile 3", __LINE__); | 225 VerifyProfileNamedIsActive(@"Profile 3", __LINE__); |
226 } | 226 } |
227 | 227 |
228 TEST_F(ProfileMenuControllerTest, DeleteActiveProfile) { | 228 TEST_F(ProfileMenuControllerTest, DeleteActiveProfile) { |
229 TestingProfileManager* manager = testing_profile_manager(); | 229 TestingProfileManager* manager = testing_profile_manager(); |
(...skipping 14 matching lines...) Expand all Loading... |
244 // Simulate the active browser changing to NULL and ensure a profile doesn't | 244 // Simulate the active browser changing to NULL and ensure a profile doesn't |
245 // get created by disallowing IO operations temporarily. | 245 // get created by disallowing IO operations temporarily. |
246 const bool io_was_allowed = base::ThreadRestrictions::SetIOAllowed(false); | 246 const bool io_was_allowed = base::ThreadRestrictions::SetIOAllowed(false); |
247 [controller() activeBrowserChangedTo:NULL]; | 247 [controller() activeBrowserChangedTo:NULL]; |
248 base::ThreadRestrictions::SetIOAllowed(io_was_allowed); | 248 base::ThreadRestrictions::SetIOAllowed(io_was_allowed); |
249 } | 249 } |
250 | 250 |
251 TEST_F(ProfileMenuControllerTest, SupervisedProfile) { | 251 TEST_F(ProfileMenuControllerTest, SupervisedProfile) { |
252 TestingProfileManager* manager = testing_profile_manager(); | 252 TestingProfileManager* manager = testing_profile_manager(); |
253 TestingProfile* supervised_profile = manager->CreateTestingProfile( | 253 TestingProfile* supervised_profile = manager->CreateTestingProfile( |
254 "test1", scoped_ptr<syncable_prefs::PrefServiceSyncable>(), | 254 "test1", std::unique_ptr<syncable_prefs::PrefServiceSyncable>(), |
255 base::ASCIIToUTF16("Supervised User"), 0, "TEST_ID", | 255 base::ASCIIToUTF16("Supervised User"), 0, "TEST_ID", |
256 TestingProfile::TestingFactories()); | 256 TestingProfile::TestingFactories()); |
257 // The supervised profile is initially marked as omitted from the avatar menu | 257 // The supervised profile is initially marked as omitted from the avatar menu |
258 // (in non-test code, until we have confirmation that it has actually been | 258 // (in non-test code, until we have confirmation that it has actually been |
259 // created on the server). For the test, just tell the profile attribute | 259 // created on the server). For the test, just tell the profile attribute |
260 // storage to un-hide it. | 260 // storage to un-hide it. |
261 ProfileAttributesEntry* entry; | 261 ProfileAttributesEntry* entry; |
262 ASSERT_TRUE(manager->profile_attributes_storage()-> | 262 ASSERT_TRUE(manager->profile_attributes_storage()-> |
263 GetProfileAttributesWithPath(supervised_profile->GetPath(), &entry)); | 263 GetProfileAttributesWithPath(supervised_profile->GetPath(), &entry)); |
264 entry->SetIsOmitted(false); | 264 entry->SetIsOmitted(false); |
(...skipping 11 matching lines...) Expand all Loading... |
276 item = [menu itemAtIndex:1]; | 276 item = [menu itemAtIndex:1]; |
277 ASSERT_EQ(@selector(switchToProfileFromMenu:), [item action]); | 277 ASSERT_EQ(@selector(switchToProfileFromMenu:), [item action]); |
278 EXPECT_TRUE([controller() validateMenuItem:item]); | 278 EXPECT_TRUE([controller() validateMenuItem:item]); |
279 | 279 |
280 item = [menu itemAtIndex:5]; | 280 item = [menu itemAtIndex:5]; |
281 ASSERT_EQ(@selector(newProfile:), [item action]); | 281 ASSERT_EQ(@selector(newProfile:), [item action]); |
282 EXPECT_TRUE([controller() validateMenuItem:item]); | 282 EXPECT_TRUE([controller() validateMenuItem:item]); |
283 | 283 |
284 // Open a new browser for the supervised user and switch to it. | 284 // Open a new browser for the supervised user and switch to it. |
285 Browser::CreateParams supervised_profile_params(supervised_profile); | 285 Browser::CreateParams supervised_profile_params(supervised_profile); |
286 scoped_ptr<Browser> supervised_browser( | 286 std::unique_ptr<Browser> supervised_browser( |
287 chrome::CreateBrowserWithTestWindowForParams(&supervised_profile_params)); | 287 chrome::CreateBrowserWithTestWindowForParams(&supervised_profile_params)); |
288 BrowserList::SetLastActive(supervised_browser.get()); | 288 BrowserList::SetLastActive(supervised_browser.get()); |
289 | 289 |
290 item = [menu itemAtIndex:0]; | 290 item = [menu itemAtIndex:0]; |
291 ASSERT_EQ(@selector(switchToProfileFromMenu:), [item action]); | 291 ASSERT_EQ(@selector(switchToProfileFromMenu:), [item action]); |
292 EXPECT_FALSE([controller() validateMenuItem:item]); | 292 EXPECT_FALSE([controller() validateMenuItem:item]); |
293 | 293 |
294 item = [menu itemAtIndex:1]; | 294 item = [menu itemAtIndex:1]; |
295 ASSERT_EQ(@selector(switchToProfileFromMenu:), [item action]); | 295 ASSERT_EQ(@selector(switchToProfileFromMenu:), [item action]); |
296 EXPECT_TRUE([controller() validateMenuItem:item]); | 296 EXPECT_TRUE([controller() validateMenuItem:item]); |
297 | 297 |
298 item = [menu itemAtIndex:5]; | 298 item = [menu itemAtIndex:5]; |
299 ASSERT_EQ(@selector(newProfile:), [item action]); | 299 ASSERT_EQ(@selector(newProfile:), [item action]); |
300 EXPECT_FALSE([controller() validateMenuItem:item]); | 300 EXPECT_FALSE([controller() validateMenuItem:item]); |
301 } | 301 } |
OLD | NEW |