| 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" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 int mock_sent_count() const { return mock_sent_count_; } | 36 int mock_sent_count() const { return mock_sent_count_; } |
| 37 | 37 |
| 38 const std::string& network_diagnostics_url() const { | 38 const std::string& network_diagnostics_url() const { |
| 39 return network_diagnostics_url_; | 39 return network_diagnostics_url_; |
| 40 } | 40 } |
| 41 | 41 |
| 42 int times_diagnostics_dialog_invoked() const { | 42 int times_diagnostics_dialog_invoked() const { |
| 43 return times_diagnostics_dialog_invoked_; | 43 return times_diagnostics_dialog_invoked_; |
| 44 } | 44 } |
| 45 | 45 |
| 46 void SetCurrentTargetFrame(content::RenderFrameHost* render_frame_host) { |
| 47 network_diagnostics_bindings_for_testing().SetCurrentTargetFrameForTesting( |
| 48 render_frame_host); |
| 49 } |
| 50 |
| 51 mojom::NetworkDiagnostics* network_diagnostics_interface() { return this; } |
| 52 |
| 46 private: | 53 private: |
| 47 // NetErrorTabHelper implementation: | 54 // NetErrorTabHelper implementation: |
| 48 | 55 |
| 49 void StartDnsProbe() override { | 56 void StartDnsProbe() override { |
| 50 EXPECT_FALSE(mock_probe_running_); | 57 EXPECT_FALSE(mock_probe_running_); |
| 51 mock_probe_running_ = true; | 58 mock_probe_running_ = true; |
| 52 } | 59 } |
| 53 | 60 |
| 54 void SendInfo() override { | 61 void SendInfo() override { |
| 55 last_status_sent_ = dns_probe_status(); | 62 last_status_sent_ = dns_probe_status(); |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 | 420 |
| 414 FinishProbe(error_page::DNS_PROBE_FINISHED_NXDOMAIN); | 421 FinishProbe(error_page::DNS_PROBE_FINISHED_NXDOMAIN); |
| 415 EXPECT_FALSE(probe_running()); | 422 EXPECT_FALSE(probe_running()); |
| 416 EXPECT_EQ(4, sent_count()); | 423 EXPECT_EQ(4, sent_count()); |
| 417 EXPECT_EQ(error_page::DNS_PROBE_FINISHED_NXDOMAIN, last_status_sent()); | 424 EXPECT_EQ(error_page::DNS_PROBE_FINISHED_NXDOMAIN, last_status_sent()); |
| 418 } | 425 } |
| 419 | 426 |
| 420 // Makes sure that URLs are sanitized before running the platform network | 427 // Makes sure that URLs are sanitized before running the platform network |
| 421 // diagnostics tool. | 428 // diagnostics tool. |
| 422 TEST_F(NetErrorTabHelperTest, SanitizeDiagnosticsUrl) { | 429 TEST_F(NetErrorTabHelperTest, SanitizeDiagnosticsUrl) { |
| 423 content::RenderFrameHost* rfh = web_contents()->GetMainFrame(); | 430 tab_helper()->SetCurrentTargetFrame(web_contents()->GetMainFrame()); |
| 424 rfh->OnMessageReceived(ChromeViewHostMsg_RunNetworkDiagnostics( | 431 tab_helper()->network_diagnostics_interface()->RunNetworkDiagnostics( |
| 425 rfh->GetRoutingID(), | 432 GURL("http://foo:bar@somewhere:123/hats?for#goats")); |
| 426 GURL("http://foo:bar@somewhere:123/hats?for#goats"))); | |
| 427 EXPECT_EQ("http://somewhere:123/", | 433 EXPECT_EQ("http://somewhere:123/", |
| 428 tab_helper()->network_diagnostics_url()); | 434 tab_helper()->network_diagnostics_url()); |
| 429 EXPECT_EQ(1, tab_helper()->times_diagnostics_dialog_invoked()); | 435 EXPECT_EQ(1, tab_helper()->times_diagnostics_dialog_invoked()); |
| 430 } | 436 } |
| 431 | 437 |
| 432 // Makes sure that diagnostics aren't run on invalid URLs or URLs with | 438 // Makes sure that diagnostics aren't run on invalid URLs or URLs with |
| 433 // non-HTTP/HTTPS schemes. | 439 // non-HTTP/HTTPS schemes. |
| 434 TEST_F(NetErrorTabHelperTest, NoDiagnosticsForNonHttpSchemes) { | 440 TEST_F(NetErrorTabHelperTest, NoDiagnosticsForNonHttpSchemes) { |
| 435 const char* kUrls[] = { | 441 const char* kUrls[] = { |
| 436 "", | 442 "", |
| 437 "http", | 443 "http", |
| 438 "file:///blah/blah", | 444 "file:///blah/blah", |
| 439 "chrome://blah/", | 445 "chrome://blah/", |
| 440 "about:blank", | 446 "about:blank", |
| 441 "file://foo/bar", | 447 "file://foo/bar", |
| 442 }; | 448 }; |
| 443 | 449 |
| 444 for (const char* url : kUrls) { | 450 for (const char* url : kUrls) { |
| 445 content::RenderFrameHost* rfh = web_contents()->GetMainFrame(); | 451 tab_helper()->SetCurrentTargetFrame(web_contents()->GetMainFrame()); |
| 446 rfh->OnMessageReceived(ChromeViewHostMsg_RunNetworkDiagnostics( | 452 tab_helper()->network_diagnostics_interface() |
| 447 rfh->GetRoutingID(), GURL(url))); | 453 ->RunNetworkDiagnostics(GURL(url)); |
| 448 EXPECT_EQ(0, tab_helper()->times_diagnostics_dialog_invoked()); | 454 EXPECT_EQ(0, tab_helper()->times_diagnostics_dialog_invoked()); |
| 449 } | 455 } |
| 450 } | 456 } |
| OLD | NEW |