| 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 "base/command_line.h" | |
| 8 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
| 11 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/prefs/pref_service_syncable.h" | 11 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
| 15 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 14 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 16 #include "chrome/browser/ui/cocoa/run_loop_testing.h" | 15 #include "chrome/browser/ui/cocoa/run_loop_testing.h" |
| 17 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
| 19 #include "chrome/test/base/test_browser_window.h" | 18 #include "chrome/test/base/test_browser_window.h" |
| 20 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
| 21 #include "components/signin/core/common/profile_management_switches.h" | |
| 22 #include "testing/gtest_mac.h" | 20 #include "testing/gtest_mac.h" |
| 23 #include "ui/base/l10n/l10n_util_mac.h" | 21 #include "ui/base/l10n/l10n_util_mac.h" |
| 24 | 22 |
| 25 class ProfileMenuControllerTest : public CocoaProfileTest { | 23 class ProfileMenuControllerTest : public CocoaProfileTest { |
| 26 public: | 24 public: |
| 27 ProfileMenuControllerTest() { | 25 ProfileMenuControllerTest() { |
| 28 item_.reset([[NSMenuItem alloc] initWithTitle:@"Users" | 26 item_.reset([[NSMenuItem alloc] initWithTitle:@"Users" |
| 29 action:nil | 27 action:nil |
| 30 keyEquivalent:@""]); | 28 keyEquivalent:@""]); |
| 31 controller_.reset( | 29 controller_.reset( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 73 |
| 76 NSMenuItem* menu_item() { return item_.get(); } | 74 NSMenuItem* menu_item() { return item_.get(); } |
| 77 | 75 |
| 78 private: | 76 private: |
| 79 base::scoped_nsobject<NSMenuItem> item_; | 77 base::scoped_nsobject<NSMenuItem> item_; |
| 80 base::scoped_nsobject<ProfileMenuController> controller_; | 78 base::scoped_nsobject<ProfileMenuController> controller_; |
| 81 }; | 79 }; |
| 82 | 80 |
| 83 TEST_F(ProfileMenuControllerTest, InitializeMenu) { | 81 TEST_F(ProfileMenuControllerTest, InitializeMenu) { |
| 84 NSMenu* menu = [controller() menu]; | 82 NSMenu* menu = [controller() menu]; |
| 85 // Profile, <sep>, Edit, <sep>, New. | 83 // <sep>, Edit, <sep>, New. |
| 86 ASSERT_EQ(5, [menu numberOfItems]); | 84 ASSERT_EQ(4, [menu numberOfItems]); |
| 87 | 85 |
| 88 TestBottomItems(); | 86 TestBottomItems(); |
| 89 | 87 |
| 90 EXPECT_FALSE([menu_item() isHidden]); | 88 EXPECT_TRUE([menu_item() isHidden]); |
| 91 } | 89 } |
| 92 | 90 |
| 93 TEST_F(ProfileMenuControllerTest, CreateItemWithTitle) { | 91 TEST_F(ProfileMenuControllerTest, CreateItemWithTitle) { |
| 94 NSMenuItem* item = | 92 NSMenuItem* item = |
| 95 [controller() createItemWithTitle:@"Title" | 93 [controller() createItemWithTitle:@"Title" |
| 96 action:@selector(someSelector:)]; | 94 action:@selector(someSelector:)]; |
| 97 EXPECT_NSEQ(@"Title", [item title]); | 95 EXPECT_NSEQ(@"Title", [item title]); |
| 98 EXPECT_EQ(controller(), [item target]); | 96 EXPECT_EQ(controller(), [item target]); |
| 99 EXPECT_EQ(@selector(someSelector:), [item action]); | 97 EXPECT_EQ(@selector(someSelector:), [item action]); |
| 100 EXPECT_NSEQ(@"", [item keyEquivalent]); | 98 EXPECT_NSEQ(@"", [item keyEquivalent]); |
| 101 } | 99 } |
| 102 | 100 |
| 103 TEST_F(ProfileMenuControllerTest, RebuildMenu) { | 101 TEST_F(ProfileMenuControllerTest, RebuildMenu) { |
| 104 NSMenu* menu = [controller() menu]; | 102 NSMenu* menu = [controller() menu]; |
| 105 EXPECT_EQ(5, [menu numberOfItems]); | 103 EXPECT_EQ(4, [menu numberOfItems]); |
| 106 | 104 |
| 107 EXPECT_FALSE([menu_item() isHidden]); | 105 EXPECT_TRUE([menu_item() isHidden]); |
| 108 | 106 |
| 109 // Create some more profiles on the manager. | 107 // Create some more profiles on the manager. |
| 110 TestingProfileManager* manager = testing_profile_manager(); | 108 TestingProfileManager* manager = testing_profile_manager(); |
| 111 manager->CreateTestingProfile("Profile 2"); | 109 manager->CreateTestingProfile("Profile 2"); |
| 112 manager->CreateTestingProfile("Profile 3"); | 110 manager->CreateTestingProfile("Profile 3"); |
| 113 | 111 |
| 114 // Verify that the menu got rebuilt. | 112 // Verify that the menu got rebuilt. |
| 115 ASSERT_EQ(7, [menu numberOfItems]); | 113 ASSERT_EQ(7, [menu numberOfItems]); |
| 116 | 114 |
| 117 NSMenuItem* item = [menu itemAtIndex:0]; | 115 NSMenuItem* item = [menu itemAtIndex:0]; |
| 118 EXPECT_EQ(@selector(switchToProfileFromMenu:), [item action]); | 116 EXPECT_EQ(@selector(switchToProfileFromMenu:), [item action]); |
| 119 | 117 |
| 120 item = [menu itemAtIndex:1]; | 118 item = [menu itemAtIndex:1]; |
| 121 EXPECT_EQ(@selector(switchToProfileFromMenu:), [item action]); | 119 EXPECT_EQ(@selector(switchToProfileFromMenu:), [item action]); |
| 122 | 120 |
| 123 item = [menu itemAtIndex:2]; | 121 item = [menu itemAtIndex:2]; |
| 124 EXPECT_EQ(@selector(switchToProfileFromMenu:), [item action]); | 122 EXPECT_EQ(@selector(switchToProfileFromMenu:), [item action]); |
| 125 | 123 |
| 126 TestBottomItems(); | 124 TestBottomItems(); |
| 127 | 125 |
| 128 EXPECT_FALSE([menu_item() isHidden]); | 126 EXPECT_FALSE([menu_item() isHidden]); |
| 129 } | 127 } |
| 130 | 128 |
| 131 TEST_F(ProfileMenuControllerTest, InsertItems) { | 129 TEST_F(ProfileMenuControllerTest, InsertItems) { |
| 132 base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); | 130 base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); |
| 133 ASSERT_EQ(0, [menu numberOfItems]); | 131 ASSERT_EQ(0, [menu numberOfItems]); |
| 134 | 132 |
| 135 // Even with one profile items can still be inserted. | 133 // With only one profile, insertItems should be a no-op. |
| 136 BOOL result = [controller() insertItemsIntoMenu:menu | 134 BOOL result = [controller() insertItemsIntoMenu:menu |
| 137 atOffset:0 | 135 atOffset:0 |
| 138 fromDock:NO]; | 136 fromDock:NO]; |
| 139 EXPECT_TRUE(result); | 137 EXPECT_FALSE(result); |
| 140 EXPECT_EQ(1, [menu numberOfItems]); | 138 EXPECT_EQ(0, [menu numberOfItems]); |
| 141 [menu removeAllItems]; | 139 [menu removeAllItems]; |
| 142 | 140 |
| 143 // Same for use in building the dock menu. | 141 // Same for use in building the dock menu. |
| 144 result = [controller() insertItemsIntoMenu:menu | 142 result = [controller() insertItemsIntoMenu:menu |
| 145 atOffset:0 | 143 atOffset:0 |
| 146 fromDock:YES]; | 144 fromDock:YES]; |
| 147 EXPECT_FALSE(result); | 145 EXPECT_FALSE(result); |
| 148 EXPECT_EQ(0, [menu numberOfItems]); | 146 EXPECT_EQ(0, [menu numberOfItems]); |
| 149 [menu removeAllItems]; | 147 [menu removeAllItems]; |
| 150 | 148 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 EXPECT_FALSE([controller() validateMenuItem:item]); | 281 EXPECT_FALSE([controller() validateMenuItem:item]); |
| 284 | 282 |
| 285 item = [menu itemAtIndex:1]; | 283 item = [menu itemAtIndex:1]; |
| 286 ASSERT_EQ(@selector(switchToProfileFromMenu:), [item action]); | 284 ASSERT_EQ(@selector(switchToProfileFromMenu:), [item action]); |
| 287 EXPECT_TRUE([controller() validateMenuItem:item]); | 285 EXPECT_TRUE([controller() validateMenuItem:item]); |
| 288 | 286 |
| 289 item = [menu itemAtIndex:5]; | 287 item = [menu itemAtIndex:5]; |
| 290 ASSERT_EQ(@selector(newProfile:), [item action]); | 288 ASSERT_EQ(@selector(newProfile:), [item action]); |
| 291 EXPECT_FALSE([controller() validateMenuItem:item]); | 289 EXPECT_FALSE([controller() validateMenuItem:item]); |
| 292 } | 290 } |
| OLD | NEW |