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

Unified Diff: extensions/browser/quota_service_unittest.cc

Issue 685603003: Remove the extension QuotaService::SustainedLimit and its last client, the (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fullstop Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/browser/quota_service.cc ('k') | extensions/common/api/storage.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/quota_service_unittest.cc
diff --git a/extensions/browser/quota_service_unittest.cc b/extensions/browser/quota_service_unittest.cc
index 5bd04007a766f5c218c3c53cad0687934c6ab68a..b33910a9d867580515388682f6ffd4f096f504d2 100644
--- a/extensions/browser/quota_service_unittest.cc
+++ b/extensions/browser/quota_service_unittest.cc
@@ -21,7 +21,6 @@ typedef QuotaLimitHeuristic::Bucket Bucket;
typedef QuotaLimitHeuristic::Config Config;
typedef QuotaLimitHeuristic::BucketList BucketList;
typedef QuotaService::TimedLimit TimedLimit;
-typedef QuotaService::SustainedLimit SustainedLimit;
namespace {
@@ -88,24 +87,6 @@ class TimedLimitMockFunction : public MockFunction {
~TimedLimitMockFunction() override {}
};
-class ChainedLimitsMockFunction : public MockFunction {
- public:
- explicit ChainedLimitsMockFunction(const std::string& name)
- : MockFunction(name) {}
- void GetQuotaLimitHeuristics(
- QuotaLimitHeuristics* heuristics) const override {
- // No more than 2 per minute sustained over 5 minutes.
- heuristics->push_back(new SustainedLimit(
- TimeDelta::FromMinutes(5), k2PerMinute, new Mapper(), kGenericName));
- // No more than 20 per hour.
- heuristics->push_back(
- new TimedLimit(k20PerHour, new Mapper(), kGenericName));
- }
-
- private:
- ~ChainedLimitsMockFunction() override {}
-};
-
class FrozenMockFunction : public MockFunction {
public:
explicit FrozenMockFunction(const std::string& name) : MockFunction(name) {}
@@ -189,31 +170,6 @@ TEST_F(QuotaLimitHeuristicTest, Timed) {
EXPECT_FALSE(lim.Apply(&b, k1MinuteAfterStart + TimeDelta::FromSeconds(3)));
}
-TEST_F(QuotaLimitHeuristicTest, Sustained) {
- SustainedLimit lim(
- TimeDelta::FromMinutes(5), k2PerMinute, new MockMapper(), kGenericName);
- Bucket bucket;
-
- bucket.Reset(k2PerMinute, kStartTime);
- DoMoreThan2PerMinuteFor5Minutes(kStartTime, &lim, &bucket, -1);
- // This straw breaks the camel's back.
- EXPECT_FALSE(lim.Apply(&bucket, kStartTime + TimeDelta::FromMinutes(6)));
-
- // The heuristic resets itself on a safe request.
- EXPECT_TRUE(lim.Apply(&bucket, kStartTime + TimeDelta::FromDays(1)));
-
- // Do the same as above except don't exhaust final bucket.
- bucket.Reset(k2PerMinute, kStartTime);
- DoMoreThan2PerMinuteFor5Minutes(kStartTime, &lim, &bucket, -1);
- EXPECT_TRUE(lim.Apply(&bucket, kStartTime + TimeDelta::FromMinutes(7)));
-
- // Do the same as above except don't exhaust the 3rd (w.l.o.g) bucket.
- bucket.Reset(k2PerMinute, kStartTime);
- DoMoreThan2PerMinuteFor5Minutes(kStartTime, &lim, &bucket, 3);
- // If the 3rd bucket were exhausted, this would fail (see first test).
- EXPECT_TRUE(lim.Apply(&bucket, kStartTime + TimeDelta::FromMinutes(6)));
-}
-
TEST_F(QuotaServiceTest, NoHeuristic) {
scoped_refptr<MockFunction> f(new MockFunction("foo"));
base::ListValue args;
@@ -298,59 +254,6 @@ TEST_F(QuotaServiceTest, SingleHeuristic) {
kStartTime + TimeDelta::FromSeconds(30)));
}
-TEST_F(QuotaServiceTest, ChainedHeuristics) {
- scoped_refptr<MockFunction> f(new ChainedLimitsMockFunction("foo"));
- base::ListValue args;
- args.Append(new base::FundamentalValue(1));
-
- // First, test that the low limit can be avoided but the higher one is hit.
- // One event per minute for 20 minutes comes in under the sustained limit,
- // but is equal to the timed limit.
- for (int i = 0; i < 20; i++) {
- EXPECT_EQ(
- "",
- service_->Assess(extension_a_,
- f.get(),
- &args,
- kStartTime + TimeDelta::FromSeconds(10 + i * 60)));
- }
-
- // This will bring us to 21 events in an hour, which is a violation.
- EXPECT_NE("",
- service_->Assess(extension_a_,
- f.get(),
- &args,
- kStartTime + TimeDelta::FromMinutes(30)));
-
- // Now, check that we can still hit the lower limit.
- for (int i = 0; i < 5; i++) {
- EXPECT_EQ(
- "",
- service_->Assess(extension_b_,
- f.get(),
- &args,
- kStartTime + TimeDelta::FromSeconds(10 + i * 60)));
- EXPECT_EQ(
- "",
- service_->Assess(extension_b_,
- f.get(),
- &args,
- kStartTime + TimeDelta::FromSeconds(15 + i * 60)));
- EXPECT_EQ(
- "",
- service_->Assess(extension_b_,
- f.get(),
- &args,
- kStartTime + TimeDelta::FromSeconds(20 + i * 60)));
- }
-
- EXPECT_NE("",
- service_->Assess(extension_b_,
- f.get(),
- &args,
- kStartTime + TimeDelta::FromMinutes(6)));
-}
-
TEST_F(QuotaServiceTest, MultipleFunctionsDontInterfere) {
scoped_refptr<MockFunction> f(new TimedLimitMockFunction("foo"));
scoped_refptr<MockFunction> g(new TimedLimitMockFunction("bar"));
« no previous file with comments | « extensions/browser/quota_service.cc ('k') | extensions/common/api/storage.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698