chromium/chrome/browser/net/net_error_tab_helper_unittest.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/net/net_error_tab_helper.h"

#include <memory>

#include "base/memory/raw_ptr.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "components/error_page/common/net_error_info.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/mock_navigation_handle.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/test_renderer_host.h"
#include "net/base/net_errors.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/page_transition_types.h"
#include "url/gurl.h"

#undef NO_ERROR  // Defined in winerror.h.

NetErrorTabHelper;
DnsProbeStatus;

class TestNetErrorTabHelper : public NetErrorTabHelper {};

class NetErrorTabHelperTest : public ChromeRenderViewHostTestHarness {};

TEST_F(NetErrorTabHelperTest, Null) {}

TEST_F(NetErrorTabHelperTest, MainFrameNonDnsError) {}

TEST_F(NetErrorTabHelperTest, NonMainFrameDnsError) {}

// Test complete DNS error page loads.  Note that the helper can see two error
// page loads: Link Doctor loads an empty HTML page so the user knows something
// is going on, then fails over to the normal error page if and when Link
// Doctor fails to load or declines to provide a page.

TEST_F(NetErrorTabHelperTest, ProbeResponse) {}

// Send result even if a new page load has started; the error page is still
// visible, and the user might cancel the load.
TEST_F(NetErrorTabHelperTest, ProbeResponseAfterNewStart) {}

// Don't send result if a new page has committed; the result would go to the
// wrong page, and the error page is gone anyway.
TEST_F(NetErrorTabHelperTest, ProbeResponseAfterNewCommit) {}

TEST_F(NetErrorTabHelperTest, MultipleDnsErrorsWithProbesWithoutErrorPages) {}

TEST_F(NetErrorTabHelperTest, MultipleDnsErrorsWithProbesAndErrorPages) {}

// If multiple DNS errors occur in a row before a probe result, don't start
// multiple probes.
TEST_F(NetErrorTabHelperTest, CoalesceFailures) {}

// Makes sure that URLs are sanitized before running the platform network
// diagnostics tool.
TEST_F(NetErrorTabHelperTest, SanitizeDiagnosticsUrl) {}

// Makes sure that diagnostics aren't run on invalid URLs or URLs with
// non-HTTP/HTTPS schemes.
TEST_F(NetErrorTabHelperTest, NoDiagnosticsForNonHttpSchemes) {}

#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
TEST_F(NetErrorTabHelperTest, DownloadPageLater) {
  GURL url("http://somewhere:123/");
  LoadURL(url, false /*succeeded*/);
  tab_helper()->DownloadPageLater();
  EXPECT_EQ(url, tab_helper()->download_page_later_url());
  EXPECT_EQ(1, tab_helper()->times_download_page_later_invoked());
}

TEST_F(NetErrorTabHelperTest, NoDownloadPageLaterOnNonErrorPage) {
  GURL url("http://somewhere:123/");
  LoadURL(url, true /*succeeded*/);
  tab_helper()->DownloadPageLater();
  EXPECT_EQ(0, tab_helper()->times_download_page_later_invoked());
}

// Makes sure that "Download page later" isn't run on URLs with non-HTTP/HTTPS
// schemes.
// NOTE: the test harness code in this file and in TestRendererHost don't always
// deal with pending RFH correctly. This works because most tests only load
// once. So workaround it by puting each test case in a separate test.
TEST_F(NetErrorTabHelperTest, NoDownloadPageLaterForNonHttpSchemes1) {
  NoDownloadPageLaterForNonHttpSchemes("file:///blah/blah", false);
}

TEST_F(NetErrorTabHelperTest, NoDownloadPageLaterForNonHttpSchemes2) {
  NoDownloadPageLaterForNonHttpSchemes("chrome://blah/", false);
}

TEST_F(NetErrorTabHelperTest, NoDownloadPageLaterForNonHttpSchemes3) {
  // about:blank always succeeds, and the test harness won't handle URLs that
  // don't go to the network failing.
  NoDownloadPageLaterForNonHttpSchemes("about:blank", true);
}

#endif  // BUILDFLAG(ENABLE_OFFLINE_PAGES)