| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" | 5 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "chrome/browser/captive_portal/captive_portal_service.h" | 11 #include "chrome/browser/captive_portal/captive_portal_service.h" |
| 12 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" | 12 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 15 #include "content/public/browser/notification_details.h" | 15 #include "content/public/browser/notification_details.h" |
| 16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
| 18 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
| 19 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| 20 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/common/browser_side_navigation_policy.h" | 22 #include "content/public/common/browser_side_navigation_policy.h" |
| 23 #include "content/public/test/test_renderer_host.h" | 23 #include "content/public/test/test_renderer_host.h" |
| 24 #include "content/public/test/test_utils.h" |
| 24 #include "content/public/test/web_contents_tester.h" | 25 #include "content/public/test/web_contents_tester.h" |
| 25 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 29 |
| 29 using captive_portal::CaptivePortalResult; | 30 using captive_portal::CaptivePortalResult; |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 const char* const kStartUrl = "http://whatever.com/index.html"; | 34 const char* const kStartUrl = "http://whatever.com/index.html"; |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 content::RenderFrameHostTester::For(subframe3); | 374 content::RenderFrameHostTester::For(subframe3); |
| 374 subframe_tester3->SimulateNavigationStart(url); | 375 subframe_tester3->SimulateNavigationStart(url); |
| 375 subframe_tester3->SimulateNavigationError(url, net::ERR_ABORTED); | 376 subframe_tester3->SimulateNavigationError(url, net::ERR_ABORTED); |
| 376 subframe_tester3->SimulateNavigationStop(); | 377 subframe_tester3->SimulateNavigationStop(); |
| 377 } | 378 } |
| 378 | 379 |
| 379 // Simulates a subframe erroring out at the same time as a provisional load, | 380 // Simulates a subframe erroring out at the same time as a provisional load, |
| 380 // but with a different error code. Make sure the TabHelper sees the correct | 381 // but with a different error code. Make sure the TabHelper sees the correct |
| 381 // error. | 382 // error. |
| 382 TEST_F(CaptivePortalTabHelperTest, HttpsSubframeParallelError) { | 383 TEST_F(CaptivePortalTabHelperTest, HttpsSubframeParallelError) { |
| 384 if (content::IsBrowserSideNavigationEnabled() && |
| 385 content::AreAllSitesIsolatedForTesting()) { |
| 386 // http://crbug.com/674734 Fix this test with PlzNavigate and Site Isolation |
| 387 return; |
| 388 } |
| 383 // URL used by both frames. | 389 // URL used by both frames. |
| 384 GURL url = GURL(kHttpsUrl); | 390 GURL url = GURL(kHttpsUrl); |
| 385 content::RenderFrameHostTester* rfh_tester = | 391 content::RenderFrameHostTester* rfh_tester = |
| 386 content::RenderFrameHostTester::For(main_rfh()); | 392 content::RenderFrameHostTester::For(main_rfh()); |
| 387 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe"); | 393 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe"); |
| 388 content::RenderFrameHostTester* subframe_tester = | 394 content::RenderFrameHostTester* subframe_tester = |
| 389 content::RenderFrameHostTester::For(subframe); | 395 content::RenderFrameHostTester::For(subframe); |
| 390 | 396 |
| 391 // Loads start. | 397 // Loads start. |
| 392 EXPECT_CALL(mock_reloader(), OnLoadStart(url.SchemeIsCryptographic())) | 398 EXPECT_CALL(mock_reloader(), OnLoadStart(url.SchemeIsCryptographic())) |
| 393 .Times(1); | 399 .Times(1); |
| 394 rfh_tester->SimulateNavigationStart(url); | 400 rfh_tester->SimulateNavigationStart(url); |
| 395 subframe_tester->SimulateNavigationStart(url); | 401 subframe_tester->SimulateNavigationStart(url); |
| 396 | 402 |
| 397 // Loads return errors. | 403 // Loads return errors. |
| 398 rfh_tester->SimulateNavigationError(url, net::ERR_UNEXPECTED); | 404 rfh_tester->SimulateNavigationError(url, net::ERR_UNEXPECTED); |
| 399 subframe_tester->SimulateNavigationError(url, net::ERR_TIMED_OUT); | 405 subframe_tester->SimulateNavigationError(url, net::ERR_TIMED_OUT); |
| 400 | 406 |
| 401 // Error page load finishes. | 407 // Error page load finishes. |
| 402 subframe_tester->SimulateNavigationErrorPageCommit(); | 408 subframe_tester->SimulateNavigationErrorPageCommit(); |
| 403 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::ERR_UNEXPECTED)).Times(1); | 409 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::ERR_UNEXPECTED)).Times(1); |
| 404 rfh_tester->SimulateNavigationErrorPageCommit(); | 410 rfh_tester->SimulateNavigationErrorPageCommit(); |
| 405 } | 411 } |
| 406 | 412 |
| 407 // Simulates an HTTP to HTTPS redirect, which then times out. | 413 // Simulates an HTTP to HTTPS redirect, which then times out. |
| 408 TEST_F(CaptivePortalTabHelperTest, HttpToHttpsRedirectTimeout) { | 414 TEST_F(CaptivePortalTabHelperTest, HttpToHttpsRedirectTimeout) { |
| 415 if (content::IsBrowserSideNavigationEnabled() && |
| 416 content::AreAllSitesIsolatedForTesting()) { |
| 417 // http://crbug.com/674734 Fix this test with PlzNavigate and Site Isolation |
| 418 return; |
| 419 } |
| 409 GURL http_url(kHttpUrl); | 420 GURL http_url(kHttpUrl); |
| 410 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1); | 421 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1); |
| 411 content::RenderFrameHostTester* rfh_tester = | 422 content::RenderFrameHostTester* rfh_tester = |
| 412 content::RenderFrameHostTester::For(main_rfh()); | 423 content::RenderFrameHostTester::For(main_rfh()); |
| 413 rfh_tester->SimulateNavigationStart(http_url); | 424 rfh_tester->SimulateNavigationStart(http_url); |
| 414 | 425 |
| 415 GURL https_url(kHttpsUrl); | 426 GURL https_url(kHttpsUrl); |
| 416 EXPECT_CALL(mock_reloader(), OnRedirect(true)).Times(1); | 427 EXPECT_CALL(mock_reloader(), OnRedirect(true)).Times(1); |
| 417 rfh_tester->SimulateRedirect(https_url); | 428 rfh_tester->SimulateRedirect(https_url); |
| 418 | 429 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 EXPECT_FALSE(tab_helper()->IsLoginTab()); | 537 EXPECT_FALSE(tab_helper()->IsLoginTab()); |
| 527 | 538 |
| 528 ObservePortalResult(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, | 539 ObservePortalResult(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
| 529 captive_portal::RESULT_NO_RESPONSE); | 540 captive_portal::RESULT_NO_RESPONSE); |
| 530 EXPECT_FALSE(tab_helper()->IsLoginTab()); | 541 EXPECT_FALSE(tab_helper()->IsLoginTab()); |
| 531 | 542 |
| 532 ObservePortalResult(captive_portal::RESULT_NO_RESPONSE, | 543 ObservePortalResult(captive_portal::RESULT_NO_RESPONSE, |
| 533 captive_portal::RESULT_INTERNET_CONNECTED); | 544 captive_portal::RESULT_INTERNET_CONNECTED); |
| 534 EXPECT_FALSE(tab_helper()->IsLoginTab()); | 545 EXPECT_FALSE(tab_helper()->IsLoginTab()); |
| 535 } | 546 } |
| OLD | NEW |