| 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 [web_controller() URLForHistoryNavigationToItem:&to_item | 232 [web_controller() URLForHistoryNavigationToItem:&to_item |
| 233 previousURL:previous_url]); | 233 previousURL:previous_url]); |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 } | 237 } |
| 238 | 238 |
| 239 // Tests that AllowCertificateError is called with correct arguments if | 239 // Tests that AllowCertificateError is called with correct arguments if |
| 240 // WKWebView fails to load a page with bad SSL cert. | 240 // WKWebView fails to load a page with bad SSL cert. |
| 241 TEST_F(CRWWebControllerTest, SslCertError) { | 241 TEST_F(CRWWebControllerTest, SslCertError) { |
| 242 web::TestWebStateObserver observer(web_state()); |
| 243 ASSERT_FALSE(observer.did_change_visible_security_state_info()); |
| 244 |
| 242 // Last arguments passed to AllowCertificateError must be in default state. | 245 // Last arguments passed to AllowCertificateError must be in default state. |
| 243 ASSERT_FALSE(GetWebClient()->last_cert_error_code()); | 246 ASSERT_FALSE(GetWebClient()->last_cert_error_code()); |
| 244 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().is_valid()); | 247 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().is_valid()); |
| 245 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().cert_status); | 248 ASSERT_FALSE(GetWebClient()->last_cert_error_ssl_info().cert_status); |
| 246 ASSERT_FALSE(GetWebClient()->last_cert_error_request_url().is_valid()); | 249 ASSERT_FALSE(GetWebClient()->last_cert_error_request_url().is_valid()); |
| 247 ASSERT_TRUE(GetWebClient()->last_cert_error_overridable()); | 250 ASSERT_TRUE(GetWebClient()->last_cert_error_overridable()); |
| 248 | 251 |
| 249 scoped_refptr<net::X509Certificate> cert = | 252 scoped_refptr<net::X509Certificate> cert = |
| 250 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | 253 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); |
| 251 | 254 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 267 didFailProvisionalNavigation:static_cast<WKNavigation*>(navigation) | 270 didFailProvisionalNavigation:static_cast<WKNavigation*>(navigation) |
| 268 withError:error]; | 271 withError:error]; |
| 269 | 272 |
| 270 // Verify correctness of AllowCertificateError method call. | 273 // Verify correctness of AllowCertificateError method call. |
| 271 EXPECT_EQ(net::ERR_CERT_INVALID, GetWebClient()->last_cert_error_code()); | 274 EXPECT_EQ(net::ERR_CERT_INVALID, GetWebClient()->last_cert_error_code()); |
| 272 EXPECT_TRUE(GetWebClient()->last_cert_error_ssl_info().is_valid()); | 275 EXPECT_TRUE(GetWebClient()->last_cert_error_ssl_info().is_valid()); |
| 273 EXPECT_EQ(net::CERT_STATUS_INVALID, | 276 EXPECT_EQ(net::CERT_STATUS_INVALID, |
| 274 GetWebClient()->last_cert_error_ssl_info().cert_status); | 277 GetWebClient()->last_cert_error_ssl_info().cert_status); |
| 275 EXPECT_EQ(url, GetWebClient()->last_cert_error_request_url()); | 278 EXPECT_EQ(url, GetWebClient()->last_cert_error_request_url()); |
| 276 EXPECT_FALSE(GetWebClient()->last_cert_error_overridable()); | 279 EXPECT_FALSE(GetWebClient()->last_cert_error_overridable()); |
| 280 |
| 281 // Verify that |DidChangeVisibleSecurityState| was called. |
| 282 ASSERT_TRUE(observer.did_change_visible_security_state_info()); |
| 283 EXPECT_EQ(web_state(), |
| 284 observer.did_change_visible_security_state_info()->web_state); |
| 277 } | 285 } |
| 278 | 286 |
| 279 // Test fixture to test |setPageDialogOpenPolicy:|. | 287 // Test fixture to test |setPageDialogOpenPolicy:|. |
| 280 class CRWWebControllerPageDialogOpenPolicyTest | 288 class CRWWebControllerPageDialogOpenPolicyTest |
| 281 : public web::WebTestWithWebController { | 289 : public web::WebTestWithWebController { |
| 282 protected: | 290 protected: |
| 283 CRWWebControllerPageDialogOpenPolicyTest() | 291 CRWWebControllerPageDialogOpenPolicyTest() |
| 284 : page_url_("https://chromium.test/") {} | 292 : page_url_("https://chromium.test/") {} |
| 285 void SetUp() override { | 293 void SetUp() override { |
| 286 web::WebTestWithWebController::SetUp(); | 294 web::WebTestWithWebController::SetUp(); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 CRWSessionController* session_controller = nav_manager.GetSessionController(); | 573 CRWSessionController* session_controller = nav_manager.GetSessionController(); |
| 566 EXPECT_EQ(2U, session_controller.items.size()); | 574 EXPECT_EQ(2U, session_controller.items.size()); |
| 567 EXPECT_EQ(session_controller.items.back().get(), | 575 EXPECT_EQ(session_controller.items.back().get(), |
| 568 session_controller.currentItem); | 576 session_controller.currentItem); |
| 569 | 577 |
| 570 [web_controller() goToItemAtIndex:0]; | 578 [web_controller() goToItemAtIndex:0]; |
| 571 EXPECT_EQ(session_controller.items.front().get(), | 579 EXPECT_EQ(session_controller.items.front().get(), |
| 572 session_controller.currentItem); | 580 session_controller.currentItem); |
| 573 } | 581 } |
| 574 | 582 |
| 575 // Tests that didShowPasswordInputOnHTTP updates the SSLStatus to indicate that | 583 // Test fixture for testing visible security state. |
| 584 typedef web::WebTestWithWebState CRWWebStateSecurityStateTest; |
| 585 |
| 586 // Tests that OnPasswordInputShownOnHttp updates the SSLStatus to indicate that |
| 576 // a password field has been displayed on an HTTP page. | 587 // a password field has been displayed on an HTTP page. |
| 577 TEST_F(CRWWebControllerNavigationTest, HTTPPassword) { | 588 TEST_F(CRWWebStateSecurityStateTest, HttpPassword) { |
| 578 LoadHtml(@"<html><body></body></html>", GURL("http://chromium.test")); | 589 LoadHtml(@"<html><body></body></html>", GURL("http://chromium.test")); |
| 579 NavigationManagerImpl& nav_manager = | 590 web::NavigationManager* nav_manager = web_state()->GetNavigationManager(); |
| 580 web_controller().webStateImpl->GetNavigationManagerImpl(); | 591 EXPECT_FALSE(nav_manager->GetLastCommittedItem()->GetSSL().content_status & |
| 581 EXPECT_FALSE(nav_manager.GetLastCommittedItem()->GetSSL().content_status & | |
| 582 web::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); | 592 web::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); |
| 583 [web_controller() didShowPasswordInputOnHTTP]; | 593 web::TestWebStateObserver observer(web_state()); |
| 584 EXPECT_TRUE(nav_manager.GetLastCommittedItem()->GetSSL().content_status & | 594 ASSERT_FALSE(observer.did_change_visible_security_state_info()); |
| 595 web_state()->OnPasswordInputShownOnHttp(); |
| 596 EXPECT_TRUE(nav_manager->GetLastCommittedItem()->GetSSL().content_status & |
| 585 web::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); | 597 web::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); |
| 598 ASSERT_TRUE(observer.did_change_visible_security_state_info()); |
| 599 EXPECT_EQ(web_state(), |
| 600 observer.did_change_visible_security_state_info()->web_state); |
| 586 } | 601 } |
| 587 | 602 |
| 588 // Tests that didShowCreditCardInputOnHTTP updates the SSLStatus to indicate | 603 // Tests that OnCreditCardInputShownOnHttp updates the SSLStatus to indicate |
| 589 // that a credit card field has been displayed on an HTTP page. | 604 // that a credit card field has been displayed on an HTTP page. |
| 590 TEST_F(CRWWebControllerNavigationTest, HTTPCreditCard) { | 605 TEST_F(CRWWebStateSecurityStateTest, HttpCreditCard) { |
| 591 LoadHtml(@"<html><body></body></html>", GURL("http://chromium.test")); | 606 LoadHtml(@"<html><body></body></html>", GURL("http://chromium.test")); |
| 592 NavigationManagerImpl& nav_manager = | 607 web::NavigationManager* nav_manager = web_state()->GetNavigationManager(); |
| 593 web_controller().webStateImpl->GetNavigationManagerImpl(); | 608 EXPECT_FALSE(nav_manager->GetLastCommittedItem()->GetSSL().content_status & |
| 594 EXPECT_FALSE(nav_manager.GetLastCommittedItem()->GetSSL().content_status & | |
| 595 web::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP); | 609 web::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP); |
| 596 [web_controller() didShowCreditCardInputOnHTTP]; | 610 web::TestWebStateObserver observer(web_state()); |
| 597 EXPECT_TRUE(nav_manager.GetLastCommittedItem()->GetSSL().content_status & | 611 ASSERT_FALSE(observer.did_change_visible_security_state_info()); |
| 612 web_state()->OnCreditCardInputShownOnHttp(); |
| 613 EXPECT_TRUE(nav_manager->GetLastCommittedItem()->GetSSL().content_status & |
| 598 web::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP); | 614 web::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP); |
| 615 ASSERT_TRUE(observer.did_change_visible_security_state_info()); |
| 616 EXPECT_EQ(web_state(), |
| 617 observer.did_change_visible_security_state_info()->web_state); |
| 618 } |
| 619 |
| 620 // Tests that loading HTTP page updates the SSLStatus. |
| 621 TEST_F(CRWWebStateSecurityStateTest, LoadHttpPage) { |
| 622 web::TestWebStateObserver observer(web_state()); |
| 623 ASSERT_FALSE(observer.did_change_visible_security_state_info()); |
| 624 LoadHtml(@"<html><body></body></html>", GURL("http://chromium.test")); |
| 625 web::NavigationManager* nav_manager = web_state()->GetNavigationManager(); |
| 626 web::NavigationItem* item = nav_manager->GetLastCommittedItem(); |
| 627 EXPECT_EQ(web::SECURITY_STYLE_UNAUTHENTICATED, item->GetSSL().security_style); |
| 628 ASSERT_TRUE(observer.did_change_visible_security_state_info()); |
| 629 EXPECT_EQ(web_state(), |
| 630 observer.did_change_visible_security_state_info()->web_state); |
| 599 } | 631 } |
| 600 | 632 |
| 601 // Real WKWebView is required for CRWWebControllerInvalidUrlTest. | 633 // Real WKWebView is required for CRWWebControllerInvalidUrlTest. |
| 602 typedef web::WebTestWithWebState CRWWebControllerInvalidUrlTest; | 634 typedef web::WebTestWithWebState CRWWebControllerInvalidUrlTest; |
| 603 | 635 |
| 604 // Tests that web controller navigates to about:blank if invalid URL is loaded. | 636 // Tests that web controller navigates to about:blank if invalid URL is loaded. |
| 605 TEST_F(CRWWebControllerInvalidUrlTest, LoadInvalidURL) { | 637 TEST_F(CRWWebControllerInvalidUrlTest, LoadInvalidURL) { |
| 606 GURL url(kInvalidURL); | 638 GURL url(kInvalidURL); |
| 607 ASSERT_FALSE(url.is_valid()); | 639 ASSERT_FALSE(url.is_valid()); |
| 608 LoadHtml(@"<html><body></body></html>", url); | 640 LoadHtml(@"<html><body></body></html>", url); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 web::TestWebStateObserver* observer_ptr = &observer; | 955 web::TestWebStateObserver* observer_ptr = &observer; |
| 924 web::SimulateWKWebViewCrash(webView_); | 956 web::SimulateWKWebViewCrash(webView_); |
| 925 base::test::ios::WaitUntilCondition(^bool() { | 957 base::test::ios::WaitUntilCondition(^bool() { |
| 926 return observer_ptr->render_process_gone_info(); | 958 return observer_ptr->render_process_gone_info(); |
| 927 }); | 959 }); |
| 928 EXPECT_EQ(web_state(), observer.render_process_gone_info()->web_state); | 960 EXPECT_EQ(web_state(), observer.render_process_gone_info()->web_state); |
| 929 EXPECT_FALSE([web_controller() isViewAlive]); | 961 EXPECT_FALSE([web_controller() isViewAlive]); |
| 930 }; | 962 }; |
| 931 | 963 |
| 932 } // namespace | 964 } // namespace |
| OLD | NEW |