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