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.
4
5#import <Cocoa/Cocoa.h>
6
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"
12
13namespace {
14
15class ClickHoldButtonCellTest : public CocoaTest {
16 public:
17  ClickHoldButtonCellTest() {
18    NSRect frame = NSMakeRect(0, 0, 50, 30);
19    base::scoped_nsobject<NSButton> view(
20        [[NSButton alloc] initWithFrame:frame]);
21    view_ = view.get();
22    base::scoped_nsobject<ClickHoldButtonCell> cell(
23        [[ClickHoldButtonCell alloc] initTextCell:@"Testing"]);
24    [view_ setCell:cell.get()];
25    [[test_window() contentView] addSubview:view_];
26  }
27
28  NSButton* view_;
29};
30
31TEST_VIEW(ClickHoldButtonCellTest, view_)
32
33// Test default values; make sure they are what they should be.
34TEST_F(ClickHoldButtonCellTest, Defaults) {
35  ClickHoldButtonCell* cell = static_cast<ClickHoldButtonCell*>([view_ cell]);
36  ASSERT_TRUE([cell isKindOfClass:[ClickHoldButtonCell class]]);
37
38  EXPECT_FALSE([cell enableClickHold]);
39
40  NSTimeInterval clickHoldTimeout = [cell clickHoldTimeout];
41  EXPECT_GE(clickHoldTimeout, 0.15);  // Check for a "Cocoa-ish" value.
42  EXPECT_LE(clickHoldTimeout, 0.35);
43
44  EXPECT_FALSE([cell trackOnlyInRect]);
45  EXPECT_TRUE([cell activateOnDrag]);
46}
47
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).
51
52}  // namespace
53