| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/net/net_error_tab_helper.h" | 5 #include "chrome/browser/net/net_error_tab_helper.h" |
| 6 | 6 |
| 7 #include "chrome/common/render_messages.h" | 7 #include "chrome/common/render_messages.h" |
| 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 9 #include "components/error_page/common/net_error_info.h" | 9 #include "components/error_page/common/net_error_info.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/navigation_handle.h" | 11 #include "content/public/browser/navigation_handle.h" |
| 12 #include "content/public/test/test_renderer_host.h" | 12 #include "content/public/test/test_renderer_host.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/base/page_transition_types.h" | 15 #include "ui/base/page_transition_types.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 #undef NO_ERROR // Defined in winerror.h. | 18 #undef NO_ERROR // Defined in winerror.h. |
| 19 | 19 |
| 20 using chrome_browser_net::NetErrorTabHelper; | 20 using chrome_browser_net::NetErrorTabHelper; |
| 21 using error_page::DnsProbeStatus; | 21 using error_page::DnsProbeStatus; |
| 22 | 22 |
| 23 class TestNetErrorTabHelper : public NetErrorTabHelper { | 23 class TestNetErrorTabHelper : public NetErrorTabHelper { |
| 24 public: | 24 public: |
| 25 explicit TestNetErrorTabHelper(content::WebContents* web_contents) | 25 explicit TestNetErrorTabHelper(content::WebContents* web_contents) |
| 26 : NetErrorTabHelper(web_contents), | 26 : NetErrorTabHelper(web_contents), |
| 27 mock_probe_running_(false), | 27 mock_probe_running_(false), |
| 28 last_status_sent_(error_page::DNS_PROBE_MAX), | 28 last_status_sent_(error_page::DNS_PROBE_MAX), |
| 29 mock_sent_count_(0), | 29 mock_sent_count_(0), |
| 30 #if BUILDFLAG(ANDROID_JAVA_UI) | 30 #if defined(OS_ANDROID) |
| 31 times_download_page_later_invoked_(0), | 31 times_download_page_later_invoked_(0), |
| 32 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 32 #endif // defined(OS_ANDROID) |
| 33 times_diagnostics_dialog_invoked_(0) {} | 33 times_diagnostics_dialog_invoked_(0) {} |
| 34 | 34 |
| 35 void FinishProbe(DnsProbeStatus status) { | 35 void FinishProbe(DnsProbeStatus status) { |
| 36 EXPECT_TRUE(mock_probe_running_); | 36 EXPECT_TRUE(mock_probe_running_); |
| 37 OnDnsProbeFinished(status); | 37 OnDnsProbeFinished(status); |
| 38 mock_probe_running_ = false; | 38 mock_probe_running_ = false; |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool mock_probe_running() const { return mock_probe_running_; } | 41 bool mock_probe_running() const { return mock_probe_running_; } |
| 42 DnsProbeStatus last_status_sent() const { return last_status_sent_; } | 42 DnsProbeStatus last_status_sent() const { return last_status_sent_; } |
| 43 int mock_sent_count() const { return mock_sent_count_; } | 43 int mock_sent_count() const { return mock_sent_count_; } |
| 44 | 44 |
| 45 #if BUILDFLAG(ANDROID_JAVA_UI) | 45 #if defined(OS_ANDROID) |
| 46 using NetErrorTabHelper::DownloadPageLater; | 46 using NetErrorTabHelper::DownloadPageLater; |
| 47 | 47 |
| 48 const GURL& download_page_later_url() const { | 48 const GURL& download_page_later_url() const { |
| 49 return download_page_later_url_; | 49 return download_page_later_url_; |
| 50 } | 50 } |
| 51 | 51 |
| 52 int times_download_page_later_invoked() const { | 52 int times_download_page_later_invoked() const { |
| 53 return times_download_page_later_invoked_; | 53 return times_download_page_later_invoked_; |
| 54 } | 54 } |
| 55 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 55 #endif // defined(OS_ANDROID) |
| 56 | 56 |
| 57 const std::string& network_diagnostics_url() const { | 57 const std::string& network_diagnostics_url() const { |
| 58 return network_diagnostics_url_; | 58 return network_diagnostics_url_; |
| 59 } | 59 } |
| 60 | 60 |
| 61 int times_diagnostics_dialog_invoked() const { | 61 int times_diagnostics_dialog_invoked() const { |
| 62 return times_diagnostics_dialog_invoked_; | 62 return times_diagnostics_dialog_invoked_; |
| 63 } | 63 } |
| 64 | 64 |
| 65 void SetCurrentTargetFrame(content::RenderFrameHost* render_frame_host) { | 65 void SetCurrentTargetFrame(content::RenderFrameHost* render_frame_host) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 82 void SendInfo() override { | 82 void SendInfo() override { |
| 83 last_status_sent_ = dns_probe_status(); | 83 last_status_sent_ = dns_probe_status(); |
| 84 mock_sent_count_++; | 84 mock_sent_count_++; |
| 85 } | 85 } |
| 86 | 86 |
| 87 void RunNetworkDiagnosticsHelper(const std::string& sanitized_url) override { | 87 void RunNetworkDiagnosticsHelper(const std::string& sanitized_url) override { |
| 88 network_diagnostics_url_ = sanitized_url; | 88 network_diagnostics_url_ = sanitized_url; |
| 89 times_diagnostics_dialog_invoked_++; | 89 times_diagnostics_dialog_invoked_++; |
| 90 } | 90 } |
| 91 | 91 |
| 92 #if BUILDFLAG(ANDROID_JAVA_UI) | 92 #if defined(OS_ANDROID) |
| 93 void DownloadPageLaterHelper(const GURL& url) override { | 93 void DownloadPageLaterHelper(const GURL& url) override { |
| 94 download_page_later_url_ = url; | 94 download_page_later_url_ = url; |
| 95 times_download_page_later_invoked_++; | 95 times_download_page_later_invoked_++; |
| 96 } | 96 } |
| 97 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 97 #endif // defined(OS_ANDROID) |
| 98 | 98 |
| 99 bool mock_probe_running_; | 99 bool mock_probe_running_; |
| 100 DnsProbeStatus last_status_sent_; | 100 DnsProbeStatus last_status_sent_; |
| 101 int mock_sent_count_; | 101 int mock_sent_count_; |
| 102 #if BUILDFLAG(ANDROID_JAVA_UI) | 102 #if defined(OS_ANDROID) |
| 103 GURL download_page_later_url_; | 103 GURL download_page_later_url_; |
| 104 int times_download_page_later_invoked_; | 104 int times_download_page_later_invoked_; |
| 105 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 105 #endif // defined(OS_ANDROID) |
| 106 std::string network_diagnostics_url_; | 106 std::string network_diagnostics_url_; |
| 107 int times_diagnostics_dialog_invoked_; | 107 int times_diagnostics_dialog_invoked_; |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 class NetErrorTabHelperTest : public ChromeRenderViewHostTestHarness { | 110 class NetErrorTabHelperTest : public ChromeRenderViewHostTestHarness { |
| 111 protected: | 111 protected: |
| 112 enum MainFrame { SUB_FRAME, MAIN_FRAME }; | 112 enum MainFrame { SUB_FRAME, MAIN_FRAME }; |
| 113 enum ErrorType { DNS_ERROR, OTHER_ERROR, NO_ERROR }; | 113 enum ErrorType { DNS_ERROR, OTHER_ERROR, NO_ERROR }; |
| 114 | 114 |
| 115 void SetUp() override { | 115 void SetUp() override { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 content::RenderFrameHostTester::For(main_rfh())-> | 162 content::RenderFrameHostTester::For(main_rfh())-> |
| 163 SimulateNavigationCommit(url); | 163 SimulateNavigationCommit(url); |
| 164 } else { | 164 } else { |
| 165 content::RenderFrameHostTester::For(main_rfh())-> | 165 content::RenderFrameHostTester::For(main_rfh())-> |
| 166 SimulateNavigationError(url, net::ERR_TIMED_OUT); | 166 SimulateNavigationError(url, net::ERR_TIMED_OUT); |
| 167 content::RenderFrameHostTester::For(main_rfh())-> | 167 content::RenderFrameHostTester::For(main_rfh())-> |
| 168 SimulateNavigationErrorPageCommit(); | 168 SimulateNavigationErrorPageCommit(); |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 | 171 |
| 172 #if BUILDFLAG(ANDROID_JAVA_UI) | 172 #if defined(OS_ANDROID) |
| 173 void NoDownloadPageLaterForNonHttpSchemes(const char* url_string, | 173 void NoDownloadPageLaterForNonHttpSchemes(const char* url_string, |
| 174 bool succeeded) { | 174 bool succeeded) { |
| 175 GURL url(url_string); | 175 GURL url(url_string); |
| 176 LoadURL(url, succeeded); | 176 LoadURL(url, succeeded); |
| 177 tab_helper()->DownloadPageLater(); | 177 tab_helper()->DownloadPageLater(); |
| 178 EXPECT_EQ(0, tab_helper()->times_download_page_later_invoked()); | 178 EXPECT_EQ(0, tab_helper()->times_download_page_later_invoked()); |
| 179 } | 179 } |
| 180 #endif | 180 #endif |
| 181 | 181 |
| 182 bool probe_running() { return tab_helper_->mock_probe_running(); } | 182 bool probe_running() { return tab_helper_->mock_probe_running(); } |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 }; | 364 }; |
| 365 | 365 |
| 366 for (const char* url : kUrls) { | 366 for (const char* url : kUrls) { |
| 367 tab_helper()->SetCurrentTargetFrame(web_contents()->GetMainFrame()); | 367 tab_helper()->SetCurrentTargetFrame(web_contents()->GetMainFrame()); |
| 368 tab_helper()->network_diagnostics_interface() | 368 tab_helper()->network_diagnostics_interface() |
| 369 ->RunNetworkDiagnostics(GURL(url)); | 369 ->RunNetworkDiagnostics(GURL(url)); |
| 370 EXPECT_EQ(0, tab_helper()->times_diagnostics_dialog_invoked()); | 370 EXPECT_EQ(0, tab_helper()->times_diagnostics_dialog_invoked()); |
| 371 } | 371 } |
| 372 } | 372 } |
| 373 | 373 |
| 374 #if BUILDFLAG(ANDROID_JAVA_UI) | 374 #if defined(OS_ANDROID) |
| 375 TEST_F(NetErrorTabHelperTest, DownloadPageLater) { | 375 TEST_F(NetErrorTabHelperTest, DownloadPageLater) { |
| 376 GURL url("http://somewhere:123/"); | 376 GURL url("http://somewhere:123/"); |
| 377 LoadURL(url, false /*succeeded*/); | 377 LoadURL(url, false /*succeeded*/); |
| 378 tab_helper()->DownloadPageLater(); | 378 tab_helper()->DownloadPageLater(); |
| 379 EXPECT_EQ(url, tab_helper()->download_page_later_url()); | 379 EXPECT_EQ(url, tab_helper()->download_page_later_url()); |
| 380 EXPECT_EQ(1, tab_helper()->times_download_page_later_invoked()); | 380 EXPECT_EQ(1, tab_helper()->times_download_page_later_invoked()); |
| 381 } | 381 } |
| 382 | 382 |
| 383 TEST_F(NetErrorTabHelperTest, NoDownloadPageLaterOnNonErrorPage) { | 383 TEST_F(NetErrorTabHelperTest, NoDownloadPageLaterOnNonErrorPage) { |
| 384 GURL url("http://somewhere:123/"); | 384 GURL url("http://somewhere:123/"); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 399 TEST_F(NetErrorTabHelperTest, NoDownloadPageLaterForNonHttpSchemes2) { | 399 TEST_F(NetErrorTabHelperTest, NoDownloadPageLaterForNonHttpSchemes2) { |
| 400 NoDownloadPageLaterForNonHttpSchemes("chrome://blah/", false); | 400 NoDownloadPageLaterForNonHttpSchemes("chrome://blah/", false); |
| 401 } | 401 } |
| 402 | 402 |
| 403 TEST_F(NetErrorTabHelperTest, NoDownloadPageLaterForNonHttpSchemes3) { | 403 TEST_F(NetErrorTabHelperTest, NoDownloadPageLaterForNonHttpSchemes3) { |
| 404 // about:blank always succeeds, and the test harness won't handle URLs that | 404 // about:blank always succeeds, and the test harness won't handle URLs that |
| 405 // don't go to the network failing. | 405 // don't go to the network failing. |
| 406 NoDownloadPageLaterForNonHttpSchemes("about:blank", true); | 406 NoDownloadPageLaterForNonHttpSchemes("about:blank", true); |
| 407 } | 407 } |
| 408 | 408 |
| 409 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 409 #endif // defined(OS_ANDROID) |
| OLD | NEW |