OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 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/mac/scoped_nsobject.h" |
| 6 #import "ios/chrome/browser/ui/ntp/centering_scrollview.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "testing/gtest_mac.h" |
| 9 #include "testing/platform_test.h" |
| 10 |
| 11 namespace { |
| 12 |
| 13 class CenteringScrollViewTest : public PlatformTest { |
| 14 protected: |
| 15 void SetUp() override { |
| 16 scrollView_.reset([[CenteringScrollView alloc] initWithFrame:CGRectZero]); |
| 17 contentView_.reset([[UIView alloc] initWithFrame:CGRectZero]); |
| 18 }; |
| 19 |
| 20 base::scoped_nsobject<CenteringScrollView> scrollView_; |
| 21 base::scoped_nsobject<UIView> contentView_; |
| 22 }; |
| 23 |
| 24 TEST_F(CenteringScrollViewTest, CenteringContent) { |
| 25 // Set up content view to be smaller than the scrolling view. |
| 26 [contentView_ setFrame:CGRectMake(0.0, 0.0, 80.0, 120.0)]; |
| 27 [scrollView_ addSubview:contentView_.get()]; |
| 28 // Do test. |
| 29 [scrollView_ setFrame:CGRectMake(0.0, 0.0, 320, 480.0)]; |
| 30 [scrollView_ layoutSubviews]; |
| 31 // Verify placement of content view. |
| 32 CGRect r = [contentView_ frame]; |
| 33 EXPECT_EQ(120.0, r.origin.x); |
| 34 EXPECT_EQ(180.0, r.origin.y); |
| 35 // Verify that scroller content is set to not scrollable. |
| 36 EXPECT_EQ(0.0, [scrollView_ contentSize].width); |
| 37 EXPECT_EQ(0.0, [scrollView_ contentSize].height); |
| 38 EXPECT_EQ(0.0, [scrollView_ contentOffset].x); |
| 39 EXPECT_EQ(0.0, [scrollView_ contentOffset].y); |
| 40 } |
| 41 |
| 42 TEST_F(CenteringScrollViewTest, ScrollingContent) { |
| 43 // Set up content view taller than the scrolling view. |
| 44 [contentView_ setFrame:CGRectMake(0.0, 0.0, 240.0, 400.0)]; |
| 45 [scrollView_ addSubview:contentView_.get()]; |
| 46 // Do test |
| 47 [scrollView_ setFrame:CGRectMake(0.0, 0.0, 480.0, 320.0)]; |
| 48 [scrollView_ layoutSubviews]; |
| 49 // Verify placement of content view. |
| 50 CGRect r = [contentView_ frame]; |
| 51 EXPECT_EQ(120.0, r.origin.x); |
| 52 EXPECT_EQ(0.0, r.origin.y); |
| 53 // Verify that scroller content is resized correctly. |
| 54 EXPECT_EQ(480.0, [scrollView_ contentSize].width); |
| 55 EXPECT_EQ(400.0, [scrollView_ contentSize].height); |
| 56 EXPECT_EQ(0.0, [scrollView_ contentOffset].x); |
| 57 EXPECT_EQ(0.0, [scrollView_ contentOffset].y); |
| 58 } |
| 59 |
| 60 TEST_F(CenteringScrollViewTest, ResetContentSize) { |
| 61 // Set up content view taller than the scrolling view. |
| 62 [contentView_ setFrame:CGRectMake(0.0, 0.0, 240.0, 400.0)]; |
| 63 [scrollView_ addSubview:contentView_.get()]; |
| 64 |
| 65 [scrollView_ setFrame:CGRectMake(0.0, 0.0, 280.0, 440.0)]; |
| 66 [scrollView_ layoutSubviews]; |
| 67 // Verify that scroller content is set to not scrollable. |
| 68 EXPECT_EQ(0.0, [scrollView_ contentSize].width); |
| 69 EXPECT_EQ(0.0, [scrollView_ contentSize].height); |
| 70 |
| 71 [scrollView_ setFrame:CGRectMake(0.0, 0.0, 200.0, 300.0)]; |
| 72 [scrollView_ layoutSubviews]; |
| 73 // Verify that scroller content is equal to the content view size. |
| 74 EXPECT_EQ(240.0, [scrollView_ contentSize].width); |
| 75 EXPECT_EQ(400.0, [scrollView_ contentSize].height); |
| 76 |
| 77 [scrollView_ setFrame:CGRectMake(0.0, 0.0, 260.0, 420.0)]; |
| 78 [scrollView_ layoutSubviews]; |
| 79 // Verify that scroller content is set to not scrollable. |
| 80 EXPECT_EQ(0.0, [scrollView_ contentSize].width); |
| 81 EXPECT_EQ(0.0, [scrollView_ contentSize].height); |
| 82 } |
| 83 |
| 84 } // anonymous namespace |
OLD | NEW |