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/avatar_menu_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_pump_mac.h" | 10 #include "base/message_loop/message_pump_mac.h" |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/prefs/pref_service_syncable.h" | 12 #include "chrome/browser/prefs/pref_service_syncable.h" |
12 #include "chrome/browser/profiles/avatar_menu.h" | 13 #include "chrome/browser/profiles/avatar_menu.h" |
13 #include "chrome/browser/profiles/avatar_menu_observer.h" | 14 #include "chrome/browser/profiles/avatar_menu_observer.h" |
14 #include "chrome/browser/profiles/profile_info_cache.h" | 15 #include "chrome/browser/profiles/profile_info_cache.h" |
15 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 16 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
16 #include "chrome/test/base/testing_browser_process.h" | 17 #include "chrome/test/base/testing_browser_process.h" |
17 #include "chrome/test/base/testing_profile_manager.h" | 18 #include "chrome/test/base/testing_profile_manager.h" |
19 #include "components/signin/core/common/profile_management_switches.h" | |
18 #include "testing/gtest_mac.h" | 20 #include "testing/gtest_mac.h" |
19 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 21 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
20 #include "ui/events/test/cocoa_test_event_utils.h" | 22 #include "ui/events/test/cocoa_test_event_utils.h" |
21 | 23 |
22 class AvatarMenuBubbleControllerTest : public CocoaTest { | 24 class AvatarMenuBubbleControllerTest : public CocoaTest { |
23 public: | 25 public: |
24 AvatarMenuBubbleControllerTest() | 26 AvatarMenuBubbleControllerTest() |
25 : manager_(TestingBrowserProcess::GetGlobal()) { | 27 : manager_(TestingBrowserProcess::GetGlobal()) { |
26 } | 28 } |
27 | 29 |
28 void SetUp() override { | 30 void SetUp() override { |
31 switches::DisableNewAvatarMenuForTesting( | |
32 base::CommandLine::ForCurrentProcess()); | |
33 | |
29 CocoaTest::SetUp(); | 34 CocoaTest::SetUp(); |
30 ASSERT_TRUE(manager_.SetUp()); | 35 ASSERT_TRUE(manager_.SetUp()); |
31 | 36 |
32 manager_.CreateTestingProfile("test1", scoped_ptr<PrefServiceSyncable>(), | 37 testing_profile_manager()->CreateTestingProfile( |
Scott Hess - ex-Googler
2015/03/07 04:33:07
Why are you going to the point of making this chan
Mike Lerman
2015/03/09 14:28:34
You're right. I had made this change as part of an
Scott Hess - ex-Googler
2015/03/09 15:36:27
OK - that's kind of what I figured, but wondered i
| |
33 base::ASCIIToUTF16("Test 1"), 1, | 38 "test1", scoped_ptr<PrefServiceSyncable>(), |
34 std::string(), | 39 base::ASCIIToUTF16("Test 1"), 1, |
35 TestingProfile::TestingFactories()); | 40 std::string(), |
36 manager_.CreateTestingProfile("test2", scoped_ptr<PrefServiceSyncable>(), | 41 TestingProfile::TestingFactories()); |
37 base::ASCIIToUTF16("Test 2"), 0, | 42 testing_profile_manager()->CreateTestingProfile( |
38 std::string(), | 43 "test2", scoped_ptr<PrefServiceSyncable>(), |
39 TestingProfile::TestingFactories()); | 44 base::ASCIIToUTF16("Test 2"), 0, |
45 std::string(), | |
46 TestingProfile::TestingFactories()); | |
40 | 47 |
41 menu_ = new AvatarMenu(manager_.profile_info_cache(), NULL, NULL); | 48 menu_ = new AvatarMenu(testing_profile_manager()->profile_info_cache(), |
49 NULL, NULL); | |
42 menu_->RebuildMenu(); | 50 menu_->RebuildMenu(); |
43 | 51 |
44 NSRect frame = [test_window() frame]; | 52 NSRect frame = [test_window() frame]; |
45 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); | 53 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); |
46 controller_ = | 54 controller_ = |
47 [[AvatarMenuBubbleController alloc] initWithMenu:menu() | 55 [[AvatarMenuBubbleController alloc] initWithMenu:menu() |
48 parentWindow:test_window() | 56 parentWindow:test_window() |
49 anchoredAt:point]; | 57 anchoredAt:point]; |
50 } | 58 } |
51 | 59 |
52 TestingProfileManager* manager() { return &manager_; } | 60 TestingProfileManager* testing_profile_manager() { return &manager_; } |
53 AvatarMenuBubbleController* controller() { return controller_; } | 61 AvatarMenuBubbleController* controller() { return controller_; } |
54 AvatarMenu* menu() { return menu_; } | 62 AvatarMenu* menu() { return menu_; } |
55 | 63 |
56 AvatarMenuItemController* GetHighlightedItem() { | 64 AvatarMenuItemController* GetHighlightedItem() { |
57 for (AvatarMenuItemController* item in [controller() items]) { | 65 for (AvatarMenuItemController* item in [controller() items]) { |
58 if ([item isHighlighted]) | 66 if ([item isHighlighted]) |
59 return item; | 67 return item; |
60 } | 68 } |
61 return nil; | 69 return nil; |
62 } | 70 } |
63 | 71 |
64 private: | 72 private: |
65 TestingProfileManager manager_; | 73 TestingProfileManager manager_; |
66 | 74 |
67 // Weak; releases self. | 75 // Weak; releases self. |
68 AvatarMenuBubbleController* controller_; | 76 AvatarMenuBubbleController* controller_; |
69 | 77 |
70 // Weak; owned by |controller_|. | 78 // Weak; owned by |controller_|. |
71 AvatarMenu* menu_; | 79 AvatarMenu* menu_; |
72 }; | 80 }; |
73 | 81 |
74 TEST_F(AvatarMenuBubbleControllerTest, InitialLayout) { | 82 TEST_F(AvatarMenuBubbleControllerTest, InitialLayout) { |
75 [controller() showWindow:nil]; | 83 [controller() showWindow:nil]; |
76 | 84 |
77 // Two profiles means two item views and the new button with separator. | 85 // Two profiles means two item views and the new button with separator. |
78 NSView* contents = [[controller() window] contentView]; | 86 NSView* contents = [[controller() window] contentView]; |
79 EXPECT_EQ(4U, [[contents subviews] count]); | 87 EXPECT_EQ(4U, [[contents subviews] count]); |
80 | 88 |
81 // Loop over the itmes and match the viewController views to subviews. | 89 // Loop over the items and match the viewController views to subviews. |
82 NSMutableArray* subviews = | 90 NSMutableArray* subviews = |
83 [NSMutableArray arrayWithArray:[contents subviews]]; | 91 [NSMutableArray arrayWithArray:[contents subviews]]; |
84 for (AvatarMenuItemController* viewController in [controller() items]) { | 92 for (AvatarMenuItemController* viewController in [controller() items]) { |
85 for (NSView* subview in subviews) { | 93 for (NSView* subview in subviews) { |
86 if ([viewController view] == subview) { | 94 if ([viewController view] == subview) { |
87 [subviews removeObject:subview]; | 95 [subviews removeObject:subview]; |
88 break; | 96 break; |
89 } | 97 } |
90 } | 98 } |
91 } | 99 } |
(...skipping 26 matching lines...) Expand all Loading... | |
118 | 126 |
119 TEST_F(AvatarMenuBubbleControllerTest, PerformLayout) { | 127 TEST_F(AvatarMenuBubbleControllerTest, PerformLayout) { |
120 [controller() showWindow:nil]; | 128 [controller() showWindow:nil]; |
121 | 129 |
122 NSView* contents = [[controller() window] contentView]; | 130 NSView* contents = [[controller() window] contentView]; |
123 EXPECT_EQ(4U, [[contents subviews] count]); | 131 EXPECT_EQ(4U, [[contents subviews] count]); |
124 | 132 |
125 base::scoped_nsobject<NSMutableArray> oldItems([[controller() items] copy]); | 133 base::scoped_nsobject<NSMutableArray> oldItems([[controller() items] copy]); |
126 | 134 |
127 // Now create a new profile and notify the delegate. | 135 // Now create a new profile and notify the delegate. |
128 manager()->CreateTestingProfile("test3", scoped_ptr<PrefServiceSyncable>(), | 136 testing_profile_manager()->CreateTestingProfile( |
129 base::ASCIIToUTF16("Test 3"), 0, | 137 "test3", scoped_ptr<PrefServiceSyncable>(), |
130 std::string(), | 138 base::ASCIIToUTF16("Test 3"), 0, |
131 TestingProfile::TestingFactories()); | 139 std::string(), |
140 TestingProfile::TestingFactories()); | |
132 | 141 |
133 // Testing the bridge is not worth the effort... | 142 // Testing the bridge is not worth the effort... |
134 [controller() performLayout]; | 143 [controller() performLayout]; |
135 | 144 |
136 EXPECT_EQ(5U, [[contents subviews] count]); | 145 EXPECT_EQ(5U, [[contents subviews] count]); |
137 | 146 |
138 // Make sure that none of the old items exit. | 147 // Make sure that none of the old items exit. |
139 NSArray* newItems = [controller() items]; | 148 NSArray* newItems = [controller() items]; |
140 for (AvatarMenuItemController* oldVC in oldItems.get()) { | 149 for (AvatarMenuItemController* oldVC in oldItems.get()) { |
141 EXPECT_FALSE([newItems containsObject:oldVC]); | 150 EXPECT_FALSE([newItems containsObject:oldVC]); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 [controller() keyDown:event]; | 270 [controller() keyDown:event]; |
262 EXPECT_EQ([[controller() items] objectAtIndex:0], GetHighlightedItem()); | 271 EXPECT_EQ([[controller() items] objectAtIndex:0], GetHighlightedItem()); |
263 | 272 |
264 [controller() keyDown:event]; | 273 [controller() keyDown:event]; |
265 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); | 274 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); |
266 | 275 |
267 // There are no more items now so going up should stay at the first item. | 276 // There are no more items now so going up should stay at the first item. |
268 [controller() keyDown:event]; | 277 [controller() keyDown:event]; |
269 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); | 278 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); |
270 } | 279 } |
OLD | NEW |