OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" | 5 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" |
6 | 6 |
7 #import "base/mac/scoped_nsobject.h" | |
8 #import "ios/web/web_state/ui/crw_web_view_proxy_impl.h" | 7 #import "ios/web/web_state/ui/crw_web_view_proxy_impl.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
10 #import "testing/gtest_mac.h" | 9 #import "testing/gtest_mac.h" |
11 #include "testing/platform_test.h" | 10 #include "testing/platform_test.h" |
12 #import "third_party/ocmock/OCMock/OCMock.h" | 11 #import "third_party/ocmock/OCMock/OCMock.h" |
13 #include "third_party/ocmock/gtest_support.h" | 12 #include "third_party/ocmock/gtest_support.h" |
14 | 13 |
| 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 15 #error "This file requires ARC support." |
| 16 #endif |
| 17 |
15 namespace { | 18 namespace { |
16 // The frame of CRWWebControllerContainerViewTest's |container_view_|. | 19 // The frame of CRWWebControllerContainerViewTest's |container_view_|. |
17 const CGRect kContainerViewFrame = CGRectMake(0.0f, 0.0f, 200.0f, 300.0f); | 20 const CGRect kContainerViewFrame = CGRectMake(0.0f, 0.0f, 200.0f, 300.0f); |
18 // TestToolbarView's frame height. | 21 // TestToolbarView's frame height. |
19 const CGFloat kTestToolbarViewHeight = 50.0f; | 22 const CGFloat kTestToolbarViewHeight = 50.0f; |
20 } | 23 } |
21 | 24 |
22 // Test view to use as a toolbar. | 25 // Test view to use as a toolbar. |
23 @interface TestToolbarView : UIView | 26 @interface TestToolbarView : UIView |
24 @end | 27 @end |
25 | 28 |
26 @implementation TestToolbarView | 29 @implementation TestToolbarView |
27 - (CGSize)sizeThatFits:(CGSize)size { | 30 - (CGSize)sizeThatFits:(CGSize)size { |
28 return CGSizeMake(size.width, kTestToolbarViewHeight); | 31 return CGSizeMake(size.width, kTestToolbarViewHeight); |
29 } | 32 } |
30 @end | 33 @end |
31 | 34 |
32 // Test CRWWebControllerContainerViewDelegate implementation. | 35 // Test CRWWebControllerContainerViewDelegate implementation. |
33 @interface TestWebControllerContainerViewDelegate | 36 @interface TestWebControllerContainerViewDelegate |
34 : NSObject<CRWWebControllerContainerViewDelegate> { | 37 : NSObject<CRWWebControllerContainerViewDelegate> { |
35 base::scoped_nsobject<CRWWebViewProxyImpl> _proxy; | 38 CRWWebViewProxyImpl* _proxy; |
36 } | 39 } |
37 - (instancetype)initWithContentViewProxy:(CRWWebViewProxyImpl*)proxy; | 40 - (instancetype)initWithContentViewProxy:(CRWWebViewProxyImpl*)proxy; |
38 @end | 41 @end |
39 | 42 |
40 @implementation TestWebControllerContainerViewDelegate | 43 @implementation TestWebControllerContainerViewDelegate |
41 | 44 |
42 - (instancetype)initWithContentViewProxy:(CRWWebViewProxyImpl*)proxy { | 45 - (instancetype)initWithContentViewProxy:(CRWWebViewProxyImpl*)proxy { |
43 if ((self = [super init])) | 46 if ((self = [super init])) |
44 _proxy.reset([proxy retain]); | 47 _proxy = proxy; |
45 return self; | 48 return self; |
46 } | 49 } |
47 | 50 |
48 - (CRWWebViewProxyImpl*)contentViewProxyForContainerView: | 51 - (CRWWebViewProxyImpl*)contentViewProxyForContainerView: |
49 (CRWWebControllerContainerView*)containerView { | 52 (CRWWebControllerContainerView*)containerView { |
50 return _proxy.get(); | 53 return _proxy; |
51 } | 54 } |
52 | 55 |
53 - (CGFloat)headerHeightForContainerView: | 56 - (CGFloat)headerHeightForContainerView: |
54 (CRWWebControllerContainerView*)containerView { | 57 (CRWWebControllerContainerView*)containerView { |
55 return 0; | 58 return 0; |
56 } | 59 } |
57 | 60 |
58 @end | 61 @end |
59 | 62 |
60 #pragma mark - CRWWebControllerContainerViewTest | 63 #pragma mark - CRWWebControllerContainerViewTest |
61 | 64 |
62 class CRWWebControllerContainerViewTest : public PlatformTest { | 65 class CRWWebControllerContainerViewTest : public PlatformTest { |
63 protected: | 66 protected: |
64 void SetUp() override { | 67 void SetUp() override { |
65 PlatformTest::SetUp(); | 68 PlatformTest::SetUp(); |
66 CRWWebViewProxyImpl* proxy = | 69 CRWWebViewProxyImpl* proxy = |
67 [OCMockObject niceMockForClass:[CRWWebViewProxyImpl class]]; | 70 [OCMockObject niceMockForClass:[CRWWebViewProxyImpl class]]; |
68 delegate_.reset([[TestWebControllerContainerViewDelegate alloc] | 71 delegate_ = [[TestWebControllerContainerViewDelegate alloc] |
69 initWithContentViewProxy:proxy]); | 72 initWithContentViewProxy:proxy]; |
70 container_view_.reset( | 73 container_view_ = |
71 [[CRWWebControllerContainerView alloc] initWithDelegate:delegate_]); | 74 [[CRWWebControllerContainerView alloc] initWithDelegate:delegate_]; |
72 [container_view_ setFrame:kContainerViewFrame]; | 75 [container_view_ setFrame:kContainerViewFrame]; |
73 } | 76 } |
74 | 77 |
75 // The CRWWebControllerContainerViewDelegate (required for designated | 78 // The CRWWebControllerContainerViewDelegate (required for designated |
76 // initializer). | 79 // initializer). |
77 base::scoped_nsobject<TestWebControllerContainerViewDelegate> delegate_; | 80 TestWebControllerContainerViewDelegate* delegate_; |
78 // The container view being tested. | 81 // The container view being tested. |
79 base::scoped_nsobject<CRWWebControllerContainerView> container_view_; | 82 CRWWebControllerContainerView* container_view_; |
80 }; | 83 }; |
81 | 84 |
82 // Tests that |-addToolbar:| will successfully add the passed-in toolbar to the | 85 // Tests that |-addToolbar:| will successfully add the passed-in toolbar to the |
83 // container view and will correctly reset its frame to be bottom-aligned with | 86 // container view and will correctly reset its frame to be bottom-aligned with |
84 // the container's width. | 87 // the container's width. |
85 TEST_F(CRWWebControllerContainerViewTest, AddToolbar) { | 88 TEST_F(CRWWebControllerContainerViewTest, AddToolbar) { |
86 base::scoped_nsobject<TestToolbarView> toolbar( | 89 TestToolbarView* toolbar = [[TestToolbarView alloc] initWithFrame:CGRectZero]; |
87 [[TestToolbarView alloc] initWithFrame:CGRectZero]); | |
88 [container_view_ addToolbar:toolbar]; | 90 [container_view_ addToolbar:toolbar]; |
89 [container_view_ layoutIfNeeded]; | 91 [container_view_ layoutIfNeeded]; |
90 // Check that the toolbar has been added to the container view. | 92 // Check that the toolbar has been added to the container view. |
91 EXPECT_TRUE([toolbar isDescendantOfView:container_view_]); | 93 EXPECT_TRUE([toolbar isDescendantOfView:container_view_]); |
92 // Check the toolbar's frame. | 94 // Check the toolbar's frame. |
93 CGRect expected_toolbar_frame = CGRectMake( | 95 CGRect expected_toolbar_frame = CGRectMake( |
94 CGRectGetMinX([container_view_ bounds]), | 96 CGRectGetMinX([container_view_ bounds]), |
95 CGRectGetMaxY([container_view_ bounds]) - kTestToolbarViewHeight, | 97 CGRectGetMaxY([container_view_ bounds]) - kTestToolbarViewHeight, |
96 CGRectGetWidth(kContainerViewFrame), kTestToolbarViewHeight); | 98 CGRectGetWidth(kContainerViewFrame), kTestToolbarViewHeight); |
97 CGRect toolbar_container_frame = | 99 CGRect toolbar_container_frame = |
98 [container_view_ convertRect:[toolbar bounds] fromView:toolbar]; | 100 [container_view_ convertRect:[toolbar bounds] fromView:toolbar]; |
99 EXPECT_TRUE(CGRectEqualToRect(expected_toolbar_frame, | 101 EXPECT_TRUE(CGRectEqualToRect(expected_toolbar_frame, |
100 toolbar_container_frame)); | 102 toolbar_container_frame)); |
101 } | 103 } |
OLD | NEW |