blob: 6b7ba2be5c95da361d0349440c4da7ac854846df (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/scoped_nsobject.h"
#import "chrome/browser/cocoa/clickhold_button_cell.h"
#import "chrome/browser/cocoa/cocoa_test_helper.h"
#import "chrome/browser/cocoa/menu_button.h"
namespace {
class MenuButtonTest : public CocoaTest {
public:
MenuButtonTest() {
NSRect frame = NSMakeRect(0, 0, 50, 30);
scoped_nsobject<MenuButton> button(
[[MenuButton alloc] initWithFrame:frame]);
button_ = button.get();
scoped_nsobject<ClickHoldButtonCell> cell(
[[ClickHoldButtonCell alloc] initTextCell:@"Testing"]);
[button_ setCell:cell.get()];
[[test_window() contentView] addSubview:button_];
}
MenuButton* button_;
};
TEST_VIEW(MenuButtonTest, button_);
// Test assigning a menu, again mostly to ensure nothing leaks or crashes.
TEST_F(MenuButtonTest, MenuAssign) {
scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]);
ASSERT_TRUE(menu.get());
[menu insertItemWithTitle:@"" action:nil keyEquivalent:@"" atIndex:0];
[menu insertItemWithTitle:@"foo" action:nil keyEquivalent:@"" atIndex:1];
[menu insertItemWithTitle:@"bar" action:nil keyEquivalent:@"" atIndex:2];
[menu insertItemWithTitle:@"baz" action:nil keyEquivalent:@"" atIndex:3];
[button_ setAttachedMenu:menu];
EXPECT_TRUE([button_ attachedMenu]);
// TODO(viettrungluu): Display the menu. (The tough part is closing the menu,
// not opening it!)
// Since |button_| doesn't retain menu, we should probably unset it here.
[button_ setAttachedMenu:nil];
}
} // namespace
|