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 #include "base/memory/scoped_nsobject.h" 6 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 7 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" 8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/platform_test.h" 10 11 namespace { 12 13 const CGFloat kContainerHeight = 15.0; 14 const CGFloat kMinimumContainerWidth = 10.0; 15 16 class BrowserActionsContainerViewTest : public CocoaTest { 17 public: 18 virtual void SetUp() { 19 CocoaTest::SetUp(); 20 view_.reset([[BrowserActionsContainerView alloc] 21 initWithFrame:NSMakeRect(0, 0, 0, kContainerHeight)]); 22 } 23 24 scoped_nsobject<BrowserActionsContainerView> view_; 25 }; 26 27 TEST_F(BrowserActionsContainerViewTest, BasicTests) { 28 EXPECT_TRUE([view_ isResizable]); 29 EXPECT_TRUE([view_ canDragLeft]); 30 EXPECT_TRUE([view_ canDragRight]); 31 EXPECT_TRUE([view_ isHidden]); 32 } 33 34 TEST_F(BrowserActionsContainerViewTest, SetWidthTests) { 35 // Try setting below the minimum width (10 pixels). 36 [view_ resizeToWidth:5.0 animate:NO]; 37 EXPECT_EQ(kMinimumContainerWidth, NSWidth([view_ frame])) << "Frame width is " 38 << "less than the minimum allowed."; 39 // Since the frame expands to the left, the x-position delta value will be 40 // negative. 41 EXPECT_EQ(-kMinimumContainerWidth, [view_ resizeDeltaX]); 42 43 [view_ resizeToWidth:35.0 animate:NO]; 44 EXPECT_EQ(35.0, NSWidth([view_ frame])); 45 EXPECT_EQ(-25.0, [view_ resizeDeltaX]); 46 47 [view_ resizeToWidth:20.0 animate:NO]; 48 EXPECT_EQ(20.0, NSWidth([view_ frame])); 49 EXPECT_EQ(15.0, [view_ resizeDeltaX]); 50 } 51 52 } // namespace 53