#include <vector>
#include "base/containers/contains.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/history_test_utils.h"
#include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/location_bar/location_bar.h"
#include "chrome/browser/ui/omnibox/omnibox_tab_helper.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/error_page/common/net_error_info.h"
#include "components/metrics/content/subprocess_metrics_provider.h"
#include "components/omnibox/browser/omnibox_controller.h"
#include "components/omnibox/browser/omnibox_edit_model.h"
#include "components/omnibox/common/omnibox_features.h"
#include "components/security_interstitials/content/ssl_error_handler.h"
#include "components/security_interstitials/core/omnibox_https_upgrade_metrics.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/content_mock_cert_verifier.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/url_loader_interceptor.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/cert_test_util.h"
#include "net/test/test_data_directory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "services/network/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "typed_navigation_upgrade_throttle.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
Event;
kEventHistogram;
namespace {
const char* const kSiteWithHttp = …;
const char* const kSiteWithGoodHttps = …;
const char* const kSiteWithGoodHttpsRedirect = …;
const char* const kSiteWithBadHttps = …;
const char* const kSiteWithSlowHttps = …;
const char* const kSiteWithNetError = …;
const char* const kNonUniqueHostname1 = …;
const char* const kNonUniqueHostname2 = …;
const char* const kGoogleSearchHost = …;
const char kNetErrorHistogram[] = …;
enum class NavigationExpectation { … };
enum class UpgradeExpectation { … };
std::string GetURLWithoutScheme(const GURL& url) { … }
GURL MakeHttpsURL(const std::string& url_without_scheme) { … }
GURL MakeHttpURL(const std::string& url_without_scheme) { … }
GURL MakeURLWithPort(const std::string& url_without_scheme,
const std::string& scheme,
int port) { … }
GURL MakeHttpsURLWithPort(const std::string& url_without_scheme, int port) { … }
GURL MakeHttpURLWithPort(const std::string& url_without_scheme, int port) { … }
void SetClipboardText(const std::u16string& text) { … }
}
class TypedNavigationUpgradeThrottleBrowserTest
: public InProcessBrowserTest,
public testing::WithParamInterface<bool > { … };
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(TypedNavigationUpgradeThrottleBrowserTest,
UrlTypedWithHttpScheme_ShouldNotUpgrade) { … }
IN_PROC_BROWSER_TEST_P(TypedNavigationUpgradeThrottleBrowserTest,
UrlTypedWithHttpsScheme_ShouldNotUpgrade) { … }
IN_PROC_BROWSER_TEST_P(TypedNavigationUpgradeThrottleBrowserTest,
UrlTypedWithHttpsScheme_BrokenSSL_ShouldNotUpgrade) { … }
IN_PROC_BROWSER_TEST_P(TypedNavigationUpgradeThrottleBrowserTest,
UrlTypedWithoutScheme_FeatureDisabled_ShouldNotUpgrade) { … }
IN_PROC_BROWSER_TEST_P(TypedNavigationUpgradeThrottleBrowserTest,
SearchQuery_ShouldNotUpgrade) { … }
IN_PROC_BROWSER_TEST_P(TypedNavigationUpgradeThrottleBrowserTest,
SearchQuery_TwoWords_ShouldNotUpgrade) { … }
IN_PROC_BROWSER_TEST_P(TypedNavigationUpgradeThrottleBrowserTest,
NonUniqueHostnameTypedWithoutScheme_ShouldNotUpgrade) { … }
IN_PROC_BROWSER_TEST_P(TypedNavigationUpgradeThrottleBrowserTest,
IPAddressTypedWithoutScheme_ShouldNotUpgrade) { … }
IN_PROC_BROWSER_TEST_P(TypedNavigationUpgradeThrottleBrowserTest,
UrlTypedWithoutScheme_GoodHttps) { … }
IN_PROC_BROWSER_TEST_P(TypedNavigationUpgradeThrottleBrowserTest,
UrlTypedWithScheme_CtrlEnter_HttpUrl_ShouldNotUpgrade) { … }
IN_PROC_BROWSER_TEST_P(TypedNavigationUpgradeThrottleBrowserTest,
UrlTypedWithScheme_CtrlEnter_HttpsUrl_ShouldNotUpgrade) { … }
IN_PROC_BROWSER_TEST_P(TypedNavigationUpgradeThrottleBrowserTest,
UrlTypedWithoutScheme_CtrlEnter_GoodHttps) { … }
IN_PROC_BROWSER_TEST_P(TypedNavigationUpgradeThrottleBrowserTest,
PasteUrlWithoutASchemeAndHitEnter_GoodHttps) { … }
IN_PROC_BROWSER_TEST_P(
TypedNavigationUpgradeThrottleBrowserTest,
PasteUrlWithoutASchemeAndHitEnter_BadHttps_ShouldFallback) { … }
IN_PROC_BROWSER_TEST_P(TypedNavigationUpgradeThrottleBrowserTest,
PasteAndGoUrlWithoutAScheme_GoodHttps) { … }
IN_PROC_BROWSER_TEST_P(TypedNavigationUpgradeThrottleBrowserTest,
UrlTypedWithoutScheme_BadHttps_ShouldFallback) { … }
IN_PROC_BROWSER_TEST_P(
TypedNavigationUpgradeThrottleBrowserTest,
UrlTypedWithoutScheme_CtrlEnter_BadHttps_ShouldFallback) { … }
IN_PROC_BROWSER_TEST_P(TypedNavigationUpgradeThrottleBrowserTest,
UrlTypedWithoutScheme_NetError_ShouldFallback) { … }
class TypedNavigationUpgradeThrottleFastTimeoutBrowserTest
: public TypedNavigationUpgradeThrottleBrowserTest { … };
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(TypedNavigationUpgradeThrottleFastTimeoutBrowserTest,
UrlTypedWithoutScheme_SlowHttps_ShouldFallback) { … }
class TypedNavigationUpgradeThrottleRedirectBrowserTest
: public TypedNavigationUpgradeThrottleBrowserTest { … };
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(
TypedNavigationUpgradeThrottleRedirectBrowserTest,
UrlTypedWithoutScheme_GoodHttps_Redirected_ShouldUpgrade) { … }
IN_PROC_BROWSER_TEST_P(
TypedNavigationUpgradeThrottleRedirectBrowserTest,
UrlTypedWithoutScheme_BadHttps_Redirected_ShouldFallback) { … }
IN_PROC_BROWSER_TEST_P(
TypedNavigationUpgradeThrottleRedirectBrowserTest,
UrlTypedWithoutScheme_NetError_Redirected_ShouldFallback) { … }