Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: chrome/browser/ui/cocoa/profiles/profile_menu_controller_unittest.mm

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

Powered by Google App Engine
This is Rietveld 408576698