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)URLForHistoryNavigationFromItem:(web::NavigationItem*)fromItem | 53 - (GURL)URLForHistoryNavigationToItem:(web::NavigationItem*)toItem |
54 toItem:(web::NavigationItem*)toItem; | 54 previousURL:(const GURL&)previousURL; |
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 web::NavigationItemImpl fromItem; | 279 |
| 280 GURL previous_url; |
280 web::NavigationItemImpl toItem; | 281 web::NavigationItemImpl toItem; |
281 | 282 |
282 // No start fragment: the end url is never changed. | 283 // No start fragment: the end url is never changed. |
283 for (NSString* start in urlsNoFragments) { | 284 for (NSString* start in urlsNoFragments) { |
284 for (NSString* end in urlsWithFragments) { | 285 for (NSString* end in urlsWithFragments) { |
285 fromItem.SetURL(MAKE_URL(start)); | 286 previous_url = MAKE_URL(start); |
286 toItem.SetURL(MAKE_URL(end)); | 287 toItem.SetURL(MAKE_URL(end)); |
287 EXPECT_EQ(MAKE_URL(end), | 288 EXPECT_EQ(MAKE_URL(end), |
288 [web_controller() URLForHistoryNavigationFromItem:&fromItem | 289 [web_controller() URLForHistoryNavigationToItem:&toItem |
289 toItem:&toItem]); | 290 previousURL:previous_url]); |
290 } | 291 } |
291 } | 292 } |
292 // Both contain fragments: the end url is never changed. | 293 // Both contain fragments: the end url is never changed. |
293 for (NSString* start in urlsWithFragments) { | 294 for (NSString* start in urlsWithFragments) { |
294 for (NSString* end in urlsWithFragments) { | 295 for (NSString* end in urlsWithFragments) { |
295 fromItem.SetURL(MAKE_URL(start)); | 296 previous_url = MAKE_URL(start); |
296 toItem.SetURL(MAKE_URL(end)); | 297 toItem.SetURL(MAKE_URL(end)); |
297 EXPECT_EQ(MAKE_URL(end), | 298 EXPECT_EQ(MAKE_URL(end), |
298 [web_controller() URLForHistoryNavigationFromItem:&fromItem | 299 [web_controller() URLForHistoryNavigationToItem:&toItem |
299 toItem:&toItem]); | 300 previousURL:previous_url]); |
300 } | 301 } |
301 } | 302 } |
302 for (unsigned start_index = 0; start_index < [urlsWithFragments count]; | 303 for (unsigned start_index = 0; start_index < [urlsWithFragments count]; |
303 ++start_index) { | 304 ++start_index) { |
304 NSString* start = urlsWithFragments[start_index]; | 305 NSString* start = urlsWithFragments[start_index]; |
305 for (unsigned end_index = 0; end_index < [urlsNoFragments count]; | 306 for (unsigned end_index = 0; end_index < [urlsNoFragments count]; |
306 ++end_index) { | 307 ++end_index) { |
307 NSString* end = urlsNoFragments[end_index]; | 308 NSString* end = urlsNoFragments[end_index]; |
| 309 previous_url = MAKE_URL(start); |
308 if (start_index / 2 != end_index) { | 310 if (start_index / 2 != end_index) { |
309 // The URLs have nothing in common, they are left untouched. | 311 // The URLs have nothing in common, they are left untouched. |
310 fromItem.SetURL(MAKE_URL(start)); | |
311 toItem.SetURL(MAKE_URL(end)); | 312 toItem.SetURL(MAKE_URL(end)); |
312 EXPECT_EQ(MAKE_URL(end), | 313 EXPECT_EQ( |
313 [web_controller() URLForHistoryNavigationFromItem:&fromItem | 314 MAKE_URL(end), |
314 toItem:&toItem]); | 315 [web_controller() URLForHistoryNavigationToItem:&toItem |
| 316 previousURL:previous_url]); |
315 } else { | 317 } else { |
316 // Start contains a fragment and matches end: An empty fragment is | 318 // Start contains a fragment and matches end: An empty fragment is |
317 // added. | 319 // added. |
318 fromItem.SetURL(MAKE_URL(start)); | |
319 toItem.SetURL(MAKE_URL(end)); | 320 toItem.SetURL(MAKE_URL(end)); |
320 EXPECT_EQ(MAKE_URL([end stringByAppendingString:@"#"]), | 321 EXPECT_EQ( |
321 [web_controller() URLForHistoryNavigationFromItem:&fromItem | 322 MAKE_URL([end stringByAppendingString:@"#"]), |
322 toItem:&toItem]); | 323 [web_controller() URLForHistoryNavigationToItem:&toItem |
| 324 previousURL:previous_url]); |
323 } | 325 } |
324 } | 326 } |
325 } | 327 } |
326 } | 328 } |
327 | 329 |
328 // Tests that AllowCertificateError is called with correct arguments if | 330 // Tests that AllowCertificateError is called with correct arguments if |
329 // WKWebView fails to load a page with bad SSL cert. | 331 // WKWebView fails to load a page with bad SSL cert. |
330 TEST_F(CRWWebControllerTest, SslCertError) { | 332 TEST_F(CRWWebControllerTest, SslCertError) { |
331 // Last arguments passed to AllowCertificateError must be in default state. | 333 // Last arguments passed to AllowCertificateError must be in default state. |
332 ASSERT_FALSE(GetWebClient()->last_cert_error_code()); | 334 ASSERT_FALSE(GetWebClient()->last_cert_error_code()); |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 }; | 1069 }; |
1068 | 1070 |
1069 RenderProcessGoneObserver observer(web_state()); | 1071 RenderProcessGoneObserver observer(web_state()); |
1070 web::SimulateWKWebViewCrash(webView_); | 1072 web::SimulateWKWebViewCrash(webView_); |
1071 observer.WaitForRenderProcessGone(); | 1073 observer.WaitForRenderProcessGone(); |
1072 | 1074 |
1073 EXPECT_FALSE([web_controller() isViewAlive]); | 1075 EXPECT_FALSE([web_controller() isViewAlive]); |
1074 }; | 1076 }; |
1075 | 1077 |
1076 } // namespace | 1078 } // namespace |
OLD | NEW |