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(
23 [[TabView alloc] initWithFrame:frame controller:nil closeButton:nil]);
25 [[test_window() contentView] addSubview:view_];
31 TEST_VIEW(TabViewTest, view_)
33 // Test drawing, mostly to ensure nothing leaks or crashes.
34 TEST_F(TabViewTest, Display) {
35 for (int i = 0; i < 5; i++) {
36 for (int j = 0; j < 5; j++) {
37 [view_ setHoverAlpha:i*0.2];
38 [view_ setAlertAlpha:j*0.2];
44 // Test it doesn't crash when asked for its menu with no TabController set.
45 TEST_F(TabViewTest, Menu) {
46 EXPECT_FALSE([view_ menu]);
49 TEST_F(TabViewTest, Glow) {
50 // TODO(viettrungluu): Figure out how to test this, which is timing-sensitive
51 // and which moreover uses |-performSelector:withObject:afterDelay:|.
53 // Call |-startAlert|/|-cancelAlert| and make sure it doesn't crash.
54 for (int i = 0; i < 5; i++) {
64 // Test that clicks outside of the visible boundaries are ignored.
65 TEST_F(TabViewTest, ClickOnlyInVisibleBounds) {
66 NSPoint bottomLeftCorner = NSMakePoint(5, 0);
67 EXPECT_TRUE([view_ hitTest:bottomLeftCorner]);
69 NSPoint topLeftCorner = NSMakePoint(0, kTabHeight);
70 EXPECT_FALSE([view_ hitTest:topLeftCorner]);
72 NSPoint middle = NSMakePoint(kTabWidth / 2, kTabHeight / 2);
73 EXPECT_TRUE([view_ hitTest:middle]);