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

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

Issue 2063763002: [ios] Removed deprecated ios/web/test/web_test.h. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Actually removed web_test.h Created 4 years, 6 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
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 10 matching lines...) Expand all
21 #include "ios/web/navigation/crw_session_entry.h" 21 #include "ios/web/navigation/crw_session_entry.h"
22 #include "ios/web/navigation/navigation_item_impl.h" 22 #include "ios/web/navigation/navigation_item_impl.h"
23 #import "ios/web/navigation/navigation_manager_impl.h" 23 #import "ios/web/navigation/navigation_manager_impl.h"
24 #include "ios/web/public/referrer.h" 24 #include "ios/web/public/referrer.h"
25 #import "ios/web/public/test/test_web_client.h" 25 #import "ios/web/public/test/test_web_client.h"
26 #include "ios/web/public/test/test_web_view_content_view.h" 26 #include "ios/web/public/test/test_web_view_content_view.h"
27 #import "ios/web/public/web_state/crw_web_controller_observer.h" 27 #import "ios/web/public/web_state/crw_web_controller_observer.h"
28 #import "ios/web/public/web_state/ui/crw_content_view.h" 28 #import "ios/web/public/web_state/ui/crw_content_view.h"
29 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" 29 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h"
30 #include "ios/web/public/web_state/url_verification_constants.h" 30 #include "ios/web/public/web_state/url_verification_constants.h"
31 #import "ios/web/test/web_test.h" 31 #import "ios/web/test/web_test_with_web_controller.h"
32 #import "ios/web/test/wk_web_view_crash_utils.h" 32 #import "ios/web/test/wk_web_view_crash_utils.h"
33 #include "ios/web/web_state/blocked_popup_info.h" 33 #include "ios/web/web_state/blocked_popup_info.h"
34 #import "ios/web/web_state/js/crw_js_invoke_parameter_queue.h" 34 #import "ios/web/web_state/js/crw_js_invoke_parameter_queue.h"
35 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" 35 #import "ios/web/web_state/ui/crw_web_controller_container_view.h"
36 #import "ios/web/web_state/web_state_impl.h" 36 #import "ios/web/web_state/web_state_impl.h"
37 #import "ios/web/web_state/wk_web_view_security_util.h" 37 #import "ios/web/web_state/wk_web_view_security_util.h"
38 #import "net/base/mac/url_conversions.h" 38 #import "net/base/mac/url_conversions.h"
39 #include "net/base/test_data_directory.h" 39 #include "net/base/test_data_directory.h"
40 #include "net/ssl/ssl_info.h" 40 #include "net/ssl/ssl_info.h"
41 #include "net/test/cert_test_util.h" 41 #include "net/test/cert_test_util.h"
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 void SetUp() override { 302 void SetUp() override {
303 web::WebTestWithWebController::SetUp(); 303 web::WebTestWithWebController::SetUp();
304 mockWebView_.reset(CreateMockWebView()); 304 mockWebView_.reset(CreateMockWebView());
305 mockScrollView_.reset([[UIScrollView alloc] init]); 305 mockScrollView_.reset([[UIScrollView alloc] init]);
306 [[[mockWebView_ stub] andReturn:mockScrollView_.get()] scrollView]; 306 [[[mockWebView_ stub] andReturn:mockScrollView_.get()] scrollView];
307 307
308 id originalMockDelegate = 308 id originalMockDelegate =
309 [OCMockObject niceMockForProtocol:@protocol(CRWWebDelegate)]; 309 [OCMockObject niceMockForProtocol:@protocol(CRWWebDelegate)];
310 mockDelegate_.reset([[MockInteractionLoader alloc] 310 mockDelegate_.reset([[MockInteractionLoader alloc]
311 initWithRepresentedObject:originalMockDelegate]); 311 initWithRepresentedObject:originalMockDelegate]);
312 [webController_ setDelegate:mockDelegate_]; 312 [web_controller() setDelegate:mockDelegate_];
313 base::scoped_nsobject<TestWebViewContentView> webViewContentView( 313 base::scoped_nsobject<TestWebViewContentView> webViewContentView(
314 [[TestWebViewContentView alloc] initWithMockWebView:mockWebView_ 314 [[TestWebViewContentView alloc] initWithMockWebView:mockWebView_
315 scrollView:mockScrollView_]); 315 scrollView:mockScrollView_]);
316 [webController_ injectWebViewContentView:webViewContentView]; 316 [web_controller() injectWebViewContentView:webViewContentView];
317 317
318 NavigationManagerImpl& navigationManager = 318 NavigationManagerImpl& navigationManager =
319 [webController_ webStateImpl]->GetNavigationManagerImpl(); 319 [web_controller() webStateImpl]->GetNavigationManagerImpl();
320 navigationManager.InitializeSession(@"name", nil, NO, 0); 320 navigationManager.InitializeSession(@"name", nil, NO, 0);
321 [navigationManager.GetSessionController() 321 [navigationManager.GetSessionController()
322 addPendingEntry:GURL("http://www.google.com/?q=foo#bar") 322 addPendingEntry:GURL("http://www.google.com/?q=foo#bar")
323 referrer:web::Referrer() 323 referrer:web::Referrer()
324 transition:ui::PAGE_TRANSITION_TYPED 324 transition:ui::PAGE_TRANSITION_TYPED
325 rendererInitiated:NO]; 325 rendererInitiated:NO];
326 } 326 }
327 327
328 void TearDown() override { 328 void TearDown() override {
329 EXPECT_OCMOCK_VERIFY(mockDelegate_); 329 EXPECT_OCMOCK_VERIFY(mockDelegate_);
330 EXPECT_OCMOCK_VERIFY(mockChildWebController_.get()); 330 EXPECT_OCMOCK_VERIFY(mockChildWebController_);
331 EXPECT_OCMOCK_VERIFY(mockWebView_); 331 EXPECT_OCMOCK_VERIFY(mockWebView_);
332 [webController_ resetInjectedWebViewContentView]; 332 [web_controller() resetInjectedWebViewContentView];
333 [webController_ setDelegate:nil]; 333 [web_controller() setDelegate:nil];
334 web::WebTestWithWebController::TearDown(); 334 web::WebTestWithWebController::TearDown();
335 } 335 }
336 336
337 // The value for web view OCMock objects to expect for |-setFrame:|. 337 // The value for web view OCMock objects to expect for |-setFrame:|.
338 CGRect ExpectedWebViewFrame() const { 338 CGRect ExpectedWebViewFrame() const {
339 CGSize containerViewSize = [UIScreen mainScreen].bounds.size; 339 CGSize containerViewSize = [UIScreen mainScreen].bounds.size;
340 containerViewSize.height -= 340 containerViewSize.height -=
341 CGRectGetHeight([UIApplication sharedApplication].statusBarFrame); 341 CGRectGetHeight([UIApplication sharedApplication].statusBarFrame);
342 return {CGPointZero, containerViewSize}; 342 return {CGPointZero, containerViewSize};
343 } 343 }
344 344
345 // Creates WebView mock. 345 // Creates WebView mock.
346 UIView* CreateMockWebView() const { 346 UIView* CreateMockWebView() {
347 id result = [[OCMockObject mockForClass:[WKWebView class]] retain]; 347 id result = [[OCMockObject mockForClass:[WKWebView class]] retain];
348 348
349 // Called by resetInjectedWebView 349 // Called by resetInjectedWebView
350 [[result stub] certificateChain]; 350 [[result stub] certificateChain];
351 [[result stub] backForwardList]; 351 [[result stub] backForwardList];
352 [[[result stub] andReturn:[NSURL URLWithString:kTestURLString]] URL]; 352 [[[result stub] andReturn:[NSURL URLWithString:kTestURLString]] URL];
353 [[result stub] setNavigationDelegate:OCMOCK_ANY]; 353 [[result stub] setNavigationDelegate:OCMOCK_ANY];
354 [[result stub] setUIDelegate:OCMOCK_ANY]; 354 [[result stub] setUIDelegate:OCMOCK_ANY];
355 [[result stub] setFrame:ExpectedWebViewFrame()]; 355 [[result stub] setFrame:ExpectedWebViewFrame()];
356 [[result stub] addObserver:webController_ 356 [[result stub] addObserver:web_controller()
357 forKeyPath:OCMOCK_ANY 357 forKeyPath:OCMOCK_ANY
358 options:0 358 options:0
359 context:nullptr]; 359 context:nullptr];
360 [[result stub] addObserver:OCMOCK_ANY 360 [[result stub] addObserver:OCMOCK_ANY
361 forKeyPath:@"scrollView.backgroundColor" 361 forKeyPath:@"scrollView.backgroundColor"
362 options:0 362 options:0
363 context:nullptr]; 363 context:nullptr];
364 364
365 [[result stub] removeObserver:webController_ forKeyPath:OCMOCK_ANY]; 365 [[result stub] removeObserver:web_controller() forKeyPath:OCMOCK_ANY];
366 [[result stub] removeObserver:OCMOCK_ANY 366 [[result stub] removeObserver:OCMOCK_ANY
367 forKeyPath:@"scrollView.backgroundColor"]; 367 forKeyPath:@"scrollView.backgroundColor"];
368 368
369 return result; 369 return result;
370 } 370 }
371 371
372 base::scoped_nsobject<UIScrollView> mockScrollView_; 372 base::scoped_nsobject<UIScrollView> mockScrollView_;
373 base::scoped_nsobject<id> mockWebView_; 373 base::scoped_nsobject<id> mockWebView_;
374 base::scoped_nsobject<id> mockDelegate_; 374 base::scoped_nsobject<id> mockDelegate_;
375 base::scoped_nsobject<id> mockChildWebController_; 375 base::scoped_nsobject<id> mockChildWebController_;
(...skipping 22 matching lines...) Expand all
398 } 398 }
399 web::NavigationItemImpl fromItem; 399 web::NavigationItemImpl fromItem;
400 web::NavigationItemImpl toItem; 400 web::NavigationItemImpl toItem;
401 401
402 // No start fragment: the end url is never changed. 402 // No start fragment: the end url is never changed.
403 for (NSString* start in urlsNoFragments) { 403 for (NSString* start in urlsNoFragments) {
404 for (NSString* end in urlsWithFragments) { 404 for (NSString* end in urlsWithFragments) {
405 fromItem.SetURL(MAKE_URL(start)); 405 fromItem.SetURL(MAKE_URL(start));
406 toItem.SetURL(MAKE_URL(end)); 406 toItem.SetURL(MAKE_URL(end));
407 EXPECT_EQ(MAKE_URL(end), 407 EXPECT_EQ(MAKE_URL(end),
408 [webController_ URLForHistoryNavigationFromItem:&fromItem 408 [web_controller() URLForHistoryNavigationFromItem:&fromItem
409 toItem:&toItem]); 409 toItem:&toItem]);
410 } 410 }
411 } 411 }
412 // Both contain fragments: the end url is never changed. 412 // Both contain fragments: the end url is never changed.
413 for (NSString* start in urlsWithFragments) { 413 for (NSString* start in urlsWithFragments) {
414 for (NSString* end in urlsWithFragments) { 414 for (NSString* end in urlsWithFragments) {
415 fromItem.SetURL(MAKE_URL(start)); 415 fromItem.SetURL(MAKE_URL(start));
416 toItem.SetURL(MAKE_URL(end)); 416 toItem.SetURL(MAKE_URL(end));
417 EXPECT_EQ(MAKE_URL(end), 417 EXPECT_EQ(MAKE_URL(end),
418 [webController_ URLForHistoryNavigationFromItem:&fromItem 418 [web_controller() URLForHistoryNavigationFromItem:&fromItem
419 toItem:&toItem]); 419 toItem:&toItem]);
420 } 420 }
421 } 421 }
422 for (unsigned start_index = 0; start_index < [urlsWithFragments count]; 422 for (unsigned start_index = 0; start_index < [urlsWithFragments count];
423 ++start_index) { 423 ++start_index) {
424 NSString* start = urlsWithFragments[start_index]; 424 NSString* start = urlsWithFragments[start_index];
425 for (unsigned end_index = 0; end_index < [urlsNoFragments count]; 425 for (unsigned end_index = 0; end_index < [urlsNoFragments count];
426 ++end_index) { 426 ++end_index) {
427 NSString* end = urlsNoFragments[end_index]; 427 NSString* end = urlsNoFragments[end_index];
428 if (start_index / 2 != end_index) { 428 if (start_index / 2 != end_index) {
429 // The URLs have nothing in common, they are left untouched. 429 // The URLs have nothing in common, they are left untouched.
430 fromItem.SetURL(MAKE_URL(start)); 430 fromItem.SetURL(MAKE_URL(start));
431 toItem.SetURL(MAKE_URL(end)); 431 toItem.SetURL(MAKE_URL(end));
432 EXPECT_EQ(MAKE_URL(end), 432 EXPECT_EQ(MAKE_URL(end),
433 [webController_ URLForHistoryNavigationFromItem:&fromItem 433 [web_controller() URLForHistoryNavigationFromItem:&fromItem
434 toItem:&toItem]); 434 toItem:&toItem]);
435 } else { 435 } else {
436 // Start contains a fragment and matches end: An empty fragment is 436 // Start contains a fragment and matches end: An empty fragment is
437 // added. 437 // added.
438 fromItem.SetURL(MAKE_URL(start)); 438 fromItem.SetURL(MAKE_URL(start));
439 toItem.SetURL(MAKE_URL(end)); 439 toItem.SetURL(MAKE_URL(end));
440 EXPECT_EQ(MAKE_URL([end stringByAppendingString:@"#"]), 440 EXPECT_EQ(MAKE_URL([end stringByAppendingString:@"#"]),
441 [webController_ URLForHistoryNavigationFromItem:&fromItem 441 [web_controller() URLForHistoryNavigationFromItem:&fromItem
442 toItem:&toItem]); 442 toItem:&toItem]);
443 } 443 }
444 } 444 }
445 } 445 }
446 } 446 }
447 447
448 // Tests that presentSSLError:forSSLStatus:recoverable:callback: is called with 448 // Tests that presentSSLError:forSSLStatus:recoverable:callback: is called with
449 // correct arguments if WKWebView fails to load a page with bad SSL cert. 449 // correct arguments if WKWebView fails to load a page with bad SSL cert.
450 // TODO(crbug.com/602298): Remove this test. 450 // TODO(crbug.com/602298): Remove this test.
451 TEST_F(CRWWebControllerTest, SslCertErrorDeprecatedApi) { 451 TEST_F(CRWWebControllerTest, SslCertErrorDeprecatedApi) {
452 ASSERT_FALSE([mockDelegate_ SSLInfo].is_valid()); 452 ASSERT_FALSE([mockDelegate_ SSLInfo].is_valid());
453 453
454 scoped_refptr<net::X509Certificate> cert = 454 scoped_refptr<net::X509Certificate> cert =
455 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); 455 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
456 456
457 NSArray* chain = @[ static_cast<id>(cert->os_cert_handle()) ]; 457 NSArray* chain = @[ static_cast<id>(cert->os_cert_handle()) ];
458 NSError* error = 458 NSError* error =
459 [NSError errorWithDomain:NSURLErrorDomain 459 [NSError errorWithDomain:NSURLErrorDomain
460 code:NSURLErrorServerCertificateHasUnknownRoot 460 code:NSURLErrorServerCertificateHasUnknownRoot
461 userInfo:@{ 461 userInfo:@{
462 web::kNSErrorPeerCertificateChainKey : chain, 462 web::kNSErrorPeerCertificateChainKey : chain,
463 }]; 463 }];
464 464
465 CRWWebControllerContainerView* containerView = 465 CRWWebControllerContainerView* containerView =
466 static_cast<CRWWebControllerContainerView*>([webController_ view]); 466 static_cast<CRWWebControllerContainerView*>([web_controller() view]);
467 WKWebView* webView = 467 WKWebView* webView =
468 static_cast<WKWebView*>(containerView.webViewContentView.webView); 468 static_cast<WKWebView*>(containerView.webViewContentView.webView);
469 base::scoped_nsobject<NSObject> navigation([[NSObject alloc] init]); 469 base::scoped_nsobject<NSObject> navigation([[NSObject alloc] init]);
470 [static_cast<id<WKNavigationDelegate>>(webController_.get()) 470 [static_cast<id<WKNavigationDelegate>>(web_controller())
471 webView:webView 471 webView:webView
472 didStartProvisionalNavigation:static_cast<WKNavigation*>(navigation)]; 472 didStartProvisionalNavigation:static_cast<WKNavigation*>(navigation)];
473 [static_cast<id<WKNavigationDelegate>>(webController_.get()) 473 [static_cast<id<WKNavigationDelegate>>(web_controller())
474 webView:webView 474 webView:webView
475 didFailProvisionalNavigation:static_cast<WKNavigation*>(navigation) 475 didFailProvisionalNavigation:static_cast<WKNavigation*>(navigation)
476 withError:error]; 476 withError:error];
477 477
478 // Verify correctness of delegate's method arguments. 478 // Verify correctness of delegate's method arguments.
479 EXPECT_TRUE([mockDelegate_ SSLInfo].is_valid()); 479 EXPECT_TRUE([mockDelegate_ SSLInfo].is_valid());
480 EXPECT_EQ(net::CERT_STATUS_INVALID, [mockDelegate_ SSLInfo].cert_status); 480 EXPECT_EQ(net::CERT_STATUS_INVALID, [mockDelegate_ SSLInfo].cert_status);
481 EXPECT_EQ(net::CERT_STATUS_INVALID, [mockDelegate_ SSLStatus].cert_status); 481 EXPECT_EQ(net::CERT_STATUS_INVALID, [mockDelegate_ SSLStatus].cert_status);
482 EXPECT_EQ(web::SECURITY_STYLE_AUTHENTICATION_BROKEN, 482 EXPECT_EQ(web::SECURITY_STYLE_AUTHENTICATION_BROKEN,
483 [mockDelegate_ SSLStatus].security_style); 483 [mockDelegate_ SSLStatus].security_style);
484 EXPECT_FALSE([mockDelegate_ recoverable]); 484 EXPECT_FALSE([mockDelegate_ recoverable]);
485 EXPECT_TRUE([mockDelegate_ shouldContinueCallback]); 485 EXPECT_TRUE([mockDelegate_ shouldContinueCallback]);
486 } 486 }
487 487
488 // Tests that AllowCertificateError is called with correct arguments if 488 // Tests that AllowCertificateError is called with correct arguments if
489 // WKWebView fails to load a page with bad SSL cert. 489 // WKWebView fails to load a page with bad SSL cert.
490 TEST_F(CRWWebControllerTest, SslCertError) { 490 TEST_F(CRWWebControllerTest, SslCertError) {
491 // TODO(crbug.com/602298): Remove this call. 491 // TODO(crbug.com/602298): Remove this call.
492 [webController_ setDelegate:nil]; 492 [web_controller() setDelegate:nil];
493 493
494 // Last arguments passed to AllowCertificateError must be in default state. 494 // Last arguments passed to AllowCertificateError must be in default state.
495 ASSERT_FALSE(GetWebClient()->last_cert_error_code()); 495 ASSERT_FALSE(GetWebClient()->last_cert_error_code());
496 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().is_valid()); 496 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().is_valid());
497 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().cert_status); 497 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().cert_status);
498 ASSERT_FALSE(GetWebClient()->last_cert_error_request_url().is_valid()); 498 ASSERT_FALSE(GetWebClient()->last_cert_error_request_url().is_valid());
499 ASSERT_TRUE(GetWebClient()->last_cert_error_overridable()); 499 ASSERT_TRUE(GetWebClient()->last_cert_error_overridable());
500 500
501 scoped_refptr<net::X509Certificate> cert = 501 scoped_refptr<net::X509Certificate> cert =
502 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); 502 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
503 503
504 NSArray* chain = @[ static_cast<id>(cert->os_cert_handle()) ]; 504 NSArray* chain = @[ static_cast<id>(cert->os_cert_handle()) ];
505 GURL url("https://chromium.test"); 505 GURL url("https://chromium.test");
506 NSError* error = 506 NSError* error =
507 [NSError errorWithDomain:NSURLErrorDomain 507 [NSError errorWithDomain:NSURLErrorDomain
508 code:NSURLErrorServerCertificateHasUnknownRoot 508 code:NSURLErrorServerCertificateHasUnknownRoot
509 userInfo:@{ 509 userInfo:@{
510 web::kNSErrorPeerCertificateChainKey : chain, 510 web::kNSErrorPeerCertificateChainKey : chain,
511 web::kNSErrorFailingURLKey : net::NSURLWithGURL(url), 511 web::kNSErrorFailingURLKey : net::NSURLWithGURL(url),
512 }]; 512 }];
513 CRWWebControllerContainerView* containerView = 513 CRWWebControllerContainerView* containerView =
514 static_cast<CRWWebControllerContainerView*>([webController_ view]); 514 static_cast<CRWWebControllerContainerView*>([web_controller() view]);
515 WKWebView* webView = 515 WKWebView* webView =
516 static_cast<WKWebView*>(containerView.webViewContentView.webView); 516 static_cast<WKWebView*>(containerView.webViewContentView.webView);
517 base::scoped_nsobject<NSObject> navigation([[NSObject alloc] init]); 517 base::scoped_nsobject<NSObject> navigation([[NSObject alloc] init]);
518 [static_cast<id<WKNavigationDelegate>>(webController_.get()) 518 [static_cast<id<WKNavigationDelegate>>(web_controller())
519 webView:webView 519 webView:webView
520 didStartProvisionalNavigation:static_cast<WKNavigation*>(navigation)]; 520 didStartProvisionalNavigation:static_cast<WKNavigation*>(navigation)];
521 [static_cast<id<WKNavigationDelegate>>(webController_.get()) 521 [static_cast<id<WKNavigationDelegate>>(web_controller())
522 webView:webView 522 webView:webView
523 didFailProvisionalNavigation:static_cast<WKNavigation*>(navigation) 523 didFailProvisionalNavigation:static_cast<WKNavigation*>(navigation)
524 withError:error]; 524 withError:error];
525 525
526 // Verify correctness of AllowCertificateError method call. 526 // Verify correctness of AllowCertificateError method call.
527 EXPECT_EQ(net::ERR_CERT_INVALID, GetWebClient()->last_cert_error_code()); 527 EXPECT_EQ(net::ERR_CERT_INVALID, GetWebClient()->last_cert_error_code());
528 EXPECT_TRUE(GetWebClient()->last_cert_error_ssl_info().is_valid()); 528 EXPECT_TRUE(GetWebClient()->last_cert_error_ssl_info().is_valid());
529 EXPECT_EQ(net::CERT_STATUS_INVALID, 529 EXPECT_EQ(net::CERT_STATUS_INVALID,
530 GetWebClient()->last_cert_error_ssl_info().cert_status); 530 GetWebClient()->last_cert_error_ssl_info().cert_status);
531 EXPECT_EQ(url, GetWebClient()->last_cert_error_request_url()); 531 EXPECT_EQ(url, GetWebClient()->last_cert_error_request_url());
532 EXPECT_FALSE(GetWebClient()->last_cert_error_overridable()); 532 EXPECT_FALSE(GetWebClient()->last_cert_error_overridable());
533 } 533 }
534 534
535 // Test fixture to test |setPageDialogOpenPolicy:|. 535 // Test fixture to test |setPageDialogOpenPolicy:|.
536 class CRWWebControllerPageDialogOpenPolicyTest 536 class CRWWebControllerPageDialogOpenPolicyTest
537 : public web::WebTestWithWebController { 537 : public web::WebTestWithWebController {
538 protected: 538 protected:
539 void SetUp() override { 539 void SetUp() override {
540 web::WebTestWithWebController::SetUp(); 540 web::WebTestWithWebController::SetUp();
541 LoadHtml(@"<html><body></body></html>"); 541 LoadHtml(@"<html><body></body></html>");
542 web_delegate_mock_.reset( 542 web_delegate_mock_.reset(
543 [[OCMockObject mockForProtocol:@protocol(CRWWebDelegate)] retain]); 543 [[OCMockObject mockForProtocol:@protocol(CRWWebDelegate)] retain]);
544 [webController_ setDelegate:web_delegate_mock_]; 544 [web_controller() setDelegate:web_delegate_mock_];
545 id ui_delegate_oc_mock = 545 id ui_delegate_oc_mock =
546 [OCMockObject mockForProtocol:@protocol(CRWWebUserInterfaceDelegate)]; 546 [OCMockObject mockForProtocol:@protocol(CRWWebUserInterfaceDelegate)];
547 ui_delegate_mock_.reset([[CRWWebUserInterfaceDelegateStub alloc] 547 ui_delegate_mock_.reset([[CRWWebUserInterfaceDelegateStub alloc]
548 initWithRepresentedObject:ui_delegate_oc_mock]); 548 initWithRepresentedObject:ui_delegate_oc_mock]);
549 [webController_ setUIDelegate:ui_delegate_mock_]; 549 [web_controller() setUIDelegate:ui_delegate_mock_];
550 // Web Controller cancels all dialogs on |close|. 550 // Web Controller cancels all dialogs on |close|.
551 [[ui_delegate_mock_ stub] cancelDialogsForWebController:webController_]; 551 [[ui_delegate_mock_ stub] cancelDialogsForWebController:web_controller()];
552 } 552 }
553 void TearDown() override { 553 void TearDown() override {
554 WaitForBackgroundTasks(); 554 WaitForBackgroundTasks();
555 EXPECT_OCMOCK_VERIFY(web_delegate_mock_); 555 EXPECT_OCMOCK_VERIFY(web_delegate_mock_);
556 EXPECT_OCMOCK_VERIFY(ui_delegate_mock_); 556 EXPECT_OCMOCK_VERIFY(ui_delegate_mock_);
557 [webController_ setDelegate:nil]; 557 [web_controller() setDelegate:nil];
558 [webController_ setUIDelegate:nil]; 558 [web_controller() setUIDelegate:nil];
559 559
560 web::WebTestWithWebController::TearDown(); 560 web::WebTestWithWebController::TearDown();
561 } 561 }
562 // Returns CRWWebDelegate mock object. 562 // Returns CRWWebDelegate mock object.
563 id web_delegate_mock() { return web_delegate_mock_; }; 563 id web_delegate_mock() { return web_delegate_mock_; };
564 // Returns CRWWebUserInterfaceDelegate mock object. 564 // Returns CRWWebUserInterfaceDelegate mock object.
565 id ui_delegate_mock() { return ui_delegate_mock_; }; 565 id ui_delegate_mock() { return ui_delegate_mock_; };
566 566
567 private: 567 private:
568 // Mocks CRWWebDelegate object. 568 // Mocks CRWWebDelegate object.
569 base::scoped_nsprotocol<id> web_delegate_mock_; 569 base::scoped_nsprotocol<id> web_delegate_mock_;
570 // Mocks CRWWebUserInterfaceDelegate object. 570 // Mocks CRWWebUserInterfaceDelegate object.
571 base::scoped_nsprotocol<id> ui_delegate_mock_; 571 base::scoped_nsprotocol<id> ui_delegate_mock_;
572 }; 572 };
573 573
574 // Tests that window.alert dialog is suppressed for DIALOG_POLICY_SUPPRESS. 574 // Tests that window.alert dialog is suppressed for DIALOG_POLICY_SUPPRESS.
575 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, SuppressAlert) { 575 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, SuppressAlert) {
576 [[web_delegate_mock() expect] webControllerDidSuppressDialog:webController_]; 576 [[web_delegate_mock() expect]
577 [webController_ setShouldSuppressDialogs:YES]; 577 webControllerDidSuppressDialog:web_controller()];
578 [web_controller() setShouldSuppressDialogs:YES];
578 EvaluateJavaScriptAsString(@"alert('test')"); 579 EvaluateJavaScriptAsString(@"alert('test')");
579 }; 580 };
580 581
581 // Tests that window.alert dialog is shown for DIALOG_POLICY_ALLOW. 582 // Tests that window.alert dialog is shown for DIALOG_POLICY_ALLOW.
582 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, AllowAlert) { 583 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, AllowAlert) {
583 SEL selector = @selector(webController: 584 SEL selector = @selector(webController:
584 runJavaScriptAlertPanelWithMessage: 585 runJavaScriptAlertPanelWithMessage:
585 requestURL: 586 requestURL:
586 completionHandler:); 587 completionHandler:);
587 [ui_delegate_mock() onSelector:selector 588 [ui_delegate_mock() onSelector:selector
588 callBlockExpectation:^(CRWWebController* web_controller, 589 callBlockExpectation:^(CRWWebController* controller,
589 NSString* message, const GURL& url, 590 NSString* message, const GURL& url,
590 ProceduralBlock completion_handler) { 591 ProceduralBlock completion_handler) {
591 EXPECT_NSEQ(webController_, web_controller); 592 EXPECT_NSEQ(web_controller(), controller);
592 EXPECT_NSEQ(@"test", message); 593 EXPECT_NSEQ(@"test", message);
593 web::URLVerificationTrustLevel unused; 594 web::URLVerificationTrustLevel unused;
594 EXPECT_EQ([web_controller currentURLWithTrustLevel:&unused], url); 595 EXPECT_EQ([controller currentURLWithTrustLevel:&unused], url);
595 completion_handler(); 596 completion_handler();
596 }]; 597 }];
597 598
598 [webController_ setShouldSuppressDialogs:NO]; 599 [web_controller() setShouldSuppressDialogs:NO];
599 EvaluateJavaScriptAsString(@"alert('test')"); 600 EvaluateJavaScriptAsString(@"alert('test')");
600 }; 601 };
601 602
602 // Tests that window.confirm dialog is suppressed for DIALOG_POLICY_SUPPRESS. 603 // Tests that window.confirm dialog is suppressed for DIALOG_POLICY_SUPPRESS.
603 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, SuppressConfirm) { 604 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, SuppressConfirm) {
604 [[web_delegate_mock() expect] webControllerDidSuppressDialog:webController_]; 605 [[web_delegate_mock() expect]
605 [webController_ setShouldSuppressDialogs:YES]; 606 webControllerDidSuppressDialog:web_controller()];
607 [web_controller() setShouldSuppressDialogs:YES];
606 EXPECT_NSEQ(@"false", EvaluateJavaScriptAsString(@"confirm('test')")); 608 EXPECT_NSEQ(@"false", EvaluateJavaScriptAsString(@"confirm('test')"));
607 }; 609 };
608 610
609 // Tests that window.confirm dialog is shown for DIALOG_POLICY_ALLOW and 611 // Tests that window.confirm dialog is shown for DIALOG_POLICY_ALLOW and
610 // it's result is true. 612 // it's result is true.
611 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, AllowConfirmWithTrue) { 613 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, AllowConfirmWithTrue) {
612 SEL selector = @selector(webController: 614 SEL selector = @selector(webController:
613 runJavaScriptConfirmPanelWithMessage: 615 runJavaScriptConfirmPanelWithMessage:
614 requestURL: 616 requestURL:
615 completionHandler:); 617 completionHandler:);
616 [ui_delegate_mock() onSelector:selector 618 [ui_delegate_mock()
617 callBlockExpectation:^(CRWWebController* web_controller, 619 onSelector:selector
618 NSString* message, const GURL& url, 620 callBlockExpectation:^(CRWWebController* controller, NSString* message,
619 id completion_handler) { 621 const GURL& url, id completion_handler) {
620 EXPECT_NSEQ(webController_, web_controller); 622 EXPECT_NSEQ(web_controller(), controller);
621 EXPECT_NSEQ(@"test", message); 623 EXPECT_NSEQ(@"test", message);
622 web::URLVerificationTrustLevel unused; 624 web::URLVerificationTrustLevel unused;
623 EXPECT_EQ([web_controller currentURLWithTrustLevel:&unused], url); 625 EXPECT_EQ([controller currentURLWithTrustLevel:&unused], url);
624 void (^callable_block)(BOOL) = completion_handler; 626 void (^callable_block)(BOOL) = completion_handler;
625 callable_block(YES); 627 callable_block(YES);
626 }]; 628 }];
627 629
628 [webController_ setShouldSuppressDialogs:NO]; 630 [web_controller() setShouldSuppressDialogs:NO];
629 EXPECT_NSEQ(@"true", EvaluateJavaScriptAsString(@"confirm('test')")); 631 EXPECT_NSEQ(@"true", EvaluateJavaScriptAsString(@"confirm('test')"));
630 } 632 }
631 633
632 // Tests that window.confirm dialog is shown for DIALOG_POLICY_ALLOW and 634 // Tests that window.confirm dialog is shown for DIALOG_POLICY_ALLOW and
633 // it's result is false. 635 // it's result is false.
634 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, AllowConfirmWithFalse) { 636 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, AllowConfirmWithFalse) {
635 SEL selector = @selector(webController: 637 SEL selector = @selector(webController:
636 runJavaScriptConfirmPanelWithMessage: 638 runJavaScriptConfirmPanelWithMessage:
637 requestURL: 639 requestURL:
638 completionHandler:); 640 completionHandler:);
639 [ui_delegate_mock() onSelector:selector 641 [ui_delegate_mock()
640 callBlockExpectation:^(CRWWebController* web_controller, 642 onSelector:selector
641 NSString* message, const GURL& url, 643 callBlockExpectation:^(CRWWebController* controller, NSString* message,
642 id completion_handler) { 644 const GURL& url, id completion_handler) {
643 EXPECT_NSEQ(webController_, web_controller); 645 EXPECT_NSEQ(web_controller(), controller);
644 EXPECT_NSEQ(@"test", message); 646 EXPECT_NSEQ(@"test", message);
645 web::URLVerificationTrustLevel unused; 647 web::URLVerificationTrustLevel unused;
646 EXPECT_EQ([web_controller currentURLWithTrustLevel:&unused], url); 648 EXPECT_EQ([controller currentURLWithTrustLevel:&unused], url);
647 void (^callable_block)(BOOL) = completion_handler; 649 void (^callable_block)(BOOL) = completion_handler;
648 callable_block(NO); 650 callable_block(NO);
649 }]; 651 }];
650 652
651 [webController_ setShouldSuppressDialogs:NO]; 653 [web_controller() setShouldSuppressDialogs:NO];
652 EXPECT_NSEQ(@"false", EvaluateJavaScriptAsString(@"confirm('test')")); 654 EXPECT_NSEQ(@"false", EvaluateJavaScriptAsString(@"confirm('test')"));
653 } 655 }
654 656
655 // Tests that window.prompt dialog is suppressed for DIALOG_POLICY_SUPPRESS. 657 // Tests that window.prompt dialog is suppressed for DIALOG_POLICY_SUPPRESS.
656 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, SuppressPrompt) { 658 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, SuppressPrompt) {
657 [[web_delegate_mock() expect] webControllerDidSuppressDialog:webController_]; 659 [[web_delegate_mock() expect]
658 [webController_ setShouldSuppressDialogs:YES]; 660 webControllerDidSuppressDialog:web_controller()];
661 [web_controller() setShouldSuppressDialogs:YES];
659 EXPECT_NSEQ(@"", EvaluateJavaScriptAsString(@"prompt('Yes?', 'No')")); 662 EXPECT_NSEQ(@"", EvaluateJavaScriptAsString(@"prompt('Yes?', 'No')"));
660 } 663 }
661 664
662 // Tests that window.prompt dialog is shown for DIALOG_POLICY_ALLOW. 665 // Tests that window.prompt dialog is shown for DIALOG_POLICY_ALLOW.
663 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, AllowPrompt) { 666 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, AllowPrompt) {
664 SEL selector = @selector(webController: 667 SEL selector = @selector(webController:
665 runJavaScriptTextInputPanelWithPrompt: 668 runJavaScriptTextInputPanelWithPrompt:
666 defaultText: 669 defaultText:
667 requestURL: 670 requestURL:
668 completionHandler:); 671 completionHandler:);
669 [ui_delegate_mock() onSelector:selector 672 [ui_delegate_mock() onSelector:selector
670 callBlockExpectation:^(CRWWebController* web_controller, 673 callBlockExpectation:^(CRWWebController* controller,
671 NSString* message, NSString* default_text, 674 NSString* message, NSString* default_text,
672 const GURL& url, id completion_handler) { 675 const GURL& url, id completion_handler) {
673 EXPECT_NSEQ(webController_, web_controller); 676 EXPECT_NSEQ(web_controller(), controller);
674 EXPECT_NSEQ(@"Yes?", message); 677 EXPECT_NSEQ(@"Yes?", message);
675 EXPECT_NSEQ(@"No", default_text); 678 EXPECT_NSEQ(@"No", default_text);
676 web::URLVerificationTrustLevel unused; 679 web::URLVerificationTrustLevel unused;
677 EXPECT_EQ([web_controller currentURLWithTrustLevel:&unused], url); 680 EXPECT_EQ([controller currentURLWithTrustLevel:&unused], url);
678 void (^callable_block)(NSString*) = completion_handler; 681 void (^callable_block)(NSString*) = completion_handler;
679 callable_block(@"Maybe"); 682 callable_block(@"Maybe");
680 }]; 683 }];
681 684
682 [webController_ setShouldSuppressDialogs:NO]; 685 [web_controller() setShouldSuppressDialogs:NO];
683 EXPECT_NSEQ(@"Maybe", EvaluateJavaScriptAsString(@"prompt('Yes?', 'No')")); 686 EXPECT_NSEQ(@"Maybe", EvaluateJavaScriptAsString(@"prompt('Yes?', 'No')"));
684 } 687 }
685 688
686 // Tests that geolocation dialog is suppressed for DIALOG_POLICY_SUPPRESS. 689 // Tests that geolocation dialog is suppressed for DIALOG_POLICY_SUPPRESS.
687 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, SuppressGeolocation) { 690 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, SuppressGeolocation) {
688 [[web_delegate_mock() expect] webControllerDidSuppressDialog:webController_]; 691 [[web_delegate_mock() expect]
689 [webController_ setShouldSuppressDialogs:YES]; 692 webControllerDidSuppressDialog:web_controller()];
693 [web_controller() setShouldSuppressDialogs:YES];
690 EvaluateJavaScriptAsString(@"navigator.geolocation.getCurrentPosition()"); 694 EvaluateJavaScriptAsString(@"navigator.geolocation.getCurrentPosition()");
691 } 695 }
692 696
693 // Tests that window.open is suppressed for DIALOG_POLICY_SUPPRESS. 697 // Tests that window.open is suppressed for DIALOG_POLICY_SUPPRESS.
694 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, SuppressWindowOpen) { 698 TEST_F(CRWWebControllerPageDialogOpenPolicyTest, SuppressWindowOpen) {
695 [[web_delegate_mock() expect] webControllerDidSuppressDialog:webController_]; 699 [[web_delegate_mock() expect]
696 [webController_ setShouldSuppressDialogs:YES]; 700 webControllerDidSuppressDialog:web_controller()];
701 [web_controller() setShouldSuppressDialogs:YES];
697 EvaluateJavaScriptAsString(@"window.open('')"); 702 EvaluateJavaScriptAsString(@"window.open('')");
698 } 703 }
699 704
700 // A separate test class, as none of the |CRWWebControllerTest| setup is 705 // A separate test class, as none of the |CRWWebControllerTest| setup is
701 // needed. 706 // needed.
702 class CRWWebControllerPageScrollStateTest 707 class CRWWebControllerPageScrollStateTest
703 : public web::WebTestWithWebController { 708 : public web::WebTestWithWebController {
704 protected: 709 protected:
705 // Returns a web::PageDisplayState that will scroll a WKWebView to 710 // Returns a web::PageDisplayState that will scroll a WKWebView to
706 // |scrollOffset| and zoom the content by |relativeZoomScale|. 711 // |scrollOffset| and zoom the content by |relativeZoomScale|.
(...skipping 12 matching lines...) Expand all
719 724
720 // TODO(iOS): Flaky on the bots. crbug/493427 725 // TODO(iOS): Flaky on the bots. crbug/493427
721 TEST_F(CRWWebControllerPageScrollStateTest, 726 TEST_F(CRWWebControllerPageScrollStateTest,
722 FLAKY_SetPageDisplayStateWithUserScalableDisabled) { 727 FLAKY_SetPageDisplayStateWithUserScalableDisabled) {
723 #if !TARGET_IPHONE_SIMULATOR 728 #if !TARGET_IPHONE_SIMULATOR
724 // TODO(crbug.com/453530): fails flakily on device, so skip it there. 729 // TODO(crbug.com/453530): fails flakily on device, so skip it there.
725 return; 730 return;
726 #endif 731 #endif
727 web::PageZoomState zoom_state(1.0, 5.0, 1.0); 732 web::PageZoomState zoom_state(1.0, 5.0, 1.0);
728 LoadHtml(GetHTMLForZoomState(zoom_state, PAGE_SCALABILITY_DISABLED)); 733 LoadHtml(GetHTMLForZoomState(zoom_state, PAGE_SCALABILITY_DISABLED));
729 CRWWebController* web_controller = webController_.get(); 734 WaitForZoomRendering(web_controller(), zoom_state);
730 WaitForZoomRendering(web_controller, zoom_state);
731 web::PageZoomState original_zoom_state = 735 web::PageZoomState original_zoom_state =
732 web_controller.pageDisplayState.zoom_state(); 736 web_controller().pageDisplayState.zoom_state();
733 737
734 web::NavigationManager* nagivation_manager = 738 web::NavigationManager* nagivation_manager =
735 web_controller.webState->GetNavigationManager(); 739 web_state()->GetNavigationManager();
736 nagivation_manager->GetLastCommittedItem()->SetPageDisplayState( 740 nagivation_manager->GetLastCommittedItem()->SetPageDisplayState(
737 CreateTestPageDisplayState(CGPointMake(1.0, 1.0), // scroll offset 741 CreateTestPageDisplayState(CGPointMake(1.0, 1.0), // scroll offset
738 3.0, // relative zoom scale 742 3.0, // relative zoom scale
739 1.0, // original minimum zoom scale 743 1.0, // original minimum zoom scale
740 5.0, // original maximum zoom scale 744 5.0, // original maximum zoom scale
741 1.0)); // original zoom scale 745 1.0)); // original zoom scale
742 [web_controller restoreStateFromHistory]; 746 [web_controller() restoreStateFromHistory];
743 747
744 // |-restoreStateFromHistory| is async; wait for its completion. 748 // |-restoreStateFromHistory| is async; wait for its completion.
745 base::test::ios::WaitUntilCondition(^bool() { 749 base::test::ios::WaitUntilCondition(^bool() {
746 return web_controller.pageDisplayState.scroll_state().offset_x() == 1.0; 750 return web_controller().pageDisplayState.scroll_state().offset_x() == 1.0;
747 }); 751 });
748 752
749 ASSERT_EQ(original_zoom_state, web_controller.pageDisplayState.zoom_state()); 753 ASSERT_EQ(original_zoom_state,
754 web_controller().pageDisplayState.zoom_state());
750 }; 755 };
751 756
752 // TODO(iOS): Flaky on the bots. crbug/493427 757 // TODO(iOS): Flaky on the bots. crbug/493427
753 TEST_F(CRWWebControllerPageScrollStateTest, 758 TEST_F(CRWWebControllerPageScrollStateTest,
754 FLAKY_SetPageDisplayStateWithUserScalableEnabled) { 759 FLAKY_SetPageDisplayStateWithUserScalableEnabled) {
755 web::PageZoomState zoom_state(1.0, 10.0, 1.0); 760 web::PageZoomState zoom_state(1.0, 10.0, 1.0);
756 LoadHtml(GetHTMLForZoomState(zoom_state, PAGE_SCALABILITY_ENABLED)); 761 LoadHtml(GetHTMLForZoomState(zoom_state, PAGE_SCALABILITY_ENABLED));
757 CRWWebController* web_controller = webController_.get(); 762 WaitForZoomRendering(web_controller(), zoom_state);
758 WaitForZoomRendering(web_controller, zoom_state);
759 763
760 web::NavigationManager* nagivation_manager = 764 web::NavigationManager* nagivation_manager =
761 web_controller.webState->GetNavigationManager(); 765 web_state()->GetNavigationManager();
762 nagivation_manager->GetLastCommittedItem()->SetPageDisplayState( 766 nagivation_manager->GetLastCommittedItem()->SetPageDisplayState(
763 CreateTestPageDisplayState(CGPointMake(1.0, 1.0), // scroll offset 767 CreateTestPageDisplayState(CGPointMake(1.0, 1.0), // scroll offset
764 3.0, // relative zoom scale 768 3.0, // relative zoom scale
765 1.0, // original minimum zoom scale 769 1.0, // original minimum zoom scale
766 10.0, // original maximum zoom scale 770 10.0, // original maximum zoom scale
767 1.0)); // original zoom scale 771 1.0)); // original zoom scale
768 [web_controller restoreStateFromHistory]; 772 [web_controller() restoreStateFromHistory];
769 773
770 // |-restoreStateFromHistory| is async; wait for its completion. 774 // |-restoreStateFromHistory| is async; wait for its completion.
771 base::test::ios::WaitUntilCondition(^bool() { 775 base::test::ios::WaitUntilCondition(^bool() {
772 return web_controller.pageDisplayState.scroll_state().offset_x() == 1.0; 776 return web_controller().pageDisplayState.scroll_state().offset_x() == 1.0;
773 }); 777 });
774 778
775 web::PageZoomState final_zoom_state = 779 web::PageZoomState final_zoom_state =
776 web_controller.pageDisplayState.zoom_state(); 780 web_controller().pageDisplayState.zoom_state();
777 EXPECT_FLOAT_EQ(3, final_zoom_state.zoom_scale() / 781 EXPECT_FLOAT_EQ(3, final_zoom_state.zoom_scale() /
778 final_zoom_state.minimum_zoom_scale()); 782 final_zoom_state.minimum_zoom_scale());
779 }; 783 };
780 784
781 // TODO(iOS): Flaky on the bots. crbug/493427 785 // TODO(iOS): Flaky on the bots. crbug/493427
782 TEST_F(CRWWebControllerPageScrollStateTest, FLAKY_AtTop) { 786 TEST_F(CRWWebControllerPageScrollStateTest, FLAKY_AtTop) {
783 // This test fails on iPhone 6/6+; skip until it's fixed. crbug.com/453105 787 // This test fails on iPhone 6/6+; skip until it's fixed. crbug.com/453105
784 if (IsIPhone6Or6Plus()) 788 if (IsIPhone6Or6Plus())
785 return; 789 return;
786 790
787 web::PageZoomState zoom_state = web::PageZoomState(1.0, 5.0, 1.0); 791 web::PageZoomState zoom_state = web::PageZoomState(1.0, 5.0, 1.0);
788 LoadHtml(GetHTMLForZoomState(zoom_state, PAGE_SCALABILITY_ENABLED)); 792 LoadHtml(GetHTMLForZoomState(zoom_state, PAGE_SCALABILITY_ENABLED));
789 CRWWebController* web_controller = webController_.get(); 793 WaitForZoomRendering(web_controller(), zoom_state);
790 WaitForZoomRendering(web_controller, zoom_state); 794 ASSERT_TRUE(web_controller().atTop);
791 ASSERT_TRUE(web_controller.atTop);
792 795
793 web::NavigationManager* nagivation_manager = 796 web::NavigationManager* nagivation_manager =
794 web_controller.webState->GetNavigationManager(); 797 web_state()->GetNavigationManager();
795 nagivation_manager->GetLastCommittedItem()->SetPageDisplayState( 798 nagivation_manager->GetLastCommittedItem()->SetPageDisplayState(
796 CreateTestPageDisplayState(CGPointMake(0.0, 30.0), // scroll offset 799 CreateTestPageDisplayState(CGPointMake(0.0, 30.0), // scroll offset
797 5.0, // relative zoom scale 800 5.0, // relative zoom scale
798 1.0, // original minimum zoom scale 801 1.0, // original minimum zoom scale
799 5.0, // original maximum zoom scale 802 5.0, // original maximum zoom scale
800 1.0)); // original zoom scale 803 1.0)); // original zoom scale
801 [web_controller restoreStateFromHistory]; 804 [web_controller() restoreStateFromHistory];
802 805
803 // |-restoreStateFromHistory| is async; wait for its completion. 806 // |-restoreStateFromHistory| is async; wait for its completion.
804 base::test::ios::WaitUntilCondition(^bool() { 807 base::test::ios::WaitUntilCondition(^bool() {
805 return web_controller.pageDisplayState.scroll_state().offset_y() == 30.0; 808 return web_controller().pageDisplayState.scroll_state().offset_y() == 30.0;
806 }); 809 });
807 810
808 ASSERT_FALSE(web_controller.atTop); 811 ASSERT_FALSE(web_controller().atTop);
809 }; 812 };
810 813
811 // Real WKWebView is required for CRWWebControllerJSExecutionTest. 814 // Real WKWebView is required for CRWWebControllerJSExecutionTest.
812 typedef web::WebTestWithWebController CRWWebControllerJSExecutionTest; 815 typedef web::WebTestWithWebController CRWWebControllerJSExecutionTest;
813 816
814 // Tests that a script correctly evaluates to string. 817 // Tests that a script correctly evaluates to string.
815 TEST_F(CRWWebControllerJSExecutionTest, LegacyAPIExecution) { 818 TEST_F(CRWWebControllerJSExecutionTest, LegacyAPIExecution) {
816 LoadHtml(@"<p></p>"); 819 LoadHtml(@"<p></p>");
817 EXPECT_NSEQ(@"true", EvaluateJavaScriptAsString(@"true")); 820 EXPECT_NSEQ(@"true", EvaluateJavaScriptAsString(@"true"));
818 EXPECT_NSEQ(@"false", EvaluateJavaScriptAsString(@"false")); 821 EXPECT_NSEQ(@"false", EvaluateJavaScriptAsString(@"false"));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 860
858 TEST_F(CRWWebControllerTest, WebUrlWithTrustLevel) { 861 TEST_F(CRWWebControllerTest, WebUrlWithTrustLevel) {
859 [[[mockWebView_ stub] andReturn:[NSURL URLWithString:kTestURLString]] URL]; 862 [[[mockWebView_ stub] andReturn:[NSURL URLWithString:kTestURLString]] URL];
860 [[[mockWebView_ stub] andReturnBool:NO] hasOnlySecureContent]; 863 [[[mockWebView_ stub] andReturnBool:NO] hasOnlySecureContent];
861 864
862 // Stub out the injection process. 865 // Stub out the injection process.
863 [[mockWebView_ stub] evaluateJavaScript:OCMOCK_ANY 866 [[mockWebView_ stub] evaluateJavaScript:OCMOCK_ANY
864 completionHandler:OCMOCK_ANY]; 867 completionHandler:OCMOCK_ANY];
865 868
866 // Simulate registering load request to avoid failing page load simulation. 869 // Simulate registering load request to avoid failing page load simulation.
867 [webController_ simulateLoadRequestWithURL:GURL([kTestURLString UTF8String])]; 870 [web_controller()
871 simulateLoadRequestWithURL:GURL([kTestURLString UTF8String])];
868 // Simulate a page load to trigger a URL update. 872 // Simulate a page load to trigger a URL update.
869 [static_cast<id<WKNavigationDelegate>>(webController_.get()) 873 [static_cast<id<WKNavigationDelegate>>(web_controller()) webView:mockWebView_
870 webView:mockWebView_ 874 didCommitNavigation:nil];
871 didCommitNavigation:nil];
872 875
873 web::URLVerificationTrustLevel trust_level = web::kNone; 876 web::URLVerificationTrustLevel trust_level = web::kNone;
874 GURL gurl = [webController_ currentURLWithTrustLevel:&trust_level]; 877 GURL gurl = [web_controller() currentURLWithTrustLevel:&trust_level];
875 878
876 EXPECT_EQ(gurl, GURL(base::SysNSStringToUTF8(kTestURLString))); 879 EXPECT_EQ(gurl, GURL(base::SysNSStringToUTF8(kTestURLString)));
877 EXPECT_EQ(web::kAbsolute, trust_level); 880 EXPECT_EQ(web::kAbsolute, trust_level);
878 } 881 }
879 882
880 // A separate test class, as none of the |CRWUIWebViewWebControllerTest| setup 883 // A separate test class, as none of the |CRWUIWebViewWebControllerTest| setup
881 // is needed; 884 // is needed;
882 typedef web::WebTestWithWebController CRWWebControllerObserversTest; 885 typedef web::WebTestWithWebController CRWWebControllerObserversTest;
883 886
884 // Tests that CRWWebControllerObservers are called. 887 // Tests that CRWWebControllerObservers are called.
885 TEST_F(CRWWebControllerObserversTest, Observers) { 888 TEST_F(CRWWebControllerObserversTest, Observers) {
886 base::scoped_nsobject<CountingObserver> observer( 889 base::scoped_nsobject<CountingObserver> observer(
887 [[CountingObserver alloc] init]); 890 [[CountingObserver alloc] init]);
888 CRWWebController* web_controller = webController_; 891 EXPECT_EQ(0u, [web_controller() observerCount]);
889 EXPECT_EQ(0u, [web_controller observerCount]); 892 [web_controller() addObserver:observer];
890 [web_controller addObserver:observer]; 893 EXPECT_EQ(1u, [web_controller() observerCount]);
891 EXPECT_EQ(1u, [web_controller observerCount]);
892 894
893 EXPECT_EQ(0, [observer pageLoadedCount]); 895 EXPECT_EQ(0, [observer pageLoadedCount]);
894 [web_controller webStateImpl]->OnPageLoaded(GURL("http://test"), false); 896 [web_controller() webStateImpl]->OnPageLoaded(GURL("http://test"), false);
895 EXPECT_EQ(0, [observer pageLoadedCount]); 897 EXPECT_EQ(0, [observer pageLoadedCount]);
896 [web_controller webStateImpl]->OnPageLoaded(GURL("http://test"), true); 898 [web_controller() webStateImpl]->OnPageLoaded(GURL("http://test"), true);
897 EXPECT_EQ(1, [observer pageLoadedCount]); 899 EXPECT_EQ(1, [observer pageLoadedCount]);
898 900
899 EXPECT_EQ(0, [observer messageCount]); 901 EXPECT_EQ(0, [observer messageCount]);
900 // Non-matching prefix. 902 // Non-matching prefix.
901 EXPECT_FALSE([web_controller webStateImpl]->OnScriptCommandReceived( 903 EXPECT_FALSE([web_controller() webStateImpl]->OnScriptCommandReceived(
902 "a", base::DictionaryValue(), GURL("http://test"), true)); 904 "a", base::DictionaryValue(), GURL("http://test"), true));
903 EXPECT_EQ(0, [observer messageCount]); 905 EXPECT_EQ(0, [observer messageCount]);
904 // Matching prefix. 906 // Matching prefix.
905 EXPECT_TRUE([web_controller webStateImpl]->OnScriptCommandReceived( 907 EXPECT_TRUE([web_controller() webStateImpl]->OnScriptCommandReceived(
906 base::SysNSStringToUTF8([observer commandPrefix]) + ".foo", 908 base::SysNSStringToUTF8([observer commandPrefix]) + ".foo",
907 base::DictionaryValue(), GURL("http://test"), true)); 909 base::DictionaryValue(), GURL("http://test"), true));
908 EXPECT_EQ(1, [observer messageCount]); 910 EXPECT_EQ(1, [observer messageCount]);
909 911
910 [web_controller removeObserver:observer]; 912 [web_controller() removeObserver:observer];
911 EXPECT_EQ(0u, [web_controller observerCount]); 913 EXPECT_EQ(0u, [web_controller() observerCount]);
912 }; 914 };
913 915
914 // Test fixture for window.open tests. 916 // Test fixture for window.open tests.
915 class CRWWebControllerWindowOpenTest : public web::WebTestWithWebController { 917 class CRWWebControllerWindowOpenTest : public web::WebTestWithWebController {
916 protected: 918 protected:
917 void SetUp() override { 919 void SetUp() override {
918 web::WebTestWithWebController::SetUp(); 920 web::WebTestWithWebController::SetUp();
919 921
920 // Configure web delegate. 922 // Configure web delegate.
921 delegate_.reset([[MockInteractionLoader alloc] 923 delegate_.reset([[MockInteractionLoader alloc]
922 initWithRepresentedObject: 924 initWithRepresentedObject:
923 [OCMockObject niceMockForProtocol:@protocol(CRWWebDelegate)]]); 925 [OCMockObject niceMockForProtocol:@protocol(CRWWebDelegate)]]);
924 ASSERT_TRUE([delegate_ blockPopups]); 926 ASSERT_TRUE([delegate_ blockPopups]);
925 [webController_ setDelegate:delegate_]; 927 [web_controller() setDelegate:delegate_];
926 928
927 // Configure child web state. 929 // Configure child web state.
928 child_web_state_.reset(new web::WebStateImpl(GetBrowserState())); 930 child_web_state_.reset(new web::WebStateImpl(GetBrowserState()));
929 child_web_state_->SetWebUsageEnabled(true); 931 child_web_state_->SetWebUsageEnabled(true);
930 [delegate_ setChildWebController:child_web_state_->GetWebController()]; 932 [delegate_ setChildWebController:child_web_state_->GetWebController()];
931 933
932 // Configure child web controller's session controller mock. 934 // Configure child web controller's session controller mock.
933 id sessionController = 935 id sessionController =
934 [OCMockObject niceMockForClass:[CRWSessionController class]]; 936 [OCMockObject niceMockForClass:[CRWSessionController class]];
935 BOOL yes = YES; 937 BOOL yes = YES;
936 [[[sessionController stub] andReturnValue:OCMOCK_VALUE(yes)] isOpenedByDOM]; 938 [[[sessionController stub] andReturnValue:OCMOCK_VALUE(yes)] isOpenedByDOM];
937 child_web_state_->GetNavigationManagerImpl().SetSessionController( 939 child_web_state_->GetNavigationManagerImpl().SetSessionController(
938 sessionController); 940 sessionController);
939 941
940 LoadHtml(@"<html><body></body></html>"); 942 LoadHtml(@"<html><body></body></html>");
941 } 943 }
942 void TearDown() override { 944 void TearDown() override {
943 EXPECT_OCMOCK_VERIFY(delegate_); 945 EXPECT_OCMOCK_VERIFY(delegate_);
944 [webController_ setDelegate:nil]; 946 [web_controller() setDelegate:nil];
945 947
946 web::WebTestWithWebController::TearDown(); 948 web::WebTestWithWebController::TearDown();
947 } 949 }
948 // Executes JavaScript that opens a new window and returns evaluation result 950 // Executes JavaScript that opens a new window and returns evaluation result
949 // as a string. 951 // as a string.
950 NSString* OpenWindowByDOM() { 952 NSString* OpenWindowByDOM() {
951 NSString* const kOpenWindowScript = 953 NSString* const kOpenWindowScript =
952 @"var w = window.open('javascript:void(0);', target='_blank');" 954 @"var w = window.open('javascript:void(0);', target='_blank');"
953 "w.toString();"; 955 "w.toString();";
954 NSString* windowJSObject = EvaluateJavaScriptAsString(kOpenWindowScript); 956 NSString* windowJSObject = EvaluateJavaScriptAsString(kOpenWindowScript);
955 WaitForBackgroundTasks(); 957 WaitForBackgroundTasks();
956 return windowJSObject; 958 return windowJSObject;
957 } 959 }
958 // A CRWWebDelegate mock used for testing. 960 // A CRWWebDelegate mock used for testing.
959 base::scoped_nsobject<id> delegate_; 961 base::scoped_nsobject<id> delegate_;
960 // A child WebState used for testing. 962 // A child WebState used for testing.
961 std::unique_ptr<web::WebStateImpl> child_web_state_; 963 std::unique_ptr<web::WebStateImpl> child_web_state_;
962 }; 964 };
963 965
964 // Tests that absence of web delegate is handled gracefully. 966 // Tests that absence of web delegate is handled gracefully.
965 TEST_F(CRWWebControllerWindowOpenTest, NoDelegate) { 967 TEST_F(CRWWebControllerWindowOpenTest, NoDelegate) {
966 [webController_ setDelegate:nil]; 968 [web_controller() setDelegate:nil];
967 969
968 EXPECT_NSEQ(@"", OpenWindowByDOM()); 970 EXPECT_NSEQ(@"", OpenWindowByDOM());
969 971
970 EXPECT_FALSE([delegate_ blockedPopupInfo]); 972 EXPECT_FALSE([delegate_ blockedPopupInfo]);
971 } 973 }
972 974
973 // Tests that window.open triggered by user gesture opens a new non-popup 975 // Tests that window.open triggered by user gesture opens a new non-popup
974 // window. 976 // window.
975 TEST_F(CRWWebControllerWindowOpenTest, OpenWithUserGesture) { 977 TEST_F(CRWWebControllerWindowOpenTest, OpenWithUserGesture) {
976 SEL selector = @selector(webPageOrderedOpen); 978 SEL selector = @selector(webPageOrderedOpen);
977 [delegate_ onSelector:selector 979 [delegate_ onSelector:selector
978 callBlockExpectation:^(){ 980 callBlockExpectation:^(){
979 }]; 981 }];
980 982
981 [webController_ touched:YES]; 983 [web_controller() touched:YES];
982 EXPECT_NSEQ(@"[object Window]", OpenWindowByDOM()); 984 EXPECT_NSEQ(@"[object Window]", OpenWindowByDOM());
983 EXPECT_FALSE([delegate_ blockedPopupInfo]); 985 EXPECT_FALSE([delegate_ blockedPopupInfo]);
984 } 986 }
985 987
986 // Tests that window.open executed w/o user gesture does not open a new window. 988 // Tests that window.open executed w/o user gesture does not open a new window.
987 // Once the blocked popup is allowed a new window is opened. 989 // Once the blocked popup is allowed a new window is opened.
988 TEST_F(CRWWebControllerWindowOpenTest, AllowPopup) { 990 TEST_F(CRWWebControllerWindowOpenTest, AllowPopup) {
989 SEL selector = 991 SEL selector =
990 @selector(webPageOrderedOpen:referrer:windowName:inBackground:); 992 @selector(webPageOrderedOpen:referrer:windowName:inBackground:);
991 [delegate_ onSelector:selector 993 [delegate_ onSelector:selector
992 callBlockExpectation:^(const GURL& new_window_url, 994 callBlockExpectation:^(const GURL& new_window_url,
993 const web::Referrer& referrer, 995 const web::Referrer& referrer,
994 NSString* obsoleted_window_name, 996 NSString* obsoleted_window_name,
995 BOOL in_background) { 997 BOOL in_background) {
996 EXPECT_EQ("javascript:void(0);", new_window_url.spec()); 998 EXPECT_EQ("javascript:void(0);", new_window_url.spec());
997 EXPECT_EQ("", referrer.url.spec()); 999 EXPECT_EQ("", referrer.url.spec());
998 EXPECT_FALSE(in_background); 1000 EXPECT_FALSE(in_background);
999 }]; 1001 }];
1000 1002
1001 ASSERT_FALSE([webController_ userIsInteracting]); 1003 ASSERT_FALSE([web_controller() userIsInteracting]);
1002 EXPECT_NSEQ(@"", OpenWindowByDOM()); 1004 EXPECT_NSEQ(@"", OpenWindowByDOM());
1003 base::test::ios::WaitUntilCondition(^bool() { 1005 base::test::ios::WaitUntilCondition(^bool() {
1004 return [delegate_ blockedPopupInfo]; 1006 return [delegate_ blockedPopupInfo];
1005 }); 1007 });
1006 1008
1007 if ([delegate_ blockedPopupInfo]) 1009 if ([delegate_ blockedPopupInfo])
1008 [delegate_ blockedPopupInfo]->ShowPopup(); 1010 [delegate_ blockedPopupInfo]->ShowPopup();
1009 1011
1010 EXPECT_EQ("", [delegate_ sourceURL].spec()); 1012 EXPECT_EQ("", [delegate_ sourceURL].spec());
1011 EXPECT_EQ("javascript:void(0);", [delegate_ popupURL].spec()); 1013 EXPECT_EQ("javascript:void(0);", [delegate_ popupURL].spec());
(...skipping 10 matching lines...) Expand all
1022 1024
1023 EXPECT_NSEQ(@"[object Window]", OpenWindowByDOM()); 1025 EXPECT_NSEQ(@"[object Window]", OpenWindowByDOM());
1024 EXPECT_FALSE([delegate_ blockedPopupInfo]); 1026 EXPECT_FALSE([delegate_ blockedPopupInfo]);
1025 1027
1026 EXPECT_EQ("", [delegate_ sourceURL].spec()); 1028 EXPECT_EQ("", [delegate_ sourceURL].spec());
1027 EXPECT_EQ("javascript:void(0);", [delegate_ popupURL].spec()); 1029 EXPECT_EQ("javascript:void(0);", [delegate_ popupURL].spec());
1028 } 1030 }
1029 1031
1030 // Tests that window.open executed w/o user gesture does not open a new window. 1032 // Tests that window.open executed w/o user gesture does not open a new window.
1031 TEST_F(CRWWebControllerWindowOpenTest, BlockPopup) { 1033 TEST_F(CRWWebControllerWindowOpenTest, BlockPopup) {
1032 ASSERT_FALSE([webController_ userIsInteracting]); 1034 ASSERT_FALSE([web_controller() userIsInteracting]);
1033 EXPECT_NSEQ(@"", OpenWindowByDOM()); 1035 EXPECT_NSEQ(@"", OpenWindowByDOM());
1034 base::test::ios::WaitUntilCondition(^bool() { 1036 base::test::ios::WaitUntilCondition(^bool() {
1035 return [delegate_ blockedPopupInfo]; 1037 return [delegate_ blockedPopupInfo];
1036 }); 1038 });
1037 1039
1038 EXPECT_EQ("", [delegate_ sourceURL].spec()); 1040 EXPECT_EQ("", [delegate_ sourceURL].spec());
1039 EXPECT_EQ("javascript:void(0);", [delegate_ popupURL].spec()); 1041 EXPECT_EQ("javascript:void(0);", [delegate_ popupURL].spec());
1040 }; 1042 };
1041 1043
1042 // Fixture class to test WKWebView crashes. 1044 // Fixture class to test WKWebView crashes.
1043 class CRWWebControllerWebProcessTest : public web::WebTestWithWebController { 1045 class CRWWebControllerWebProcessTest : public web::WebTestWithWebController {
1044 protected: 1046 protected:
1045 void SetUp() override { 1047 void SetUp() override {
1046 web::WebTestWithWebController::SetUp(); 1048 web::WebTestWithWebController::SetUp();
1047 webView_.reset(web::CreateTerminatedWKWebView()); 1049 webView_.reset(web::CreateTerminatedWKWebView());
1048 base::scoped_nsobject<TestWebViewContentView> webViewContentView( 1050 base::scoped_nsobject<TestWebViewContentView> webViewContentView(
1049 [[TestWebViewContentView alloc] 1051 [[TestWebViewContentView alloc]
1050 initWithMockWebView:webView_ 1052 initWithMockWebView:webView_
1051 scrollView:[webView_ scrollView]]); 1053 scrollView:[webView_ scrollView]]);
1052 [webController_ injectWebViewContentView:webViewContentView]; 1054 [web_controller() injectWebViewContentView:webViewContentView];
1053 } 1055 }
1054 base::scoped_nsobject<WKWebView> webView_; 1056 base::scoped_nsobject<WKWebView> webView_;
1055 }; 1057 };
1056 1058
1057 // Tests that -[CRWWebDelegate webControllerWebProcessDidCrash:] is called 1059 // Tests that -[CRWWebDelegate webControllerWebProcessDidCrash:] is called
1058 // when WKWebView web process has crashed. 1060 // when WKWebView web process has crashed.
1059 TEST_F(CRWWebControllerWebProcessTest, Crash) { 1061 TEST_F(CRWWebControllerWebProcessTest, Crash) {
1060 id delegate = [OCMockObject niceMockForProtocol:@protocol(CRWWebDelegate)]; 1062 id delegate = [OCMockObject niceMockForProtocol:@protocol(CRWWebDelegate)];
1061 [[delegate expect] webControllerWebProcessDidCrash:webController_]; 1063 [[delegate expect] webControllerWebProcessDidCrash:web_controller()];
1062 1064
1063 [webController_ setDelegate:delegate]; 1065 [web_controller() setDelegate:delegate];
1064 web::SimulateWKWebViewCrash(webView_); 1066 web::SimulateWKWebViewCrash(webView_);
1065 1067
1066 EXPECT_OCMOCK_VERIFY(delegate); 1068 EXPECT_OCMOCK_VERIFY(delegate);
1067 EXPECT_FALSE([webController_ isViewAlive]); 1069 EXPECT_FALSE([web_controller() isViewAlive]);
1068 [webController_ setDelegate:nil]; 1070 [web_controller() setDelegate:nil];
1069 }; 1071 };
1070 1072
1071 } // namespace 1073 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698