| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/avatar_menu_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_nsobject.h" | 7 #include "base/memory/scoped_nsobject.h" |
| 8 #include "base/message_loop/message_pump_mac.h" | 8 #include "base/message_loop/message_pump_mac.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 10 #include "chrome/browser/profiles/avatar_menu_model.h" | 11 #include "chrome/browser/profiles/avatar_menu_model.h" |
| 11 #include "chrome/browser/profiles/avatar_menu_model_observer.h" | 12 #include "chrome/browser/profiles/avatar_menu_model_observer.h" |
| 12 #include "chrome/browser/profiles/profile_info_cache.h" | 13 #include "chrome/browser/profiles/profile_info_cache.h" |
| 13 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 14 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 14 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" | 15 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" |
| 15 #include "chrome/test/base/testing_browser_process.h" | 16 #include "chrome/test/base/testing_browser_process.h" |
| 16 #include "chrome/test/base/testing_profile_manager.h" | 17 #include "chrome/test/base/testing_profile_manager.h" |
| 17 #include "testing/gtest_mac.h" | 18 #include "testing/gtest_mac.h" |
| 18 #include "ui/base/test/cocoa_test_event_utils.h" | 19 #include "ui/base/test/cocoa_test_event_utils.h" |
| 19 | 20 |
| 20 class AvatarMenuBubbleControllerTest : public CocoaTest { | 21 class AvatarMenuBubbleControllerTest : public CocoaTest { |
| 21 public: | 22 public: |
| 22 AvatarMenuBubbleControllerTest() | 23 AvatarMenuBubbleControllerTest() |
| 23 : manager_(TestingBrowserProcess::GetGlobal()) { | 24 : manager_(TestingBrowserProcess::GetGlobal()) { |
| 24 } | 25 } |
| 25 | 26 |
| 26 virtual void SetUp() { | 27 virtual void SetUp() { |
| 27 CocoaTest::SetUp(); | 28 CocoaTest::SetUp(); |
| 28 ASSERT_TRUE(manager_.SetUp()); | 29 ASSERT_TRUE(manager_.SetUp()); |
| 29 | 30 |
| 30 manager_.CreateTestingProfile("test1", ASCIIToUTF16("Test 1"), 1); | 31 manager_.CreateTestingProfile("test1", scoped_ptr<PrefServiceSyncable>(), |
| 31 manager_.CreateTestingProfile("test2", ASCIIToUTF16("Test 2"), 0); | 32 ASCIIToUTF16("Test 1"), 1); |
| 33 manager_.CreateTestingProfile("test2", scoped_ptr<PrefServiceSyncable>(), |
| 34 ASCIIToUTF16("Test 2"), 0); |
| 32 | 35 |
| 33 model_ = new AvatarMenuModel(manager_.profile_info_cache(), NULL, NULL); | 36 model_ = new AvatarMenuModel(manager_.profile_info_cache(), NULL, NULL); |
| 34 | 37 |
| 35 NSRect frame = [test_window() frame]; | 38 NSRect frame = [test_window() frame]; |
| 36 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); | 39 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); |
| 37 controller_ = | 40 controller_ = |
| 38 [[AvatarMenuBubbleController alloc] initWithModel:model() | 41 [[AvatarMenuBubbleController alloc] initWithModel:model() |
| 39 parentWindow:test_window() | 42 parentWindow:test_window() |
| 40 anchoredAt:point]; | 43 anchoredAt:point]; |
| 41 } | 44 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 112 |
| 110 TEST_F(AvatarMenuBubbleControllerTest, PerformLayout) { | 113 TEST_F(AvatarMenuBubbleControllerTest, PerformLayout) { |
| 111 [controller() showWindow:nil]; | 114 [controller() showWindow:nil]; |
| 112 | 115 |
| 113 NSView* contents = [[controller() window] contentView]; | 116 NSView* contents = [[controller() window] contentView]; |
| 114 EXPECT_EQ(4U, [[contents subviews] count]); | 117 EXPECT_EQ(4U, [[contents subviews] count]); |
| 115 | 118 |
| 116 scoped_nsobject<NSMutableArray> oldItems([[controller() items] copy]); | 119 scoped_nsobject<NSMutableArray> oldItems([[controller() items] copy]); |
| 117 | 120 |
| 118 // Now create a new profile and notify the delegate. | 121 // Now create a new profile and notify the delegate. |
| 119 manager()->CreateTestingProfile("test3", ASCIIToUTF16("Test 3"), 0); | 122 manager()->CreateTestingProfile("test3", scoped_ptr<PrefServiceSyncable>(), |
| 123 ASCIIToUTF16("Test 3"), 0); |
| 120 | 124 |
| 121 // Testing the bridge is not worth the effort... | 125 // Testing the bridge is not worth the effort... |
| 122 [controller() performLayout]; | 126 [controller() performLayout]; |
| 123 | 127 |
| 124 EXPECT_EQ(5U, [[contents subviews] count]); | 128 EXPECT_EQ(5U, [[contents subviews] count]); |
| 125 | 129 |
| 126 // Make sure that none of the old items exit. | 130 // Make sure that none of the old items exit. |
| 127 NSArray* newItems = [controller() items]; | 131 NSArray* newItems = [controller() items]; |
| 128 for (AvatarMenuItemController* oldVC in oldItems.get()) { | 132 for (AvatarMenuItemController* oldVC in oldItems.get()) { |
| 129 EXPECT_FALSE([newItems containsObject:oldVC]); | 133 EXPECT_FALSE([newItems containsObject:oldVC]); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 [controller() keyDown:event]; | 253 [controller() keyDown:event]; |
| 250 EXPECT_EQ([[controller() items] objectAtIndex:0], GetHighlightedItem()); | 254 EXPECT_EQ([[controller() items] objectAtIndex:0], GetHighlightedItem()); |
| 251 | 255 |
| 252 [controller() keyDown:event]; | 256 [controller() keyDown:event]; |
| 253 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); | 257 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); |
| 254 | 258 |
| 255 // There are no more items now so going up should stay at the first item. | 259 // There are no more items now so going up should stay at the first item. |
| 256 [controller() keyDown:event]; | 260 [controller() keyDown:event]; |
| 257 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); | 261 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); |
| 258 } | 262 } |
| OLD | NEW |