Commit db14329b authored by warx's avatar warx Committed by Commit bot

cros: Do not schedule attempt when behind captive portal with response 200 is detected

Changes:
(1) Do not schedule attempt if we are already behind captive portal with response 200, which can be either the result of NetworkPortalDetector or shill's detection. In test, this can reduce the call times of CaptivePortalDetector::DetectCaptivePortal from 6+ to 2~3 within 10s.
(2) modify tests to adapt this change

BUG=702273
TEST=If we log in CaptivePortalDetector::DetectCaptivePortal, we can see the attempts reduced to 2~3 for connecting to captive portal wifi.

Review-Url: https://codereview.chromium.org/2756643002
Cr-Commit-Position: refs/heads/master@{#457829}
parent 19de954f
...@@ -551,8 +551,15 @@ void NetworkPortalDetectorImpl::OnAttemptCompleted( ...@@ -551,8 +551,15 @@ void NetworkPortalDetectorImpl::OnAttemptCompleted(
} }
// Observers (via OnDetectionCompleted) may already schedule new attempt. // Observers (via OnDetectionCompleted) may already schedule new attempt.
if (is_idle()) if (!is_idle())
ScheduleAttempt(results.retry_after_delta); return;
// If behind a captive portal and the response code was 200 (OK), do not
// schedule a new attempt.
if (state.status == CAPTIVE_PORTAL_STATUS_PORTAL && response_code == 200)
return;
ScheduleAttempt(results.retry_after_delta);
} }
void NetworkPortalDetectorImpl::Observe( void NetworkPortalDetectorImpl::Observe(
......
...@@ -334,7 +334,7 @@ TEST_F(NetworkPortalDetectorImplTest, Portal) { ...@@ -334,7 +334,7 @@ TEST_F(NetworkPortalDetectorImplTest, Portal) {
CompleteURLFetch(net::OK, 200, nullptr); CompleteURLFetch(net::OK, 200, nullptr);
ASSERT_FALSE(is_state_idle()); ASSERT_TRUE(is_state_idle());
CheckPortalState( CheckPortalState(
NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, kStubWireless1); NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, kStubWireless1);
...@@ -425,7 +425,7 @@ TEST_F(NetworkPortalDetectorImplTest, TwoNetworks) { ...@@ -425,7 +425,7 @@ TEST_F(NetworkPortalDetectorImplTest, TwoNetworks) {
// WiFi is in portal state. // WiFi is in portal state.
CompleteURLFetch(net::OK, 200, nullptr); CompleteURLFetch(net::OK, 200, nullptr);
ASSERT_FALSE(is_state_idle()); ASSERT_TRUE(is_state_idle());
SetConnected(kStubEthernet); SetConnected(kStubEthernet);
ASSERT_TRUE(is_state_checking_for_portal()); ASSERT_TRUE(is_state_checking_for_portal());
...@@ -508,7 +508,7 @@ TEST_F(NetworkPortalDetectorImplTest, NetworkStateChanged) { ...@@ -508,7 +508,7 @@ TEST_F(NetworkPortalDetectorImplTest, NetworkStateChanged) {
CompleteURLFetch(net::OK, 200, nullptr); CompleteURLFetch(net::OK, 200, nullptr);
ASSERT_FALSE(is_state_idle()); ASSERT_TRUE(is_state_idle());
CheckPortalState( CheckPortalState(
NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, kStubWireless1); NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, kStubWireless1);
...@@ -526,7 +526,7 @@ TEST_F(NetworkPortalDetectorImplTest, NetworkStateChanged) { ...@@ -526,7 +526,7 @@ TEST_F(NetworkPortalDetectorImplTest, NetworkStateChanged) {
CompleteURLFetch(net::OK, 200, nullptr); CompleteURLFetch(net::OK, 200, nullptr);
ASSERT_FALSE(is_state_idle()); ASSERT_TRUE(is_state_idle());
CheckPortalState( CheckPortalState(
NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, kStubWireless1); NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, kStubWireless1);
...@@ -825,7 +825,7 @@ TEST_F(NetworkPortalDetectorImplTest, ErrorScreenStrategyForPortalNetwork) { ...@@ -825,7 +825,7 @@ TEST_F(NetworkPortalDetectorImplTest, ErrorScreenStrategyForPortalNetwork) {
CompleteURLFetch(net::OK, 200, nullptr); CompleteURLFetch(net::OK, 200, nullptr);
ASSERT_EQ(0, no_response_result_count()); ASSERT_EQ(0, no_response_result_count());
ASSERT_TRUE(is_state_portal_detection_pending()); ASSERT_TRUE(is_state_idle());
CheckPortalState( CheckPortalState(
NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, kStubWireless1); NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, kStubWireless1);
...@@ -834,6 +834,7 @@ TEST_F(NetworkPortalDetectorImplTest, ErrorScreenStrategyForPortalNetwork) { ...@@ -834,6 +834,7 @@ TEST_F(NetworkPortalDetectorImplTest, ErrorScreenStrategyForPortalNetwork) {
disable_error_screen_strategy(); disable_error_screen_strategy();
// Set a different strategy will Start detection if idle.
ASSERT_TRUE(is_state_portal_detection_pending()); ASSERT_TRUE(is_state_portal_detection_pending());
CheckPortalState( CheckPortalState(
NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, kStubWireless1); NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, kStubWireless1);
...@@ -887,7 +888,7 @@ TEST_F(NetworkPortalDetectorImplTest, TestDetectionRestart) { ...@@ -887,7 +888,7 @@ TEST_F(NetworkPortalDetectorImplTest, TestDetectionRestart) {
CheckPortalState( CheckPortalState(
NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, kStubWireless1); NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL, 200, kStubWireless1);
ASSERT_FALSE(is_state_idle()); ASSERT_TRUE(is_state_idle());
ASSERT_TRUE( ASSERT_TRUE(
MakeResultHistogramChecker() MakeResultHistogramChecker()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment