// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "components/captive_portal/content/captive_portal_tab_reloader.h" #include <memory> #include "base/functional/callback.h" #include "base/functional/callback_helpers.h" #include "base/run_loop.h" #include "components/captive_portal/content/captive_portal_service.h" #include "content/public/browser/web_contents.h" #include "content/public/test/test_renderer_host.h" #include "net/base/net_errors.h" #include "net/cert/cert_status_flags.h" #include "net/ssl/ssl_info.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" namespace captive_portal { // Used for testing CaptivePortalTabReloader in isolation from the observer. // Exposes a number of private functions and mocks out others. class TestCaptivePortalTabReloader : public CaptivePortalTabReloader { … }; class CaptivePortalTabReloaderTest : public content::RenderViewHostTestHarness { … }; // Simulates a slow SSL load when the Internet is connected. TEST_F(CaptivePortalTabReloaderTest, InternetConnected) { … } // Simulates a slow SSL load when the Internet is connected. In this case, // the timeout error occurs before the timer triggers. Unlikely to happen // in practice, but best if it still works. TEST_F(CaptivePortalTabReloaderTest, InternetConnectedTimeout) { … } // Simulates a slow SSL load when captive portal checks return no response. TEST_F(CaptivePortalTabReloaderTest, NoResponse) { … } // Simulates a slow HTTP load when behind a captive portal, that eventually. // times out. Since it's HTTP, the TabReloader should do nothing. TEST_F(CaptivePortalTabReloaderTest, DoesNothingOnHttp) { … } // Simulate the normal login process. The user logs in before the error page // in the original tab commits. TEST_F(CaptivePortalTabReloaderTest, Login) { … } // Simulate the normal login process. The user logs in after the tab finishes // loading the error page. TEST_F(CaptivePortalTabReloaderTest, LoginLate) { … } // Simulate a login after the tab times out unexpectedly quickly. TEST_F(CaptivePortalTabReloaderTest, TimeoutFast) { … } // The secure DNS config is misconfigured. A secure DNS network error on a // HTTP navigation triggers a captive portal probe. The probe does not find // a captive portal. TEST_F(CaptivePortalTabReloaderTest, HttpBadSecureDnsConfig) { … } // The secure DNS config is misconfigured. A secure DNS network error on a // HTTPS navigation triggers a captive portal probe before the SSL timer // triggers. The probe does not find a captive portal. TEST_F(CaptivePortalTabReloaderTest, HttpsBadSecureDnsConfigPageLoadsBeforeTimerTriggers) { … } // The secure DNS config is misconfigured. The SSL timer triggers a captive // portal probe, which does not complete before the page loads with a secure // DNS network error. The probe does not find a captive portal. TEST_F(CaptivePortalTabReloaderTest, HttpsBadSecureDnsConfigPageLoadsBeforeTimerTriggeredResults) { … } // The secure DNS config is misconfigured. The SSL timer triggers a captive // portal probe, which completes before the page loads with a secure DNS // network error, which triggers another captive portal probe. The probe does // not find a captive portal. TEST_F(CaptivePortalTabReloaderTest, HttpsBadSecureDnsConfigPageLoadsAfterTimerTriggeredResults) { … } // The secure DNS config is configured correctly. The SSL timer triggers a // captive portal probe. This probe finds a captive portal and completes before // the page loads with a secure DNS network error, which does not trigger // another captive portal probe. The user then logs in, causing a page reload. TEST_F(CaptivePortalTabReloaderTest, HttpsSecureDnsConfigPageLoadsAfterTimerTriggeredResults) { … } // The user logs in in a different tab, before the page loads with a secure // DNS network error. A reload should occur when the page commits. TEST_F(CaptivePortalTabReloaderTest, HttpsSecureDnsConfigErrorAlreadyLoggedIn) { … } // An SSL protocol error triggers a captive portal check behind a captive // portal. The user then logs in. TEST_F(CaptivePortalTabReloaderTest, SSLProtocolError) { … } // An SSL protocol error triggers a captive portal check behind a captive // portal. The user logs in before the results from the captive portal check // completes. TEST_F(CaptivePortalTabReloaderTest, SSLProtocolErrorFastLogin) { … } // An SSL protocol error triggers a captive portal check behind a captive // portal. The user logs in before the results from the captive portal check // completes. This case is probably not too likely, but should be handled. TEST_F(CaptivePortalTabReloaderTest, SSLProtocolErrorAlreadyLoggedIn) { … } // Simulate the case that a user has already logged in before the tab receives a // captive portal result, but a RESULT_BEHIND_CAPTIVE_PORTAL was received // before the tab started loading. TEST_F(CaptivePortalTabReloaderTest, AlreadyLoggedIn) { … } // Same as above, except the result is received even before the timer triggers, // due to a captive portal test request from some external source, like a login // tab. TEST_F(CaptivePortalTabReloaderTest, AlreadyLoggedInBeforeTimerTriggers) { … } // Simulate the user logging in while the timer is still running. May happen // if the tab is reloaded just before logging in on another tab. TEST_F(CaptivePortalTabReloaderTest, LoginWhileTimerRunning) { … } // Simulate a captive portal being detected while the time is still running. // The captive portal check triggered by the timer detects the captive portal // again, and then the user logs in. TEST_F(CaptivePortalTabReloaderTest, BehindPortalResultWhileTimerRunning) { … } // The CaptivePortalService detects the user has logged in to a captive portal // while the timer is still running, but the original load succeeds, so no // reload is done. TEST_F(CaptivePortalTabReloaderTest, LogInWhileTimerRunningNoError) { … } // Simulate an HTTP redirect to HTTPS, when the Internet is connected. TEST_F(CaptivePortalTabReloaderTest, HttpToHttpsRedirectInternetConnected) { … } // Simulate an HTTP redirect to HTTPS and subsequent Login, when the user logs // in before the original page commits. TEST_F(CaptivePortalTabReloaderTest, HttpToHttpsRedirectLogin) { … } // Simulate the case where an HTTPs page redirects to an HTTPS page, before // the timer triggers. TEST_F(CaptivePortalTabReloaderTest, HttpsToHttpRedirect) { … } // Check that an HTTPS to HTTPS redirect results in no timer running. TEST_F(CaptivePortalTabReloaderTest, HttpsToHttpsRedirect) { … } // Check that an HTTPS to HTTP to HTTPS redirect results in no timer running. TEST_F(CaptivePortalTabReloaderTest, HttpsToHttpToHttpsRedirect) { … } // Check that an HTTP to HTTP redirect results in the timer not running. TEST_F(CaptivePortalTabReloaderTest, HttpToHttpRedirect) { … } } // namespace captive_portal