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

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

Issue 334016: First set of unittest fixes. Many more to come ;-)... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/cocoa/infobar_gradient_view_unittest.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 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 <Cocoa/Cocoa.h>
6
7 #include "base/scoped_nsobject.h" 5 #include "base/scoped_nsobject.h"
8 #import "chrome/browser/cocoa/clickhold_button_cell.h" 6 #import "chrome/browser/cocoa/clickhold_button_cell.h"
9 #import "chrome/browser/cocoa/cocoa_test_helper.h" 7 #import "chrome/browser/cocoa/cocoa_test_helper.h"
10 #import "chrome/browser/cocoa/menu_button.h" 8 #import "chrome/browser/cocoa/menu_button.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/platform_test.h"
13 9
14 namespace { 10 namespace {
15 11
16 class MenuButtonTest : public PlatformTest { 12 class MenuButtonTest : public CocoaTest {
17 public: 13 public:
18 MenuButtonTest() { 14 MenuButtonTest() {
19 NSRect frame = NSMakeRect(0, 0, 50, 30); 15 NSRect frame = NSMakeRect(0, 0, 50, 30);
20 button_.reset([[MenuButton alloc] initWithFrame:frame]); 16 scoped_nsobject<MenuButton> button(
17 [[MenuButton alloc] initWithFrame:frame]);
18 button_ = button.get();
21 scoped_nsobject<ClickHoldButtonCell> cell( 19 scoped_nsobject<ClickHoldButtonCell> cell(
22 [[ClickHoldButtonCell alloc] initTextCell:@"Testing"]); 20 [[ClickHoldButtonCell alloc] initTextCell:@"Testing"]);
23 [button_ setCell:cell.get()]; 21 [button_ setCell:cell.get()];
24 [cocoa_helper_.contentView() addSubview:button_.get()]; 22 [[test_window() contentView] addSubview:button_];
25 } 23 }
26 24
27 scoped_nsobject<MenuButton> button_; 25 MenuButton* button_;
28 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc.
29 }; 26 };
30 27
31 // Test adding/removing from the view hierarchy, mostly to ensure nothing leaks 28 TEST_VIEW(MenuButtonTest, button_)
32 // or crashes.
33 TEST_F(MenuButtonTest, 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(MenuButtonTest, Display) {
41 [button_ display];
42 }
43 29
44 // Test assigning a menu, again mostly to ensure nothing leaks or crashes. 30 // Test assigning a menu, again mostly to ensure nothing leaks or crashes.
45 TEST_F(MenuButtonTest, MenuAssign) { 31 TEST_F(MenuButtonTest, MenuAssign) {
46 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); 32 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]);
47 ASSERT_TRUE(menu.get()); 33 ASSERT_TRUE(menu.get());
48 34
49 [menu insertItemWithTitle:@"" action:nil keyEquivalent:@"" atIndex:0]; 35 [menu insertItemWithTitle:@"" action:nil keyEquivalent:@"" atIndex:0];
50 [menu insertItemWithTitle:@"foo" action:nil keyEquivalent:@"" atIndex:1]; 36 [menu insertItemWithTitle:@"foo" action:nil keyEquivalent:@"" atIndex:1];
51 [menu insertItemWithTitle:@"bar" action:nil keyEquivalent:@"" atIndex:2]; 37 [menu insertItemWithTitle:@"bar" action:nil keyEquivalent:@"" atIndex:2];
52 [menu insertItemWithTitle:@"baz" action:nil keyEquivalent:@"" atIndex:3]; 38 [menu insertItemWithTitle:@"baz" action:nil keyEquivalent:@"" atIndex:3];
53 39
54 [button_ setAttachedMenu:menu]; 40 [button_ setAttachedMenu:menu];
55 EXPECT_TRUE([button_ attachedMenu]); 41 EXPECT_TRUE([button_ attachedMenu]);
56 42
57 // TODO(viettrungluu): Display the menu. (The tough part is closing the menu, 43 // TODO(viettrungluu): Display the menu. (The tough part is closing the menu,
58 // not opening it!) 44 // not opening it!)
59 45
60 // Since |button_| doesn't retain menu, we should probably unset it here. 46 // Since |button_| doesn't retain menu, we should probably unset it here.
61 [button_ setAttachedMenu:nil]; 47 [button_ setAttachedMenu:nil];
62 } 48 }
63 49
64 } // namespace 50 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/infobar_gradient_view_unittest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698