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/cocoa_test_helper.h"
9 #import "chrome/browser/ui/cocoa/tabs/tab_view.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h"
15 const float kTabWidth = 50;
16 const float kTabHeight = 30;
18 class TabViewTest : public CocoaTest {
21 NSRect frame = NSMakeRect(0, 0, kTabWidth, kTabHeight);
22 base::scoped_nsobject<TabView> view([[TabView alloc] initWithFrame:frame]);
24 [[test_window() contentView] addSubview:view_];
30 TEST_VIEW(TabViewTest, view_)
32 // Test drawing, mostly to ensure nothing leaks or crashes.
33 TEST_F(TabViewTest, Display) {
34 for (int i = 0; i < 5; i++) {
35 for (int j = 0; j < 5; j++) {
36 [view_ setHoverAlpha:i*0.2];
37 [view_ setAlertAlpha:j*0.2];
43 // Test it doesn't crash when asked for its menu with no TabController set.
44 TEST_F(TabViewTest, Menu) {
45 EXPECT_FALSE([view_ menu]);
48 TEST_F(TabViewTest, Glow) {
49 // TODO(viettrungluu): Figure out how to test this, which is timing-sensitive
50 // and which moreover uses |-performSelector:withObject:afterDelay:|.
52 // Call |-startAlert|/|-cancelAlert| and make sure it doesn't crash.
53 for (int i = 0; i < 5; i++) {
63 // Test that clicks outside of the visible boundaries are ignored.
64 TEST_F(TabViewTest, ClickOnlyInVisibleBounds) {
65 NSPoint bottomLeftCorner = NSMakePoint(5, 0);
66 EXPECT_TRUE([view_ hitTest:bottomLeftCorner]);
68 NSPoint topLeftCorner = NSMakePoint(0, kTabHeight);
69 EXPECT_FALSE([view_ hitTest:topLeftCorner]);
71 NSPoint middle = NSMakePoint(kTabWidth / 2, kTabHeight / 2);
72 EXPECT_TRUE([view_ hitTest:middle]);