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

Side by Side Diff: components/ntp_snippets/request_throttler_unittest.cc

Issue 2227973002: Add request throttler to thumbnail fetching for articles on mobile NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Build issue 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/ntp_snippets/request_throttler.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | 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/ntp_snippets/request_throttler.h" 5 #include "components/ntp_snippets/request_throttler.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "components/ntp_snippets/pref_names.h" 10 #include "components/ntp_snippets/pref_names.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 EXPECT_TRUE(throttler_->DemandQuotaForRequest(true)); 55 EXPECT_TRUE(throttler_->DemandQuotaForRequest(true));
56 } 56 }
57 57
58 TEST_F(RequestThrottlerTest, QuotaIsPerDay) { 58 TEST_F(RequestThrottlerTest, QuotaIsPerDay) {
59 EXPECT_TRUE(throttler_->DemandQuotaForRequest(false)); 59 EXPECT_TRUE(throttler_->DemandQuotaForRequest(false));
60 EXPECT_TRUE(throttler_->DemandQuotaForRequest(false)); 60 EXPECT_TRUE(throttler_->DemandQuotaForRequest(false));
61 61
62 // Now fake the day pref so that the counter believes the count comes from 62 // Now fake the day pref so that the counter believes the count comes from
63 // yesterday. 63 // yesterday.
64 int now_day = (base::Time::Now() - base::Time::UnixEpoch()).InDays(); 64 int now_day = (base::Time::Now() - base::Time::UnixEpoch()).InDays();
65 test_prefs_.SetInteger(ntp_snippets::prefs::kSnippetFetcherQuotaDay, 65 test_prefs_.SetInteger(ntp_snippets::prefs::kSnippetFetcherRequestsDay,
66 now_day - 1); 66 now_day - 1);
67 67
68 // The quota should get reset as the day has changed. 68 // The quota should get reset as the day has changed.
69 EXPECT_TRUE(throttler_->DemandQuotaForRequest(false)); 69 EXPECT_TRUE(throttler_->DemandQuotaForRequest(false));
70 } 70 }
71 71
72 } // namespace ntp_snippets 72 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/request_throttler.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698