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