Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2234)

Side by Side Diff: chrome/browser/cocoa/delayedmenu_button_unittest.mm

Issue 179043: (Mac) Added unit tests for ClickHoldButtonCell and DelayedMenuButton. (Closed)
Patch Set: Read gtest docs; using constructors instead of SetUp() is okay. Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/cocoa/delayedmenu_button.mm ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/delayedmenu_button.mm ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698