| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/message_loop/message_pump_mac.h" | 11 #include "base/message_loop/message_pump_mac.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/profiles/avatar_menu.h" | 13 #include "chrome/browser/profiles/avatar_menu.h" |
| 14 #include "chrome/browser/profiles/avatar_menu_observer.h" | 14 #include "chrome/browser/profiles/avatar_menu_observer.h" |
| 15 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 15 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 16 #include "chrome/test/base/testing_browser_process.h" | 16 #include "chrome/test/base/testing_browser_process.h" |
| 17 #include "chrome/test/base/testing_profile_manager.h" | 17 #include "chrome/test/base/testing_profile_manager.h" |
| 18 #include "components/signin/core/common/profile_management_switches.h" | 18 #include "components/signin/core/common/profile_management_switches.h" |
| 19 #include "components/syncable_prefs/pref_service_syncable.h" | 19 #include "components/sync_preferences/pref_service_syncable.h" |
| 20 #include "content/public/test/test_browser_thread_bundle.h" | 20 #include "content/public/test/test_browser_thread_bundle.h" |
| 21 #include "testing/gtest_mac.h" | 21 #include "testing/gtest_mac.h" |
| 22 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 22 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
| 23 #include "ui/events/test/cocoa_test_event_utils.h" | 23 #include "ui/events/test/cocoa_test_event_utils.h" |
| 24 | 24 |
| 25 class AvatarMenuBubbleControllerTest : public CocoaTest { | 25 class AvatarMenuBubbleControllerTest : public CocoaTest { |
| 26 public: | 26 public: |
| 27 AvatarMenuBubbleControllerTest() | 27 AvatarMenuBubbleControllerTest() |
| 28 : manager_(TestingBrowserProcess::GetGlobal()) { | 28 : manager_(TestingBrowserProcess::GetGlobal()) { |
| 29 } | 29 } |
| 30 | 30 |
| 31 void SetUp() override { | 31 void SetUp() override { |
| 32 CocoaTest::SetUp(); | 32 CocoaTest::SetUp(); |
| 33 ASSERT_TRUE(manager_.SetUp()); | 33 ASSERT_TRUE(manager_.SetUp()); |
| 34 | 34 |
| 35 manager_.CreateTestingProfile( | 35 manager_.CreateTestingProfile( |
| 36 "test1", std::unique_ptr<syncable_prefs::PrefServiceSyncable>(), | 36 "test1", std::unique_ptr<sync_preferences::PrefServiceSyncable>(), |
| 37 base::ASCIIToUTF16("Test 1"), 1, std::string(), | 37 base::ASCIIToUTF16("Test 1"), 1, std::string(), |
| 38 TestingProfile::TestingFactories()); | 38 TestingProfile::TestingFactories()); |
| 39 manager_.CreateTestingProfile( | 39 manager_.CreateTestingProfile( |
| 40 "test2", std::unique_ptr<syncable_prefs::PrefServiceSyncable>(), | 40 "test2", std::unique_ptr<sync_preferences::PrefServiceSyncable>(), |
| 41 base::ASCIIToUTF16("Test 2"), 0, std::string(), | 41 base::ASCIIToUTF16("Test 2"), 0, std::string(), |
| 42 TestingProfile::TestingFactories()); | 42 TestingProfile::TestingFactories()); |
| 43 | 43 |
| 44 menu_ = new AvatarMenu(manager_.profile_attributes_storage(), NULL, NULL); | 44 menu_ = new AvatarMenu(manager_.profile_attributes_storage(), NULL, NULL); |
| 45 menu_->RebuildMenu(); | 45 menu_->RebuildMenu(); |
| 46 | 46 |
| 47 NSRect frame = [test_window() frame]; | 47 NSRect frame = [test_window() frame]; |
| 48 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); | 48 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); |
| 49 controller_ = | 49 controller_ = |
| 50 [[AvatarMenuBubbleController alloc] initWithMenu:menu() | 50 [[AvatarMenuBubbleController alloc] initWithMenu:menu() |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 TEST_F(AvatarMenuBubbleControllerTest, PerformLayout) { | 123 TEST_F(AvatarMenuBubbleControllerTest, PerformLayout) { |
| 124 [controller() showWindow:nil]; | 124 [controller() showWindow:nil]; |
| 125 | 125 |
| 126 NSView* contents = [[controller() window] contentView]; | 126 NSView* contents = [[controller() window] contentView]; |
| 127 EXPECT_EQ(4U, [[contents subviews] count]); | 127 EXPECT_EQ(4U, [[contents subviews] count]); |
| 128 | 128 |
| 129 base::scoped_nsobject<NSMutableArray> oldItems([[controller() items] copy]); | 129 base::scoped_nsobject<NSMutableArray> oldItems([[controller() items] copy]); |
| 130 | 130 |
| 131 // Now create a new profile and notify the delegate. | 131 // Now create a new profile and notify the delegate. |
| 132 manager()->CreateTestingProfile( | 132 manager()->CreateTestingProfile( |
| 133 "test3", std::unique_ptr<syncable_prefs::PrefServiceSyncable>(), | 133 "test3", std::unique_ptr<sync_preferences::PrefServiceSyncable>(), |
| 134 base::ASCIIToUTF16("Test 3"), 0, std::string(), | 134 base::ASCIIToUTF16("Test 3"), 0, std::string(), |
| 135 TestingProfile::TestingFactories()); | 135 TestingProfile::TestingFactories()); |
| 136 | 136 |
| 137 // Testing the bridge is not worth the effort... | 137 // Testing the bridge is not worth the effort... |
| 138 [controller() performLayout]; | 138 [controller() performLayout]; |
| 139 | 139 |
| 140 EXPECT_EQ(5U, [[contents subviews] count]); | 140 EXPECT_EQ(5U, [[contents subviews] count]); |
| 141 | 141 |
| 142 // Make sure that none of the old items exit. | 142 // Make sure that none of the old items exit. |
| 143 NSArray* newItems = [controller() items]; | 143 NSArray* newItems = [controller() items]; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 [controller() keyDown:event]; | 265 [controller() keyDown:event]; |
| 266 EXPECT_EQ([[controller() items] objectAtIndex:0], GetHighlightedItem()); | 266 EXPECT_EQ([[controller() items] objectAtIndex:0], GetHighlightedItem()); |
| 267 | 267 |
| 268 [controller() keyDown:event]; | 268 [controller() keyDown:event]; |
| 269 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); | 269 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); |
| 270 | 270 |
| 271 // There are no more items now so going up should stay at the first item. | 271 // There are no more items now so going up should stay at the first item. |
| 272 [controller() keyDown:event]; | 272 [controller() keyDown:event]; |
| 273 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); | 273 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); |
| 274 } | 274 } |
| OLD | NEW |