Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: components/offline_pages/background/request_coordinator_unittest.cc

Issue 2493683002: [OfflinePages] Fixes RequestCoordinator bug not clearing state on timeout (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/offline_pages/background/request_coordinator.h" 5 #include "components/offline_pages/background/request_coordinator.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 ->GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() + 1)); 1089 ->GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() + 1));
1090 PumpLoop(); 1090 PumpLoop();
1091 1091
1092 // Wait for timeout to expire. Use a TaskRunner with a DelayedTaskRunner 1092 // Wait for timeout to expire. Use a TaskRunner with a DelayedTaskRunner
1093 // which won't time out immediately, so the watchdog thread doesn't kill valid 1093 // which won't time out immediately, so the watchdog thread doesn't kill valid
1094 // tasks too soon. 1094 // tasks too soon.
1095 WaitForCallback(); 1095 WaitForCallback();
1096 PumpLoop(); 1096 PumpLoop();
1097 1097
1098 EXPECT_FALSE(is_starting()); 1098 EXPECT_FALSE(is_starting());
1099 EXPECT_FALSE(coordinator()->is_busy());
1099 EXPECT_TRUE(OfflinerWasCanceled()); 1100 EXPECT_TRUE(OfflinerWasCanceled());
1100 } 1101 }
1101 1102
1102 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForImmediateProcessing) { 1103 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForImmediateProcessing) {
1103 // If low end device, pretend it is not so that immediate start happens. 1104 // If low end device, pretend it is not so that immediate start happens.
1104 SetIsLowEndDeviceForTest(false); 1105 SetIsLowEndDeviceForTest(false);
1105 1106
1106 // Ensure that the new request does not finish - we simulate it being 1107 // Ensure that the new request does not finish - we simulate it being
1107 // in progress by asking it to skip making the completion callback. 1108 // in progress by asking it to skip making the completion callback.
1108 EnableOfflinerCallback(false); 1109 EnableOfflinerCallback(false);
(...skipping 16 matching lines...) Expand all
1125 1126
1126 // Verify still busy. 1127 // Verify still busy.
1127 EXPECT_TRUE(coordinator()->is_busy()); 1128 EXPECT_TRUE(coordinator()->is_busy());
1128 EXPECT_FALSE(OfflinerWasCanceled()); 1129 EXPECT_FALSE(OfflinerWasCanceled());
1129 1130
1130 // Advance the mock clock past the watchdog timeout now. 1131 // Advance the mock clock past the watchdog timeout now.
1131 AdvanceClockBy(base::TimeDelta::FromSeconds(2)); 1132 AdvanceClockBy(base::TimeDelta::FromSeconds(2));
1132 PumpLoop(); 1133 PumpLoop();
1133 1134
1134 // Verify the request timed out. 1135 // Verify the request timed out.
1136 EXPECT_FALSE(coordinator()->is_busy());
1135 EXPECT_TRUE(OfflinerWasCanceled()); 1137 EXPECT_TRUE(OfflinerWasCanceled());
1136 } 1138 }
1137 1139
1138 TEST_F(RequestCoordinatorTest, TimeBudgetExceeded) { 1140 TEST_F(RequestCoordinatorTest, TimeBudgetExceeded) {
1139 // Build two requests to use with the pre-renderer, and put it on the queue. 1141 // Build two requests to use with the pre-renderer, and put it on the queue.
1140 offline_pages::SavePageRequest request1( 1142 offline_pages::SavePageRequest request1(
1141 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); 1143 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
1142 offline_pages::SavePageRequest request2( 1144 offline_pages::SavePageRequest request2(
1143 kRequestId1 + 1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); 1145 kRequestId1 + 1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
1144 request2.set_completed_attempt_count(kAttemptCount); 1146 request2.set_completed_attempt_count(kAttemptCount);
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1395 // Now whether processing triggered immediately depends on whether test 1397 // Now whether processing triggered immediately depends on whether test
1396 // is run on svelte device or not. 1398 // is run on svelte device or not.
1397 if (base::SysInfo::IsLowEndDevice()) { 1399 if (base::SysInfo::IsLowEndDevice()) {
1398 EXPECT_FALSE(is_busy()); 1400 EXPECT_FALSE(is_busy());
1399 } else { 1401 } else {
1400 EXPECT_TRUE(is_busy()); 1402 EXPECT_TRUE(is_busy());
1401 } 1403 }
1402 } 1404 }
1403 1405
1404 } // namespace offline_pages 1406 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698