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 | 53 - (GURL)URLForHistoryNavigationFromItem:(web::NavigationItem*)fromItem |
54 previousURL:(const GURL&)previousURL; | 54 toItem:(web::NavigationItem*)toItem; |
55 @end | 55 @end |
56 | 56 |
57 // Used to mock CRWWebDelegate methods with C++ params. | 57 // Used to mock CRWWebDelegate methods with C++ params. |
58 @interface MockInteractionLoader : OCMockComplexTypeHelper | 58 @interface MockInteractionLoader : OCMockComplexTypeHelper |
59 // Whether or not the delegate should block popups. | 59 // Whether or not the delegate should block popups. |
60 @property(nonatomic, assign) BOOL blockPopups; | 60 @property(nonatomic, assign) BOOL blockPopups; |
61 // A web controller that will be returned by webPageOrdered... methods. | 61 // A web controller that will be returned by webPageOrdered... methods. |
62 @property(nonatomic, assign) CRWWebController* childWebController; | 62 @property(nonatomic, assign) CRWWebController* childWebController; |
63 | 63 |
64 // Values of arguments passed to | 64 // Values of arguments passed to |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 @"" | 269 @"" |
270 ]; | 270 ]; |
271 | 271 |
272 NSArray* fragments = @[ @"#", @"#bar" ]; | 272 NSArray* fragments = @[ @"#", @"#bar" ]; |
273 NSMutableArray* urlsWithFragments = [NSMutableArray array]; | 273 NSMutableArray* urlsWithFragments = [NSMutableArray array]; |
274 for (NSString* url in urlsNoFragments) { | 274 for (NSString* url in urlsNoFragments) { |
275 for (NSString* fragment in fragments) { | 275 for (NSString* fragment in fragments) { |
276 [urlsWithFragments addObject:[url stringByAppendingString:fragment]]; | 276 [urlsWithFragments addObject:[url stringByAppendingString:fragment]]; |
277 } | 277 } |
278 } | 278 } |
279 | 279 web::NavigationItemImpl fromItem; |
280 GURL previous_url; | |
281 web::NavigationItemImpl toItem; | 280 web::NavigationItemImpl toItem; |
282 | 281 |
283 // No start fragment: the end url is never changed. | 282 // No start fragment: the end url is never changed. |
284 for (NSString* start in urlsNoFragments) { | 283 for (NSString* start in urlsNoFragments) { |
285 for (NSString* end in urlsWithFragments) { | 284 for (NSString* end in urlsWithFragments) { |
286 previous_url = MAKE_URL(start); | 285 fromItem.SetURL(MAKE_URL(start)); |
287 toItem.SetURL(MAKE_URL(end)); | 286 toItem.SetURL(MAKE_URL(end)); |
288 EXPECT_EQ(MAKE_URL(end), | 287 EXPECT_EQ(MAKE_URL(end), |
289 [web_controller() URLForHistoryNavigationToItem:&toItem | 288 [web_controller() URLForHistoryNavigationFromItem:&fromItem |
290 previousURL:previous_url]); | 289 toItem:&toItem]); |
291 } | 290 } |
292 } | 291 } |
293 // Both contain fragments: the end url is never changed. | 292 // Both contain fragments: the end url is never changed. |
294 for (NSString* start in urlsWithFragments) { | 293 for (NSString* start in urlsWithFragments) { |
295 for (NSString* end in urlsWithFragments) { | 294 for (NSString* end in urlsWithFragments) { |
296 previous_url = MAKE_URL(start); | 295 fromItem.SetURL(MAKE_URL(start)); |
297 toItem.SetURL(MAKE_URL(end)); | 296 toItem.SetURL(MAKE_URL(end)); |
298 EXPECT_EQ(MAKE_URL(end), | 297 EXPECT_EQ(MAKE_URL(end), |
299 [web_controller() URLForHistoryNavigationToItem:&toItem | 298 [web_controller() URLForHistoryNavigationFromItem:&fromItem |
300 previousURL:previous_url]); | 299 toItem:&toItem]); |
301 } | 300 } |
302 } | 301 } |
303 for (unsigned start_index = 0; start_index < [urlsWithFragments count]; | 302 for (unsigned start_index = 0; start_index < [urlsWithFragments count]; |
304 ++start_index) { | 303 ++start_index) { |
305 NSString* start = urlsWithFragments[start_index]; | 304 NSString* start = urlsWithFragments[start_index]; |
306 for (unsigned end_index = 0; end_index < [urlsNoFragments count]; | 305 for (unsigned end_index = 0; end_index < [urlsNoFragments count]; |
307 ++end_index) { | 306 ++end_index) { |
308 NSString* end = urlsNoFragments[end_index]; | 307 NSString* end = urlsNoFragments[end_index]; |
309 previous_url = MAKE_URL(start); | |
310 if (start_index / 2 != end_index) { | 308 if (start_index / 2 != end_index) { |
311 // The URLs have nothing in common, they are left untouched. | 309 // The URLs have nothing in common, they are left untouched. |
| 310 fromItem.SetURL(MAKE_URL(start)); |
312 toItem.SetURL(MAKE_URL(end)); | 311 toItem.SetURL(MAKE_URL(end)); |
313 EXPECT_EQ( | 312 EXPECT_EQ(MAKE_URL(end), |
314 MAKE_URL(end), | 313 [web_controller() URLForHistoryNavigationFromItem:&fromItem |
315 [web_controller() URLForHistoryNavigationToItem:&toItem | 314 toItem:&toItem]); |
316 previousURL:previous_url]); | |
317 } else { | 315 } else { |
318 // Start contains a fragment and matches end: An empty fragment is | 316 // Start contains a fragment and matches end: An empty fragment is |
319 // added. | 317 // added. |
| 318 fromItem.SetURL(MAKE_URL(start)); |
320 toItem.SetURL(MAKE_URL(end)); | 319 toItem.SetURL(MAKE_URL(end)); |
321 EXPECT_EQ( | 320 EXPECT_EQ(MAKE_URL([end stringByAppendingString:@"#"]), |
322 MAKE_URL([end stringByAppendingString:@"#"]), | 321 [web_controller() URLForHistoryNavigationFromItem:&fromItem |
323 [web_controller() URLForHistoryNavigationToItem:&toItem | 322 toItem:&toItem]); |
324 previousURL:previous_url]); | |
325 } | 323 } |
326 } | 324 } |
327 } | 325 } |
328 } | 326 } |
329 | 327 |
330 // Tests that AllowCertificateError is called with correct arguments if | 328 // Tests that AllowCertificateError is called with correct arguments if |
331 // WKWebView fails to load a page with bad SSL cert. | 329 // WKWebView fails to load a page with bad SSL cert. |
332 TEST_F(CRWWebControllerTest, SslCertError) { | 330 TEST_F(CRWWebControllerTest, SslCertError) { |
333 // Last arguments passed to AllowCertificateError must be in default state. | 331 // Last arguments passed to AllowCertificateError must be in default state. |
334 ASSERT_FALSE(GetWebClient()->last_cert_error_code()); | 332 ASSERT_FALSE(GetWebClient()->last_cert_error_code()); |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 }; | 1067 }; |
1070 | 1068 |
1071 RenderProcessGoneObserver observer(web_state()); | 1069 RenderProcessGoneObserver observer(web_state()); |
1072 web::SimulateWKWebViewCrash(webView_); | 1070 web::SimulateWKWebViewCrash(webView_); |
1073 observer.WaitForRenderProcessGone(); | 1071 observer.WaitForRenderProcessGone(); |
1074 | 1072 |
1075 EXPECT_FALSE([web_controller() isViewAlive]); | 1073 EXPECT_FALSE([web_controller() isViewAlive]); |
1076 }; | 1074 }; |
1077 | 1075 |
1078 } // namespace | 1076 } // namespace |
OLD | NEW |