| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 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 #include "base/scoped_nsobject.h" |
| 8 #import "chrome/browser/cocoa/clickhold_button_cell.h" |
| 9 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| 10 #import "chrome/browser/cocoa/delayedmenu_button.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "testing/platform_test.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 class DelayedMenuButtonTest : public PlatformTest { |
| 17 public: |
| 18 DelayedMenuButtonTest() { |
| 19 NSRect frame = NSMakeRect(0, 0, 50, 30); |
| 20 button_.reset([[DelayedMenuButton alloc] initWithFrame:frame]); |
| 21 scoped_nsobject<ClickHoldButtonCell> cell( |
| 22 [[ClickHoldButtonCell alloc] initTextCell:@"Testing"]); |
| 23 [button_ setCell:cell.get()]; |
| 24 [cocoa_helper_.contentView() addSubview:button_.get()]; |
| 25 } |
| 26 |
| 27 scoped_nsobject<DelayedMenuButton> button_; |
| 28 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc. |
| 29 }; |
| 30 |
| 31 // Test adding/removing from the view hierarchy, mostly to ensure nothing leaks |
| 32 // or crashes. |
| 33 TEST_F(DelayedMenuButtonTest, AddRemove) { |
| 34 EXPECT_EQ(cocoa_helper_.contentView(), [button_ superview]); |
| 35 [button_.get() removeFromSuperview]; |
| 36 EXPECT_FALSE([button_ superview]); |
| 37 } |
| 38 |
| 39 // Test drawing, mostly to ensure nothing leaks or crashes. |
| 40 TEST_F(DelayedMenuButtonTest, Display) { |
| 41 [button_ display]; |
| 42 } |
| 43 |
| 44 // Test assigning and enabling a menu, again mostly to ensure nothing leaks or |
| 45 // crashes. |
| 46 TEST_F(DelayedMenuButtonTest, MenuAssign) { |
| 47 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); |
| 48 ASSERT_TRUE(menu.get()); |
| 49 |
| 50 [menu insertItemWithTitle:@"" action:nil keyEquivalent:@"" atIndex:0]; |
| 51 [menu insertItemWithTitle:@"foo" action:nil keyEquivalent:@"" atIndex:1]; |
| 52 [menu insertItemWithTitle:@"bar" action:nil keyEquivalent:@"" atIndex:2]; |
| 53 [menu insertItemWithTitle:@"baz" action:nil keyEquivalent:@"" atIndex:3]; |
| 54 |
| 55 [button_ setMenu:menu]; |
| 56 EXPECT_TRUE([button_ menu]); |
| 57 |
| 58 [button_ setMenuEnabled:YES]; |
| 59 EXPECT_TRUE([button_ menuEnabled]); |
| 60 |
| 61 // TODO(viettrungluu): Display the menu. (Calling DelayedMenuButton's private |
| 62 // |-menuAction:| method displays it fine, but the problem is getting rid of |
| 63 // the menu. We can catch the |NSMenuDidBeginTrackingNotification| from |menu| |
| 64 // fine, but then |-cancelTracking| doesn't dismiss it. I don't know why.) |
| 65 } |
| 66 |
| 67 // TODO(viettrungluu): Test the two actions of the button (the normal one and |
| 68 // displaying the menu, also making sure the latter drags correctly)? It would |
| 69 // require "emulating" a mouse.... |
| 70 |
| 71 } // namespace |
| OLD | NEW |