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 |
35 void FinishProbe(DnsProbeStatus status) { | 36 void FinishProbe(DnsProbeStatus status) { |
36 EXPECT_TRUE(mock_probe_running_); | 37 EXPECT_TRUE(mock_probe_running_); |
37 OnDnsProbeFinished(status); | 38 OnDnsProbeFinished(status); |
38 mock_probe_running_ = false; | 39 mock_probe_running_ = false; |
39 } | 40 } |
40 | 41 |
41 bool mock_probe_running() const { return mock_probe_running_; } | 42 bool mock_probe_running() const { return mock_probe_running_; } |
42 DnsProbeStatus last_status_sent() const { return last_status_sent_; } | 43 DnsProbeStatus last_status_sent() const { return last_status_sent_; } |
43 int mock_sent_count() const { return mock_sent_count_; } | 44 int mock_sent_count() const { return mock_sent_count_; } |
44 | 45 |
45 #if BUILDFLAG(ANDROID_JAVA_UI) | 46 #if defined(OS_ANDROID) |
46 using NetErrorTabHelper::DownloadPageLater; | 47 using NetErrorTabHelper::DownloadPageLater; |
47 | 48 |
48 const GURL& download_page_later_url() const { | 49 const GURL& download_page_later_url() const { |
49 return download_page_later_url_; | 50 return download_page_later_url_; |
50 } | 51 } |
51 | 52 |
52 int times_download_page_later_invoked() const { | 53 int times_download_page_later_invoked() const { |
53 return times_download_page_later_invoked_; | 54 return times_download_page_later_invoked_; |
54 } | 55 } |
55 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 56 #endif // defined(OS_ANDROID) |
56 | 57 |
57 const std::string& network_diagnostics_url() const { | 58 const std::string& network_diagnostics_url() const { |
58 return network_diagnostics_url_; | 59 return network_diagnostics_url_; |
59 } | 60 } |
60 | 61 |
61 int times_diagnostics_dialog_invoked() const { | 62 int times_diagnostics_dialog_invoked() const { |
62 return times_diagnostics_dialog_invoked_; | 63 return times_diagnostics_dialog_invoked_; |
63 } | 64 } |
64 | 65 |
65 void SetCurrentTargetFrame(content::RenderFrameHost* render_frame_host) { | 66 void SetCurrentTargetFrame(content::RenderFrameHost* render_frame_host) { |
(...skipping 16 matching lines...) Expand all Loading... |
82 void SendInfo() override { | 83 void SendInfo() override { |
83 last_status_sent_ = dns_probe_status(); | 84 last_status_sent_ = dns_probe_status(); |
84 mock_sent_count_++; | 85 mock_sent_count_++; |
85 } | 86 } |
86 | 87 |
87 void RunNetworkDiagnosticsHelper(const std::string& sanitized_url) override { | 88 void RunNetworkDiagnosticsHelper(const std::string& sanitized_url) override { |
88 network_diagnostics_url_ = sanitized_url; | 89 network_diagnostics_url_ = sanitized_url; |
89 times_diagnostics_dialog_invoked_++; | 90 times_diagnostics_dialog_invoked_++; |
90 } | 91 } |
91 | 92 |
92 #if BUILDFLAG(ANDROID_JAVA_UI) | 93 #if defined(OS_ANDROID) |
93 void DownloadPageLaterHelper(const GURL& url) override { | 94 void DownloadPageLaterHelper(const GURL& url) override { |
94 download_page_later_url_ = url; | 95 download_page_later_url_ = url; |
95 times_download_page_later_invoked_++; | 96 times_download_page_later_invoked_++; |
96 } | 97 } |
97 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 98 #endif // defined(OS_ANDROID) |
98 | 99 |
99 bool mock_probe_running_; | 100 bool mock_probe_running_; |
100 DnsProbeStatus last_status_sent_; | 101 DnsProbeStatus last_status_sent_; |
101 int mock_sent_count_; | 102 int mock_sent_count_; |
102 #if BUILDFLAG(ANDROID_JAVA_UI) | 103 #if defined(OS_ANDROID) |
103 GURL download_page_later_url_; | 104 GURL download_page_later_url_; |
104 int times_download_page_later_invoked_; | 105 int times_download_page_later_invoked_; |
105 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 106 #endif // defined(OS_ANDROID) |
106 std::string network_diagnostics_url_; | 107 std::string network_diagnostics_url_; |
107 int times_diagnostics_dialog_invoked_; | 108 int times_diagnostics_dialog_invoked_; |
108 }; | 109 }; |
109 | 110 |
110 class NetErrorTabHelperTest : public ChromeRenderViewHostTestHarness { | 111 class NetErrorTabHelperTest : public ChromeRenderViewHostTestHarness { |
111 protected: | 112 protected: |
112 enum MainFrame { SUB_FRAME, MAIN_FRAME }; | 113 enum MainFrame { SUB_FRAME, MAIN_FRAME }; |
113 enum ErrorType { DNS_ERROR, OTHER_ERROR, NO_ERROR }; | 114 enum ErrorType { DNS_ERROR, OTHER_ERROR, NO_ERROR }; |
114 | 115 |
115 void SetUp() override { | 116 void SetUp() override { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 content::RenderFrameHostTester::For(main_rfh())-> | 163 content::RenderFrameHostTester::For(main_rfh())-> |
163 SimulateNavigationCommit(url); | 164 SimulateNavigationCommit(url); |
164 } else { | 165 } else { |
165 content::RenderFrameHostTester::For(main_rfh())-> | 166 content::RenderFrameHostTester::For(main_rfh())-> |
166 SimulateNavigationError(url, net::ERR_TIMED_OUT); | 167 SimulateNavigationError(url, net::ERR_TIMED_OUT); |
167 content::RenderFrameHostTester::For(main_rfh())-> | 168 content::RenderFrameHostTester::For(main_rfh())-> |
168 SimulateNavigationErrorPageCommit(); | 169 SimulateNavigationErrorPageCommit(); |
169 } | 170 } |
170 } | 171 } |
171 | 172 |
172 #if BUILDFLAG(ANDROID_JAVA_UI) | 173 #if defined(OS_ANDROID) |
173 void NoDownloadPageLaterForNonHttpSchemes(const char* url_string, | 174 void NoDownloadPageLaterForNonHttpSchemes(const char* url_string, |
174 bool succeeded) { | 175 bool succeeded) { |
175 GURL url(url_string); | 176 GURL url(url_string); |
176 LoadURL(url, succeeded); | 177 LoadURL(url, succeeded); |
177 tab_helper()->DownloadPageLater(); | 178 tab_helper()->DownloadPageLater(); |
178 EXPECT_EQ(0, tab_helper()->times_download_page_later_invoked()); | 179 EXPECT_EQ(0, tab_helper()->times_download_page_later_invoked()); |
179 } | 180 } |
180 #endif | 181 #endif |
181 | 182 |
182 bool probe_running() { return tab_helper_->mock_probe_running(); } | 183 bool probe_running() { return tab_helper_->mock_probe_running(); } |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 }; | 365 }; |
365 | 366 |
366 for (const char* url : kUrls) { | 367 for (const char* url : kUrls) { |
367 tab_helper()->SetCurrentTargetFrame(web_contents()->GetMainFrame()); | 368 tab_helper()->SetCurrentTargetFrame(web_contents()->GetMainFrame()); |
368 tab_helper()->network_diagnostics_interface() | 369 tab_helper()->network_diagnostics_interface() |
369 ->RunNetworkDiagnostics(GURL(url)); | 370 ->RunNetworkDiagnostics(GURL(url)); |
370 EXPECT_EQ(0, tab_helper()->times_diagnostics_dialog_invoked()); | 371 EXPECT_EQ(0, tab_helper()->times_diagnostics_dialog_invoked()); |
371 } | 372 } |
372 } | 373 } |
373 | 374 |
374 #if BUILDFLAG(ANDROID_JAVA_UI) | 375 #if defined(OS_ANDROID) |
375 TEST_F(NetErrorTabHelperTest, DownloadPageLater) { | 376 TEST_F(NetErrorTabHelperTest, DownloadPageLater) { |
376 GURL url("http://somewhere:123/"); | 377 GURL url("http://somewhere:123/"); |
377 LoadURL(url, false /*succeeded*/); | 378 LoadURL(url, false /*succeeded*/); |
378 tab_helper()->DownloadPageLater(); | 379 tab_helper()->DownloadPageLater(); |
379 EXPECT_EQ(url, tab_helper()->download_page_later_url()); | 380 EXPECT_EQ(url, tab_helper()->download_page_later_url()); |
380 EXPECT_EQ(1, tab_helper()->times_download_page_later_invoked()); | 381 EXPECT_EQ(1, tab_helper()->times_download_page_later_invoked()); |
381 } | 382 } |
382 | 383 |
383 TEST_F(NetErrorTabHelperTest, NoDownloadPageLaterOnNonErrorPage) { | 384 TEST_F(NetErrorTabHelperTest, NoDownloadPageLaterOnNonErrorPage) { |
384 GURL url("http://somewhere:123/"); | 385 GURL url("http://somewhere:123/"); |
(...skipping 14 matching lines...) Expand all Loading... |
399 TEST_F(NetErrorTabHelperTest, NoDownloadPageLaterForNonHttpSchemes2) { | 400 TEST_F(NetErrorTabHelperTest, NoDownloadPageLaterForNonHttpSchemes2) { |
400 NoDownloadPageLaterForNonHttpSchemes("chrome://blah/", false); | 401 NoDownloadPageLaterForNonHttpSchemes("chrome://blah/", false); |
401 } | 402 } |
402 | 403 |
403 TEST_F(NetErrorTabHelperTest, NoDownloadPageLaterForNonHttpSchemes3) { | 404 TEST_F(NetErrorTabHelperTest, NoDownloadPageLaterForNonHttpSchemes3) { |
404 // about:blank always succeeds, and the test harness won't handle URLs that | 405 // about:blank always succeeds, and the test harness won't handle URLs that |
405 // don't go to the network failing. | 406 // don't go to the network failing. |
406 NoDownloadPageLaterForNonHttpSchemes("about:blank", true); | 407 NoDownloadPageLaterForNonHttpSchemes("about:blank", true); |
407 } | 408 } |
408 | 409 |
409 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 410 #endif // defined(OS_ANDROID) |
OLD | NEW |