Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: ios/web/web_state/crw_web_view_scroll_view_proxy_unittest.mm

Issue 2752113002: Moved WebView(ScrollView)Proxy files to ui subdirectory. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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 #import "ios/web/public/web_state/crw_web_view_scroll_view_proxy.h"
6
7 #import <UIKit/UIKit.h>
8
9 #include "base/compiler_specific.h"
10 #import "base/mac/scoped_nsobject.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #import "third_party/ocmock/OCMock/OCMock.h"
13 #include "third_party/ocmock/gtest_support.h"
14
15 namespace {
16
17 class CRWWebViewScrollViewProxyTest : public ::testing::Test {
18 protected:
19 void SetUp() override {
20 mockScrollView_.reset(
21 [[OCMockObject niceMockForClass:[UIScrollView class]] retain]);
22 webViewScrollViewProxy_.reset([[CRWWebViewScrollViewProxy alloc] init]);
23 }
24 base::scoped_nsobject<id> mockScrollView_;
25 base::scoped_nsobject<CRWWebViewScrollViewProxy> webViewScrollViewProxy_;
26 };
27
28 // Tests that the UIScrollViewDelegate is set correctly.
29 TEST_F(CRWWebViewScrollViewProxyTest, testDelegate) {
30 [static_cast<UIScrollView*>([mockScrollView_ expect])
31 setDelegate:webViewScrollViewProxy_.get()];
32 [webViewScrollViewProxy_ setScrollView:mockScrollView_];
33 EXPECT_OCMOCK_VERIFY(mockScrollView_);
34 }
35
36 // Tests that setting 2 scroll views consecutively, clears the delegate of the
37 // previous scroll view.
38 TEST_F(CRWWebViewScrollViewProxyTest, testMultipleScrollView) {
39 base::scoped_nsobject<UIScrollView> mockScrollView1(
40 [[UIScrollView alloc] init]);
41 base::scoped_nsobject<UIScrollView> mockScrollView2(
42 [[UIScrollView alloc] init]);
43 [webViewScrollViewProxy_ setScrollView:mockScrollView1];
44 [webViewScrollViewProxy_ setScrollView:mockScrollView2];
45 EXPECT_FALSE([mockScrollView1 delegate]);
46 EXPECT_EQ(webViewScrollViewProxy_.get(), [mockScrollView2 delegate]);
47 [webViewScrollViewProxy_ setScrollView:nil];
48 }
49
50 // Tests that when releasing a scroll view from the CRWWebViewScrollViewProxy,
51 // the UIScrollView's delegate is also cleared.
52 TEST_F(CRWWebViewScrollViewProxyTest, testDelegateClearingUp) {
53 base::scoped_nsobject<UIScrollView> mockScrollView1(
54 [[UIScrollView alloc] init]);
55 [webViewScrollViewProxy_ setScrollView:mockScrollView1];
56 EXPECT_EQ(webViewScrollViewProxy_.get(), [mockScrollView1 delegate]);
57 [webViewScrollViewProxy_ setScrollView:nil];
58 EXPECT_FALSE([mockScrollView1 delegate]);
59 }
60
61 // Tests that CRWWebViewScrollViewProxy returns the correct property values from
62 // the underlying UIScrollView.
63 TEST_F(CRWWebViewScrollViewProxyTest, testScrollViewPresent) {
64 [webViewScrollViewProxy_ setScrollView:mockScrollView_];
65 BOOL yes = YES;
66 [[[mockScrollView_ stub] andReturnValue:OCMOCK_VALUE(yes)] isZooming];
67 EXPECT_TRUE([webViewScrollViewProxy_ isZooming]);
68
69 // Arbitrary point.
70 const CGPoint point = CGPointMake(10, 10);
71 [[[mockScrollView_ stub]
72 andReturnValue:[NSValue valueWithCGPoint:point]] contentOffset];
73 EXPECT_TRUE(CGPointEqualToPoint(point,
74 [webViewScrollViewProxy_ contentOffset]));
75
76 // Arbitrary inset.
77 const UIEdgeInsets contentInset = UIEdgeInsetsMake(10, 10, 10, 10);
78 [[[mockScrollView_ stub] andReturnValue:
79 [NSValue valueWithUIEdgeInsets:contentInset]] contentInset];
80 EXPECT_TRUE(UIEdgeInsetsEqualToEdgeInsets(contentInset,
81 [webViewScrollViewProxy_ contentInset]));
82
83 // Arbitrary inset.
84 const UIEdgeInsets scrollIndicatorInsets = UIEdgeInsetsMake(20, 20, 20, 20);
85 [[[mockScrollView_ stub] andReturnValue:[NSValue
86 valueWithUIEdgeInsets:scrollIndicatorInsets]] scrollIndicatorInsets];
87 EXPECT_TRUE(UIEdgeInsetsEqualToEdgeInsets(scrollIndicatorInsets,
88 [webViewScrollViewProxy_ scrollIndicatorInsets]));
89
90 // Arbitrary size.
91 const CGSize contentSize = CGSizeMake(19, 19);
92 [[[mockScrollView_ stub] andReturnValue:
93 [NSValue valueWithCGSize:contentSize]] contentSize];
94 EXPECT_TRUE(CGSizeEqualToSize(contentSize,
95 [webViewScrollViewProxy_ contentSize]));
96
97 // Arbitrary rect.
98 const CGRect frame = CGRectMake(2, 4, 5, 1);
99 [[[mockScrollView_ stub] andReturnValue:
100 [NSValue valueWithCGRect:frame]] frame];
101 EXPECT_TRUE(CGRectEqualToRect(frame,
102 [webViewScrollViewProxy_ frame]));
103 }
104
105 // Tests that CRWWebViewScrollViewProxy returns the correct property values when
106 // there is no underlying UIScrollView.
107 TEST_F(CRWWebViewScrollViewProxyTest, testScrollViewAbsent) {
108 [webViewScrollViewProxy_ setScrollView:nil];
109
110 EXPECT_TRUE(CGPointEqualToPoint(CGPointZero,
111 [webViewScrollViewProxy_ contentOffset]));
112 EXPECT_TRUE(UIEdgeInsetsEqualToEdgeInsets(
113 UIEdgeInsetsZero, [webViewScrollViewProxy_ contentInset]));
114 EXPECT_TRUE(UIEdgeInsetsEqualToEdgeInsets(
115 UIEdgeInsetsZero, [webViewScrollViewProxy_ scrollIndicatorInsets]));
116 EXPECT_TRUE(CGSizeEqualToSize(CGSizeZero,
117 [webViewScrollViewProxy_ contentSize]));
118 EXPECT_TRUE(CGRectEqualToRect(CGRectZero,
119 [webViewScrollViewProxy_ frame]));
120
121 // Make sure setting the properties is fine too.
122 // Arbitrary point.
123 const CGPoint kPoint = CGPointMake(10, 10);
124 [webViewScrollViewProxy_ setContentOffset:kPoint];
125 // Arbitrary inset.
126 const UIEdgeInsets kContentInset = UIEdgeInsetsMake(10, 10, 10, 10);
127 [webViewScrollViewProxy_ setContentInset:kContentInset];
128 [webViewScrollViewProxy_ setScrollIndicatorInsets:kContentInset];
129 // Arbitrary size.
130 const CGSize kContentSize = CGSizeMake(19, 19);
131 [webViewScrollViewProxy_ setContentSize:kContentSize];
132 }
133
134 // Tests releasing a scroll view when none is owned by the
135 // CRWWebViewScrollViewProxy.
136 TEST_F(CRWWebViewScrollViewProxyTest, testReleasingAScrollView) {
137 [webViewScrollViewProxy_ setScrollView:nil];
138 }
139
140 // Tests that multiple WebViewScrollViewProxies hold onto the same underlying
141 // UIScrollView
142 TEST_F(CRWWebViewScrollViewProxyTest, testMultipleWebViewScrollViewProxies) {
143 [webViewScrollViewProxy_ setScrollView:mockScrollView_];
144
145 base::scoped_nsobject<CRWWebViewScrollViewProxy> webViewScrollViewProxy1(
146 [[CRWWebViewScrollViewProxy alloc] init]);
147 [webViewScrollViewProxy1 setScrollView:mockScrollView_];
148
149 base::scoped_nsobject<CRWWebViewScrollViewProxy> webViewScrollViewProxy2(
150 [[CRWWebViewScrollViewProxy alloc] init]);
151 [webViewScrollViewProxy2 setScrollView:mockScrollView_];
152
153 // Arbitrary point.
154 const CGPoint point = CGPointMake(10, 10);
155 [[[mockScrollView_ stub]
156 andReturnValue:[NSValue valueWithCGPoint:point]] contentOffset];
157 EXPECT_TRUE(CGPointEqualToPoint(point,
158 [webViewScrollViewProxy_ contentOffset]));
159 EXPECT_TRUE(CGPointEqualToPoint(point,
160 [webViewScrollViewProxy1 contentOffset]));
161 EXPECT_TRUE(CGPointEqualToPoint(point,
162 [webViewScrollViewProxy2 contentOffset]));
163 }
164
165 } // namespace
166
OLDNEW
« no previous file with comments | « ios/web/web_state/crw_web_view_scroll_view_proxy.mm ('k') | ios/web/web_state/ui/crw_web_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698