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

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

Issue 2176393004: Add expiration policy, code to check it, and a test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR feedback per DougArnett Created 4 years, 4 months 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
« no previous file with comments | « components/offline_pages/background/request_picker.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_picker.h" 5 #include "components/offline_pages/background/request_picker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/test/test_simple_task_runner.h" 8 #include "base/test/test_simple_task_runner.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 10 matching lines...) Expand all
21 // Data for request 1. 21 // Data for request 1.
22 const int64_t kRequestId1 = 17; 22 const int64_t kRequestId1 = 17;
23 const GURL kUrl1("https://google.com"); 23 const GURL kUrl1("https://google.com");
24 const ClientId kClientId1("bookmark", "1234"); 24 const ClientId kClientId1("bookmark", "1234");
25 // Data for request 2. 25 // Data for request 2.
26 const int64_t kRequestId2 = 42; 26 const int64_t kRequestId2 = 42;
27 const GURL kUrl2("http://nytimes.com"); 27 const GURL kUrl2("http://nytimes.com");
28 const ClientId kClientId2("bookmark", "5678"); 28 const ClientId kClientId2("bookmark", "5678");
29 const bool kUserRequested = true; 29 const bool kUserRequested = true;
30 const int kAttemptCount = 1; 30 const int kAttemptCount = 1;
31 const int kTwoWeeksInSeconds = 60 * 60 * 24 * 7 * 2;
31 32
32 // Constants for policy values - These settings represent the default values. 33 // Constants for policy values - These settings represent the default values.
33 const bool kPreferUntried = false; 34 const bool kPreferUntried = false;
34 const bool kPreferEarlier = true; 35 const bool kPreferEarlier = true;
35 const bool kPreferRetryCount = true; 36 const bool kPreferRetryCount = true;
36 } // namespace 37 } // namespace
37 38
38 class RequestPickerTest : public testing::Test { 39 class RequestPickerTest : public testing::Test {
39 public: 40 public:
40 RequestPickerTest(); 41 RequestPickerTest();
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 kUserRequested); 242 kUserRequested);
242 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time2, 243 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time2,
243 kUserRequested); 244 kUserRequested);
244 245
245 QueueRequestsAndChooseOne(request1, request2); 246 QueueRequestsAndChooseOne(request1, request2);
246 247
247 EXPECT_EQ(kRequestId2, last_picked_->request_id()); 248 EXPECT_EQ(kRequestId2, last_picked_->request_id());
248 EXPECT_FALSE(request_queue_empty_called_); 249 EXPECT_FALSE(request_queue_empty_called_);
249 } 250 }
250 251
252 TEST_F(RequestPickerTest, ChooseUnexpiredRequest) {
253 base::Time creation_time1 =
254 base::Time::Now() - base::TimeDelta::FromSeconds(kTwoWeeksInSeconds);
255 base::Time creation_time2 = base::Time::Now();
256 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time1,
257 kUserRequested);
258 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time2,
259 kUserRequested);
260
261 QueueRequestsAndChooseOne(request1, request2);
262
263 EXPECT_EQ(kRequestId2, last_picked_->request_id());
264 EXPECT_FALSE(request_queue_empty_called_);
265 }
266
251 } // namespace offline_pages 267 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/background/request_picker.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698