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 #import "ios/web/web_state/ui/crw_web_controller.h" | 5 #import "ios/web/web_state/ui/crw_web_controller.h" |
6 | 6 |
7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #import "testing/gtest_mac.h" | 43 #import "testing/gtest_mac.h" |
44 #include "third_party/ocmock/OCMock/OCMock.h" | 44 #include "third_party/ocmock/OCMock/OCMock.h" |
45 #include "third_party/ocmock/gtest_support.h" | 45 #include "third_party/ocmock/gtest_support.h" |
46 #include "third_party/ocmock/ocmock_extensions.h" | 46 #include "third_party/ocmock/ocmock_extensions.h" |
47 #import "ui/base/test/ios/ui_view_test_utils.h" | 47 #import "ui/base/test/ios/ui_view_test_utils.h" |
48 | 48 |
49 using web::NavigationManagerImpl; | 49 using web::NavigationManagerImpl; |
50 | 50 |
51 @interface CRWWebController (PrivateAPI) | 51 @interface CRWWebController (PrivateAPI) |
52 @property(nonatomic, readwrite) web::PageDisplayState pageDisplayState; | 52 @property(nonatomic, readwrite) web::PageDisplayState pageDisplayState; |
53 - (GURL)URLForHistoryNavigationToItem:(web::NavigationItem*)toItem | |
54 previousURL:(const GURL&)previousURL; | |
55 @end | 53 @end |
56 | 54 |
57 @interface CountingObserver : NSObject<CRWWebControllerObserver> | 55 @interface CountingObserver : NSObject<CRWWebControllerObserver> |
58 | 56 |
59 @property(nonatomic, readonly) int pageLoadedCount; | 57 @property(nonatomic, readonly) int pageLoadedCount; |
60 @end | 58 @end |
61 | 59 |
62 @implementation CountingObserver | 60 @implementation CountingObserver |
63 @synthesize pageLoadedCount = _pageLoadedCount; | 61 @synthesize pageLoadedCount = _pageLoadedCount; |
64 | 62 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 context:nullptr]; | 161 context:nullptr]; |
164 [[result stub] removeObserver:web_controller() forKeyPath:OCMOCK_ANY]; | 162 [[result stub] removeObserver:web_controller() forKeyPath:OCMOCK_ANY]; |
165 | 163 |
166 return result; | 164 return result; |
167 } | 165 } |
168 | 166 |
169 base::scoped_nsobject<UIScrollView> scroll_view_; | 167 base::scoped_nsobject<UIScrollView> scroll_view_; |
170 base::scoped_nsobject<id> mock_web_view_; | 168 base::scoped_nsobject<id> mock_web_view_; |
171 }; | 169 }; |
172 | 170 |
173 #define MAKE_URL(url_string) GURL([url_string UTF8String]) | |
174 | |
175 TEST_F(CRWWebControllerTest, UrlForHistoryNavigation) { | |
176 NSArray* urls_without_fragments = @[ | |
177 @"http://one.com", @"http://two.com/", @"http://three.com/bar", | |
178 @"http://four.com/bar/", @"five", @"/six", @"/seven/", @"" | |
179 ]; | |
180 | |
181 NSArray* fragments = @[ @"#", @"#bar" ]; | |
182 NSMutableArray* urls_with_fragments = [NSMutableArray array]; | |
183 for (NSString* url in urls_without_fragments) { | |
184 for (NSString* fragment in fragments) { | |
185 [urls_with_fragments addObject:[url stringByAppendingString:fragment]]; | |
186 } | |
187 } | |
188 | |
189 GURL previous_url; | |
190 web::NavigationItemImpl to_item; | |
191 | |
192 // No start fragment: the end url is never changed. | |
193 for (NSString* start in urls_without_fragments) { | |
194 for (NSString* end in urls_with_fragments) { | |
195 previous_url = MAKE_URL(start); | |
196 to_item.SetURL(MAKE_URL(end)); | |
197 EXPECT_EQ(MAKE_URL(end), | |
198 [web_controller() URLForHistoryNavigationToItem:&to_item | |
199 previousURL:previous_url]); | |
200 } | |
201 } | |
202 // Both contain fragments: the end url is never changed. | |
203 for (NSString* start in urls_with_fragments) { | |
204 for (NSString* end in urls_with_fragments) { | |
205 previous_url = MAKE_URL(start); | |
206 to_item.SetURL(MAKE_URL(end)); | |
207 EXPECT_EQ(MAKE_URL(end), | |
208 [web_controller() URLForHistoryNavigationToItem:&to_item | |
209 previousURL:previous_url]); | |
210 } | |
211 } | |
212 for (unsigned start_index = 0; start_index < urls_with_fragments.count; | |
213 ++start_index) { | |
214 NSString* start = urls_with_fragments[start_index]; | |
215 for (unsigned end_index = 0; end_index < urls_without_fragments.count; | |
216 ++end_index) { | |
217 NSString* end = urls_without_fragments[end_index]; | |
218 previous_url = MAKE_URL(start); | |
219 if (start_index / 2 != end_index) { | |
220 // The URLs have nothing in common, they are left untouched. | |
221 to_item.SetURL(MAKE_URL(end)); | |
222 EXPECT_EQ( | |
223 MAKE_URL(end), | |
224 [web_controller() URLForHistoryNavigationToItem:&to_item | |
225 previousURL:previous_url]); | |
226 } else { | |
227 // Start contains a fragment and matches end: An empty fragment is | |
228 // added. | |
229 to_item.SetURL(MAKE_URL(end)); | |
230 EXPECT_EQ( | |
231 MAKE_URL([end stringByAppendingString:@"#"]), | |
232 [web_controller() URLForHistoryNavigationToItem:&to_item | |
233 previousURL:previous_url]); | |
234 } | |
235 } | |
236 } | |
237 } | |
238 | |
239 // Tests that AllowCertificateError is called with correct arguments if | 171 // Tests that AllowCertificateError is called with correct arguments if |
240 // WKWebView fails to load a page with bad SSL cert. | 172 // WKWebView fails to load a page with bad SSL cert. |
241 TEST_F(CRWWebControllerTest, SslCertError) { | 173 TEST_F(CRWWebControllerTest, SslCertError) { |
242 web::TestWebStateObserver observer(web_state()); | 174 web::TestWebStateObserver observer(web_state()); |
243 ASSERT_FALSE(observer.did_change_visible_security_state_info()); | 175 ASSERT_FALSE(observer.did_change_visible_security_state_info()); |
244 | 176 |
245 // Last arguments passed to AllowCertificateError must be in default state. | 177 // Last arguments passed to AllowCertificateError must be in default state. |
246 ASSERT_FALSE(GetWebClient()->last_cert_error_code()); | 178 ASSERT_FALSE(GetWebClient()->last_cert_error_code()); |
247 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().is_valid()); | 179 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().is_valid()); |
248 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().cert_status); | 180 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().cert_status); |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 web::TestWebStateObserver* observer_ptr = &observer; | 887 web::TestWebStateObserver* observer_ptr = &observer; |
956 web::SimulateWKWebViewCrash(webView_); | 888 web::SimulateWKWebViewCrash(webView_); |
957 base::test::ios::WaitUntilCondition(^bool() { | 889 base::test::ios::WaitUntilCondition(^bool() { |
958 return observer_ptr->render_process_gone_info(); | 890 return observer_ptr->render_process_gone_info(); |
959 }); | 891 }); |
960 EXPECT_EQ(web_state(), observer.render_process_gone_info()->web_state); | 892 EXPECT_EQ(web_state(), observer.render_process_gone_info()->web_state); |
961 EXPECT_FALSE([web_controller() isViewAlive]); | 893 EXPECT_FALSE([web_controller() isViewAlive]); |
962 }; | 894 }; |
963 | 895 |
964 } // namespace | 896 } // namespace |
OLD | NEW |