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.
5 #import <Cocoa/Cocoa.h>
7 #include "base/mac/scoped_nsobject.h"
8 #import "chrome/browser/ui/cocoa/clickhold_button_cell.h"
9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h"
15 class ClickHoldButtonCellTest : public CocoaTest {
17 ClickHoldButtonCellTest() {
18 NSRect frame = NSMakeRect(0, 0, 50, 30);
19 base::scoped_nsobject<NSButton> view(
20 [[NSButton alloc] initWithFrame:frame]);
22 base::scoped_nsobject<ClickHoldButtonCell> cell(
23 [[ClickHoldButtonCell alloc] initTextCell:@"Testing"]);
24 [view_ setCell:cell.get()];
25 [[test_window() contentView] addSubview:view_];
31 TEST_VIEW(ClickHoldButtonCellTest, view_)
33 // Test default values; make sure they are what they should be.
34 TEST_F(ClickHoldButtonCellTest, Defaults) {
35 ClickHoldButtonCell* cell = static_cast<ClickHoldButtonCell*>([view_ cell]);
36 ASSERT_TRUE([cell isKindOfClass:[ClickHoldButtonCell class]]);
38 EXPECT_FALSE([cell enableClickHold]);
40 NSTimeInterval clickHoldTimeout = [cell clickHoldTimeout];
41 EXPECT_GE(clickHoldTimeout, 0.15); // Check for a "Cocoa-ish" value.
42 EXPECT_LE(clickHoldTimeout, 0.35);
44 EXPECT_FALSE([cell trackOnlyInRect]);
45 EXPECT_TRUE([cell activateOnDrag]);
48 // TODO(viettrungluu): (1) Enable click-hold and figure out how to test the
49 // tracking loop (i.e., |-trackMouse:...|), which is the nontrivial part.
50 // (2) Test various initialization code paths (in particular, loading from nib).