| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import <Cocoa/Cocoa.h> | |
| 6 | |
| 7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | |
| 8 #import "chrome/browser/ui/cocoa/profile_menu_button.h" | |
| 9 #import "chrome/browser/ui/cocoa/test_event_utils.h" | |
| 10 #import "testing/gtest_mac.h" | |
| 11 | |
| 12 class ProfileMenuButtonTest : public CocoaTest { | |
| 13 public: | |
| 14 ProfileMenuButtonTest() { | |
| 15 scoped_nsobject<ProfileMenuButton> button([[ProfileMenuButton alloc] | |
| 16 initWithFrame:NSMakeRect(50, 50, 100, 100)]); | |
| 17 button_ = button.get(); | |
| 18 [[test_window() contentView] addSubview:button_]; | |
| 19 } | |
| 20 | |
| 21 ProfileMenuButton* button_; | |
| 22 }; | |
| 23 | |
| 24 | |
| 25 TEST_F(ProfileMenuButtonTest, ControlSize) { | |
| 26 scoped_nsobject<ProfileMenuButton> button([[ProfileMenuButton alloc] | |
| 27 initWithFrame:NSZeroRect]); | |
| 28 | |
| 29 NSSize minSize = [button minControlSize]; | |
| 30 EXPECT_TRUE(NSEqualSizes(minSize, [button desiredControlSize])); | |
| 31 | |
| 32 [button setProfileDisplayName:@"Test"]; | |
| 33 EXPECT_TRUE(NSEqualSizes(minSize, [button desiredControlSize])); | |
| 34 EXPECT_TRUE(NSEqualSizes(minSize, [button desiredControlSize])); | |
| 35 | |
| 36 [button setShouldShowProfileDisplayName:YES]; | |
| 37 EXPECT_TRUE(NSEqualSizes(minSize, [button minControlSize])); | |
| 38 EXPECT_GT([button desiredControlSize].height, minSize.height); | |
| 39 EXPECT_GT([button desiredControlSize].width, minSize.width); | |
| 40 | |
| 41 [button setShouldShowProfileDisplayName:NO]; | |
| 42 EXPECT_TRUE(NSEqualSizes(minSize, [button desiredControlSize])); | |
| 43 EXPECT_TRUE(NSEqualSizes(minSize, [button desiredControlSize])); | |
| 44 } | |
| 45 | |
| 46 // Tests display, add/remove. | |
| 47 TEST_VIEW(ProfileMenuButtonTest, button_); | |
| 48 | |
| 49 TEST_F(ProfileMenuButtonTest, HitTest) { | |
| 50 NSRect mouseRect = NSInsetRect([button_ frame], 1, 1); | |
| 51 NSPoint topRight = NSMakePoint(NSMaxX(mouseRect), NSMaxY(mouseRect)); | |
| 52 NSPoint bottomRight = NSMakePoint(NSMaxX(mouseRect), NSMinY(mouseRect)); | |
| 53 NSPoint outsidePoint = NSOffsetRect(mouseRect, -10, -10).origin; | |
| 54 | |
| 55 // Without profile display name. Only topRight should hit. | |
| 56 EXPECT_NSEQ([button_ hitTest:topRight], button_); | |
| 57 EXPECT_NSEQ([button_ hitTest:bottomRight], NULL); | |
| 58 EXPECT_NSEQ([button_ hitTest:outsidePoint], NULL); | |
| 59 | |
| 60 // With profile display name. The profile display name should not hit. | |
| 61 [button_ setProfileDisplayName:@"Test"]; | |
| 62 [button_ setShouldShowProfileDisplayName:YES]; | |
| 63 EXPECT_NSEQ([button_ hitTest:topRight], button_); | |
| 64 EXPECT_NSEQ([button_ hitTest:bottomRight], NULL); | |
| 65 EXPECT_NSEQ([button_ hitTest:outsidePoint], NULL); | |
| 66 } | |
| 67 | |
| 68 // Test drawing, mostly to ensure nothing leaks or crashes. | |
| 69 TEST_F(ProfileMenuButtonTest, Display) { | |
| 70 // With profile display name. | |
| 71 [button_ display]; | |
| 72 | |
| 73 // With profile display name. | |
| 74 [button_ setProfileDisplayName:@"Test"]; | |
| 75 [button_ setShouldShowProfileDisplayName:YES]; | |
| 76 [button_ display]; | |
| 77 } | |
| OLD | NEW |