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/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" 12 13 namespace { 14 15 class TabViewTest : public CocoaTest { 16 public: 17 TabViewTest() { 18 NSRect frame = NSMakeRect(0, 0, 50, 30); 19 scoped_nsobject<TabView> view([[TabView alloc] initWithFrame:frame]); 20 view_ = view.get(); 21 [[test_window() contentView] addSubview:view_]; 22 } 23 24 TabView* view_; 25 }; 26 27 TEST_VIEW(TabViewTest, view_) 28 29 // Test drawing, mostly to ensure nothing leaks or crashes. 30 TEST_F(TabViewTest, Display) { 31 for (int i = 0; i < 5; i++) { 32 for (int j = 0; j < 5; j++) { 33 [view_ setHoverAlpha:i*0.2]; 34 [view_ setAlertAlpha:j*0.2]; 35 [view_ display]; 36 } 37 } 38 } 39 40 // Test it doesn't crash when asked for its menu with no TabController set. 41 TEST_F(TabViewTest, Menu) { 42 EXPECT_FALSE([view_ menu]); 43 } 44 45 TEST_F(TabViewTest, Glow) { 46 // TODO(viettrungluu): Figure out how to test this, which is timing-sensitive 47 // and which moreover uses |-performSelector:withObject:afterDelay:|. 48 49 // Call |-startAlert|/|-cancelAlert| and make sure it doesn't crash. 50 for (int i = 0; i < 5; i++) { 51 [view_ startAlert]; 52 [view_ cancelAlert]; 53 } 54 [view_ startAlert]; 55 [view_ startAlert]; 56 [view_ cancelAlert]; 57 [view_ cancelAlert]; 58 } 59 60 } // namespace 61