Home | History | Annotate | Download | only in cocoa
      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/memory/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 
     13 namespace {
     14 
     15 class ClickHoldButtonCellTest : public CocoaTest {
     16  public:
     17   ClickHoldButtonCellTest() {
     18     NSRect frame = NSMakeRect(0, 0, 50, 30);
     19     scoped_nsobject<NSButton> view([[NSButton alloc] initWithFrame:frame]);
     20     view_ = view.get();
     21     scoped_nsobject<ClickHoldButtonCell> cell(
     22         [[ClickHoldButtonCell alloc] initTextCell:@"Testing"]);
     23     [view_ setCell:cell.get()];
     24     [[test_window() contentView] addSubview:view_];
     25   }
     26 
     27   NSButton* view_;
     28 };
     29 
     30 TEST_VIEW(ClickHoldButtonCellTest, view_)
     31 
     32 // Test default values; make sure they are what they should be.
     33 TEST_F(ClickHoldButtonCellTest, Defaults) {
     34   ClickHoldButtonCell* cell = static_cast<ClickHoldButtonCell*>([view_ cell]);
     35   ASSERT_TRUE([cell isKindOfClass:[ClickHoldButtonCell class]]);
     36 
     37   EXPECT_FALSE([cell enableClickHold]);
     38 
     39   NSTimeInterval clickHoldTimeout = [cell clickHoldTimeout];
     40   EXPECT_GE(clickHoldTimeout, 0.15);  // Check for a "Cocoa-ish" value.
     41   EXPECT_LE(clickHoldTimeout, 0.35);
     42 
     43   EXPECT_FALSE([cell trackOnlyInRect]);
     44   EXPECT_TRUE([cell activateOnDrag]);
     45 }
     46 
     47 // TODO(viettrungluu): (1) Enable click-hold and figure out how to test the
     48 // tracking loop (i.e., |-trackMouse:...|), which is the nontrivial part.
     49 // (2) Test various initialization code paths (in particular, loading from nib).
     50 
     51 }  // namespace
     52