| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/mac/scoped_nsobject.h" | 5 #include "base/mac/scoped_nsobject.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" | 7 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" |
| 8 #import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h" | 8 #import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "testing/platform_test.h" | 10 #include "testing/platform_test.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 const CGFloat kContainerHeight = 15.0; | 14 const CGFloat kContainerHeight = 15.0; |
| 15 const CGFloat kMinimumContainerWidth = 3.0; | 15 const CGFloat kMinimumContainerWidth = 3.0; |
| 16 const CGFloat kMaxAllowedWidthForTest = 50.0; | 16 const CGFloat kMaxAllowedWidthForTest = 50.0; |
| 17 | 17 |
| 18 class BrowserActionsContainerTestDelegate | |
| 19 : public BrowserActionsContainerViewSizeDelegate { | |
| 20 public: | |
| 21 BrowserActionsContainerTestDelegate() {} | |
| 22 ~BrowserActionsContainerTestDelegate() override {} | |
| 23 | |
| 24 CGFloat GetMaxAllowedWidth() override { return kMaxAllowedWidthForTest; } | |
| 25 | |
| 26 private: | |
| 27 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainerTestDelegate); | |
| 28 }; | |
| 29 | |
| 30 class BrowserActionsContainerViewTest : public CocoaTest { | 18 class BrowserActionsContainerViewTest : public CocoaTest { |
| 31 public: | 19 public: |
| 32 void SetUp() override { | 20 void SetUp() override { |
| 33 CocoaTest::SetUp(); | 21 CocoaTest::SetUp(); |
| 34 view_.reset([[BrowserActionsContainerView alloc] | 22 view_.reset([[BrowserActionsContainerView alloc] |
| 35 initWithFrame:NSMakeRect(0, 0, 0, kContainerHeight)]); | 23 initWithFrame:NSMakeRect(0, 0, 0, kContainerHeight)]); |
| 36 } | 24 } |
| 37 | 25 |
| 38 base::scoped_nsobject<BrowserActionsContainerView> view_; | 26 base::scoped_nsobject<BrowserActionsContainerView> view_; |
| 39 }; | 27 }; |
| 40 | 28 |
| 41 TEST_F(BrowserActionsContainerViewTest, BasicTests) { | 29 TEST_F(BrowserActionsContainerViewTest, BasicTests) { |
| 42 EXPECT_TRUE([view_ canDragLeft]); | |
| 43 EXPECT_TRUE([view_ canDragRight]); | |
| 44 EXPECT_TRUE([view_ isHidden]); | 30 EXPECT_TRUE([view_ isHidden]); |
| 45 } | 31 } |
| 46 | 32 |
| 47 TEST_F(BrowserActionsContainerViewTest, SetWidthTests) { | 33 TEST_F(BrowserActionsContainerViewTest, SetWidthTests) { |
| 48 // Try setting below the minimum width (10 pixels). | 34 [view_ setMinWidth:kMinimumContainerWidth]; |
| 35 [view_ setMaxWidth:kMaxAllowedWidthForTest]; |
| 36 |
| 37 // Try setting below the minimum width. |
| 49 [view_ resizeToWidth:kMinimumContainerWidth - 1 animate:NO]; | 38 [view_ resizeToWidth:kMinimumContainerWidth - 1 animate:NO]; |
| 50 EXPECT_EQ(kMinimumContainerWidth, NSWidth([view_ frame])) << "Frame width is " | 39 EXPECT_EQ(kMinimumContainerWidth, NSWidth([view_ frame])) << "Frame width is " |
| 51 << "less than the minimum allowed."; | 40 << "less than the minimum allowed."; |
| 52 | 41 |
| 53 [view_ resizeToWidth:35.0 animate:NO]; | 42 [view_ resizeToWidth:35.0 animate:NO]; |
| 54 EXPECT_EQ(35.0, NSWidth([view_ frame])); | 43 EXPECT_EQ(35.0, NSWidth([view_ frame])); |
| 55 | 44 |
| 56 [view_ resizeToWidth:20.0 animate:NO]; | 45 [view_ resizeToWidth:20.0 animate:NO]; |
| 57 EXPECT_EQ(20.0, NSWidth([view_ frame])); | 46 EXPECT_EQ(20.0, NSWidth([view_ frame])); |
| 58 | 47 |
| 59 // Resize the view with animation. It shouldn't immediately take the new | 48 // Resize the view with animation. It shouldn't immediately take the new |
| 60 // value, but the animationEndFrame should reflect the pending change. | 49 // value, but the animationEndFrame should reflect the pending change. |
| 61 [view_ resizeToWidth:40.0 animate:YES]; | 50 [view_ resizeToWidth:40.0 animate:YES]; |
| 62 EXPECT_LE(NSWidth([view_ frame]), 40.0); | 51 EXPECT_LE(NSWidth([view_ frame]), 40.0); |
| 63 EXPECT_EQ(40.0, NSWidth([view_ animationEndFrame])); | 52 EXPECT_EQ(40.0, NSWidth([view_ animationEndFrame])); |
| 64 | 53 |
| 65 // The container should be able to be resized while animating (simply taking | 54 // The container should be able to be resized while animating (simply taking |
| 66 // the newest target width). | 55 // the newest target width). |
| 67 [view_ resizeToWidth:30.0 animate:YES]; | 56 [view_ resizeToWidth:30.0 animate:YES]; |
| 68 EXPECT_EQ(30.0, NSWidth([view_ animationEndFrame])); | 57 EXPECT_EQ(30.0, NSWidth([view_ animationEndFrame])); |
| 69 | 58 |
| 70 // Test with no animation again. The animationEndFrame should also reflect | 59 // Test with no animation again. The animationEndFrame should also reflect |
| 71 // the current frame, if no animation is pending. | 60 // the current frame, if no animation is pending. |
| 72 [view_ resizeToWidth:35.0 animate:NO]; | 61 [view_ resizeToWidth:35.0 animate:NO]; |
| 73 EXPECT_EQ(35.0, NSWidth([view_ frame])); | 62 EXPECT_EQ(35.0, NSWidth([view_ frame])); |
| 74 EXPECT_EQ(35.0, NSWidth([view_ animationEndFrame])); | 63 EXPECT_EQ(35.0, NSWidth([view_ animationEndFrame])); |
| 75 | 64 |
| 76 BrowserActionsContainerTestDelegate delegate; | |
| 77 [view_ setDelegate:&delegate]; | |
| 78 [view_ resizeToWidth:kMaxAllowedWidthForTest + 10.0 animate:NO]; | 65 [view_ resizeToWidth:kMaxAllowedWidthForTest + 10.0 animate:NO]; |
| 79 EXPECT_EQ(kMaxAllowedWidthForTest, NSWidth([view_ frame])); | 66 EXPECT_EQ(kMaxAllowedWidthForTest, NSWidth([view_ frame])); |
| 80 [view_ setDelegate:nil]; | |
| 81 } | 67 } |
| 82 | 68 |
| 83 } // namespace | 69 } // namespace |
| OLD | NEW |