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

Side by Side Diff: ios/web/web_state/ui/crw_web_controller_unittest.mm

Issue 2745653007: Fix NavigationItem use-after-free crash in |-goToItemAtIndex:| (Closed)
Patch Set: test fix 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
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 @end 59 @end
60 60
61 @implementation MockInteractionLoader 61 @implementation MockInteractionLoader
62 62
63 typedef BOOL (^openExternalURLBlockType)(const GURL&); 63 typedef BOOL (^openExternalURLBlockType)(const GURL&);
64 64
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 @"" 231 @""
232 ]; 232 ];
233 233
234 NSArray* fragments = @[ @"#", @"#bar" ]; 234 NSArray* fragments = @[ @"#", @"#bar" ];
235 NSMutableArray* urlsWithFragments = [NSMutableArray array]; 235 NSMutableArray* urlsWithFragments = [NSMutableArray array];
236 for (NSString* url in urlsNoFragments) { 236 for (NSString* url in urlsNoFragments) {
237 for (NSString* fragment in fragments) { 237 for (NSString* fragment in fragments) {
238 [urlsWithFragments addObject:[url stringByAppendingString:fragment]]; 238 [urlsWithFragments addObject:[url stringByAppendingString:fragment]];
239 } 239 }
240 } 240 }
241 web::NavigationItemImpl fromItem; 241
242 GURL previous_url;
242 web::NavigationItemImpl toItem; 243 web::NavigationItemImpl toItem;
243 244
244 // No start fragment: the end url is never changed. 245 // No start fragment: the end url is never changed.
245 for (NSString* start in urlsNoFragments) { 246 for (NSString* start in urlsNoFragments) {
246 for (NSString* end in urlsWithFragments) { 247 for (NSString* end in urlsWithFragments) {
247 fromItem.SetURL(MAKE_URL(start)); 248 previous_url = MAKE_URL(start);
248 toItem.SetURL(MAKE_URL(end)); 249 toItem.SetURL(MAKE_URL(end));
249 EXPECT_EQ(MAKE_URL(end), 250 EXPECT_EQ(MAKE_URL(end),
250 [web_controller() URLForHistoryNavigationFromItem:&fromItem 251 [web_controller() URLForHistoryNavigationToItem:&toItem
251 toItem:&toItem]); 252 previousURL:previous_url]);
252 } 253 }
253 } 254 }
254 // Both contain fragments: the end url is never changed. 255 // Both contain fragments: the end url is never changed.
255 for (NSString* start in urlsWithFragments) { 256 for (NSString* start in urlsWithFragments) {
256 for (NSString* end in urlsWithFragments) { 257 for (NSString* end in urlsWithFragments) {
257 fromItem.SetURL(MAKE_URL(start)); 258 previous_url = MAKE_URL(start);
258 toItem.SetURL(MAKE_URL(end)); 259 toItem.SetURL(MAKE_URL(end));
259 EXPECT_EQ(MAKE_URL(end), 260 EXPECT_EQ(MAKE_URL(end),
260 [web_controller() URLForHistoryNavigationFromItem:&fromItem 261 [web_controller() URLForHistoryNavigationToItem:&toItem
261 toItem:&toItem]); 262 previousURL:previous_url]);
262 } 263 }
263 } 264 }
264 for (unsigned start_index = 0; start_index < [urlsWithFragments count]; 265 for (unsigned start_index = 0; start_index < [urlsWithFragments count];
265 ++start_index) { 266 ++start_index) {
266 NSString* start = urlsWithFragments[start_index]; 267 NSString* start = urlsWithFragments[start_index];
267 for (unsigned end_index = 0; end_index < [urlsNoFragments count]; 268 for (unsigned end_index = 0; end_index < [urlsNoFragments count];
268 ++end_index) { 269 ++end_index) {
269 NSString* end = urlsNoFragments[end_index]; 270 NSString* end = urlsNoFragments[end_index];
271 previous_url = MAKE_URL(start);
270 if (start_index / 2 != end_index) { 272 if (start_index / 2 != end_index) {
271 // The URLs have nothing in common, they are left untouched. 273 // The URLs have nothing in common, they are left untouched.
272 fromItem.SetURL(MAKE_URL(start));
273 toItem.SetURL(MAKE_URL(end)); 274 toItem.SetURL(MAKE_URL(end));
274 EXPECT_EQ(MAKE_URL(end), 275 EXPECT_EQ(
275 [web_controller() URLForHistoryNavigationFromItem:&fromItem 276 MAKE_URL(end),
276 toItem:&toItem]); 277 [web_controller() URLForHistoryNavigationToItem:&toItem
278 previousURL:previous_url]);
277 } else { 279 } else {
278 // Start contains a fragment and matches end: An empty fragment is 280 // Start contains a fragment and matches end: An empty fragment is
279 // added. 281 // added.
280 fromItem.SetURL(MAKE_URL(start));
281 toItem.SetURL(MAKE_URL(end)); 282 toItem.SetURL(MAKE_URL(end));
282 EXPECT_EQ(MAKE_URL([end stringByAppendingString:@"#"]), 283 EXPECT_EQ(
283 [web_controller() URLForHistoryNavigationFromItem:&fromItem 284 MAKE_URL([end stringByAppendingString:@"#"]),
284 toItem:&toItem]); 285 [web_controller() URLForHistoryNavigationToItem:&toItem
286 previousURL:previous_url]);
285 } 287 }
286 } 288 }
287 } 289 }
288 } 290 }
289 291
290 // Tests that AllowCertificateError is called with correct arguments if 292 // Tests that AllowCertificateError is called with correct arguments if
291 // WKWebView fails to load a page with bad SSL cert. 293 // WKWebView fails to load a page with bad SSL cert.
292 TEST_F(CRWWebControllerTest, SslCertError) { 294 TEST_F(CRWWebControllerTest, SslCertError) {
293 // Last arguments passed to AllowCertificateError must be in default state. 295 // Last arguments passed to AllowCertificateError must be in default state.
294 ASSERT_FALSE(GetWebClient()->last_cert_error_code()); 296 ASSERT_FALSE(GetWebClient()->last_cert_error_code());
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 web::TestWebStateObserver* observer_ptr = &observer; 957 web::TestWebStateObserver* observer_ptr = &observer;
956 web::SimulateWKWebViewCrash(webView_); 958 web::SimulateWKWebViewCrash(webView_);
957 base::test::ios::WaitUntilCondition(^bool() { 959 base::test::ios::WaitUntilCondition(^bool() {
958 return observer_ptr->render_process_gone_info(); 960 return observer_ptr->render_process_gone_info();
959 }); 961 });
960 EXPECT_EQ(web_state(), observer.render_process_gone_info()->web_state); 962 EXPECT_EQ(web_state(), observer.render_process_gone_info()->web_state);
961 EXPECT_FALSE([web_controller() isViewAlive]); 963 EXPECT_FALSE([web_controller() isViewAlive]);
962 }; 964 };
963 965
964 } // namespace 966 } // namespace
OLDNEW
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698