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