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" | |
8 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
9 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_pump_mac.h" | 9 #include "base/message_loop/message_pump_mac.h" |
11 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/prefs/pref_service_syncable.h" | 11 #include "chrome/browser/prefs/pref_service_syncable.h" |
13 #include "chrome/browser/profiles/avatar_menu.h" | 12 #include "chrome/browser/profiles/avatar_menu.h" |
14 #include "chrome/browser/profiles/avatar_menu_observer.h" | 13 #include "chrome/browser/profiles/avatar_menu_observer.h" |
15 #include "chrome/browser/profiles/profile_info_cache.h" | 14 #include "chrome/browser/profiles/profile_info_cache.h" |
16 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 15 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
17 #include "chrome/test/base/testing_browser_process.h" | 16 #include "chrome/test/base/testing_browser_process.h" |
18 #include "chrome/test/base/testing_profile_manager.h" | 17 #include "chrome/test/base/testing_profile_manager.h" |
19 #include "components/signin/core/common/profile_management_switches.h" | |
20 #include "testing/gtest_mac.h" | 18 #include "testing/gtest_mac.h" |
21 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 19 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
22 #include "ui/events/test/cocoa_test_event_utils.h" | 20 #include "ui/events/test/cocoa_test_event_utils.h" |
23 | 21 |
24 class AvatarMenuBubbleControllerTest : public CocoaTest { | 22 class AvatarMenuBubbleControllerTest : public CocoaTest { |
25 public: | 23 public: |
26 AvatarMenuBubbleControllerTest() | 24 AvatarMenuBubbleControllerTest() |
27 : manager_(TestingBrowserProcess::GetGlobal()) { | 25 : manager_(TestingBrowserProcess::GetGlobal()) { |
28 } | 26 } |
29 | 27 |
30 void SetUp() override { | 28 void SetUp() override { |
31 switches::DisableNewAvatarMenuForTesting( | |
32 base::CommandLine::ForCurrentProcess()); | |
33 | |
34 CocoaTest::SetUp(); | 29 CocoaTest::SetUp(); |
35 ASSERT_TRUE(manager_.SetUp()); | 30 ASSERT_TRUE(manager_.SetUp()); |
36 | 31 |
37 manager_.CreateTestingProfile("test1", scoped_ptr<PrefServiceSyncable>(), | 32 manager_.CreateTestingProfile("test1", scoped_ptr<PrefServiceSyncable>(), |
38 base::ASCIIToUTF16("Test 1"), 1, | 33 base::ASCIIToUTF16("Test 1"), 1, |
39 std::string(), | 34 std::string(), |
40 TestingProfile::TestingFactories()); | 35 TestingProfile::TestingFactories()); |
41 manager_.CreateTestingProfile("test2", scoped_ptr<PrefServiceSyncable>(), | 36 manager_.CreateTestingProfile("test2", scoped_ptr<PrefServiceSyncable>(), |
42 base::ASCIIToUTF16("Test 2"), 0, | 37 base::ASCIIToUTF16("Test 2"), 0, |
43 std::string(), | 38 std::string(), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 AvatarMenu* menu_; | 71 AvatarMenu* menu_; |
77 }; | 72 }; |
78 | 73 |
79 TEST_F(AvatarMenuBubbleControllerTest, InitialLayout) { | 74 TEST_F(AvatarMenuBubbleControllerTest, InitialLayout) { |
80 [controller() showWindow:nil]; | 75 [controller() showWindow:nil]; |
81 | 76 |
82 // Two profiles means two item views and the new button with separator. | 77 // Two profiles means two item views and the new button with separator. |
83 NSView* contents = [[controller() window] contentView]; | 78 NSView* contents = [[controller() window] contentView]; |
84 EXPECT_EQ(4U, [[contents subviews] count]); | 79 EXPECT_EQ(4U, [[contents subviews] count]); |
85 | 80 |
86 // Loop over the items and match the viewController views to subviews. | 81 // Loop over the itmes and match the viewController views to subviews. |
87 NSMutableArray* subviews = | 82 NSMutableArray* subviews = |
88 [NSMutableArray arrayWithArray:[contents subviews]]; | 83 [NSMutableArray arrayWithArray:[contents subviews]]; |
89 for (AvatarMenuItemController* viewController in [controller() items]) { | 84 for (AvatarMenuItemController* viewController in [controller() items]) { |
90 for (NSView* subview in subviews) { | 85 for (NSView* subview in subviews) { |
91 if ([viewController view] == subview) { | 86 if ([viewController view] == subview) { |
92 [subviews removeObject:subview]; | 87 [subviews removeObject:subview]; |
93 break; | 88 break; |
94 } | 89 } |
95 } | 90 } |
96 } | 91 } |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 [controller() keyDown:event]; | 261 [controller() keyDown:event]; |
267 EXPECT_EQ([[controller() items] objectAtIndex:0], GetHighlightedItem()); | 262 EXPECT_EQ([[controller() items] objectAtIndex:0], GetHighlightedItem()); |
268 | 263 |
269 [controller() keyDown:event]; | 264 [controller() keyDown:event]; |
270 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); | 265 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); |
271 | 266 |
272 // There are no more items now so going up should stay at the first item. | 267 // There are no more items now so going up should stay at the first item. |
273 [controller() keyDown:event]; | 268 [controller() keyDown:event]; |
274 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); | 269 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); |
275 } | 270 } |
OLD | NEW |