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

Side by Side Diff: extensions/browser/quota_service_unittest.cc

Issue 664933004: Standardize usage of virtual/override/final in extensions/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « extensions/browser/quota_service.h ('k') | extensions/browser/renderer_startup_helper.h » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "base/process/process.h" 6 #include "base/process/process.h"
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "content/public/test/test_browser_thread.h" 9 #include "content/public/test/test_browser_thread.h"
10 #include "extensions/browser/extension_function.h" 10 #include "extensions/browser/extension_function.h"
(...skipping 17 matching lines...) Expand all
28 const char kGenericName[] = "name"; 28 const char kGenericName[] = "name";
29 const Config kFrozenConfig = {0, TimeDelta::FromDays(0)}; 29 const Config kFrozenConfig = {0, TimeDelta::FromDays(0)};
30 const Config k2PerMinute = {2, TimeDelta::FromMinutes(1)}; 30 const Config k2PerMinute = {2, TimeDelta::FromMinutes(1)};
31 const Config k20PerHour = {20, TimeDelta::FromHours(1)}; 31 const Config k20PerHour = {20, TimeDelta::FromHours(1)};
32 const TimeTicks kStartTime = TimeTicks(); 32 const TimeTicks kStartTime = TimeTicks();
33 const TimeTicks k1MinuteAfterStart = kStartTime + TimeDelta::FromMinutes(1); 33 const TimeTicks k1MinuteAfterStart = kStartTime + TimeDelta::FromMinutes(1);
34 34
35 class Mapper : public QuotaLimitHeuristic::BucketMapper { 35 class Mapper : public QuotaLimitHeuristic::BucketMapper {
36 public: 36 public:
37 Mapper() {} 37 Mapper() {}
38 virtual ~Mapper() { STLDeleteValues(&buckets_); } 38 ~Mapper() override { STLDeleteValues(&buckets_); }
39 virtual void GetBucketsForArgs(const base::ListValue* args, 39 void GetBucketsForArgs(const base::ListValue* args,
40 BucketList* buckets) override { 40 BucketList* buckets) override {
41 for (size_t i = 0; i < args->GetSize(); i++) { 41 for (size_t i = 0; i < args->GetSize(); i++) {
42 int id; 42 int id;
43 ASSERT_TRUE(args->GetInteger(i, &id)); 43 ASSERT_TRUE(args->GetInteger(i, &id));
44 if (buckets_.find(id) == buckets_.end()) 44 if (buckets_.find(id) == buckets_.end())
45 buckets_[id] = new Bucket(); 45 buckets_[id] = new Bucket();
46 buckets->push_back(buckets_[id]); 46 buckets->push_back(buckets_[id]);
47 } 47 }
48 } 48 }
49 49
50 private: 50 private:
51 typedef std::map<int, Bucket*> BucketMap; 51 typedef std::map<int, Bucket*> BucketMap;
52 BucketMap buckets_; 52 BucketMap buckets_;
53 DISALLOW_COPY_AND_ASSIGN(Mapper); 53 DISALLOW_COPY_AND_ASSIGN(Mapper);
54 }; 54 };
55 55
56 class MockMapper : public QuotaLimitHeuristic::BucketMapper { 56 class MockMapper : public QuotaLimitHeuristic::BucketMapper {
57 public: 57 public:
58 virtual void GetBucketsForArgs(const base::ListValue* args, 58 void GetBucketsForArgs(const base::ListValue* args,
59 BucketList* buckets) override {} 59 BucketList* buckets) override {}
60 }; 60 };
61 61
62 class MockFunction : public ExtensionFunction { 62 class MockFunction : public ExtensionFunction {
63 public: 63 public:
64 explicit MockFunction(const std::string& name) { set_name(name); } 64 explicit MockFunction(const std::string& name) { set_name(name); }
65 65
66 virtual void SetArgs(const base::ListValue* args) override {} 66 void SetArgs(const base::ListValue* args) override {}
67 virtual std::string GetError() const override { return std::string(); } 67 std::string GetError() const override { return std::string(); }
68 virtual void SetError(const std::string& error) override {} 68 void SetError(const std::string& error) override {}
69 virtual void Destruct() const override { delete this; } 69 void Destruct() const override { delete this; }
70 virtual ResponseAction Run() override { return RespondLater(); } 70 ResponseAction Run() override { return RespondLater(); }
71 virtual void SendResponse(bool) override {} 71 void SendResponse(bool) override {}
72 72
73 protected: 73 protected:
74 virtual ~MockFunction() {} 74 ~MockFunction() override {}
75 }; 75 };
76 76
77 class TimedLimitMockFunction : public MockFunction { 77 class TimedLimitMockFunction : public MockFunction {
78 public: 78 public:
79 explicit TimedLimitMockFunction(const std::string& name) 79 explicit TimedLimitMockFunction(const std::string& name)
80 : MockFunction(name) {} 80 : MockFunction(name) {}
81 virtual void GetQuotaLimitHeuristics(QuotaLimitHeuristics* heuristics) const 81 void GetQuotaLimitHeuristics(
82 override { 82 QuotaLimitHeuristics* heuristics) const override {
83 heuristics->push_back( 83 heuristics->push_back(
84 new TimedLimit(k2PerMinute, new Mapper(), kGenericName)); 84 new TimedLimit(k2PerMinute, new Mapper(), kGenericName));
85 } 85 }
86 86
87 private: 87 private:
88 virtual ~TimedLimitMockFunction() {} 88 ~TimedLimitMockFunction() override {}
89 }; 89 };
90 90
91 class ChainedLimitsMockFunction : public MockFunction { 91 class ChainedLimitsMockFunction : public MockFunction {
92 public: 92 public:
93 explicit ChainedLimitsMockFunction(const std::string& name) 93 explicit ChainedLimitsMockFunction(const std::string& name)
94 : MockFunction(name) {} 94 : MockFunction(name) {}
95 virtual void GetQuotaLimitHeuristics(QuotaLimitHeuristics* heuristics) const 95 void GetQuotaLimitHeuristics(
96 override { 96 QuotaLimitHeuristics* heuristics) const override {
97 // No more than 2 per minute sustained over 5 minutes. 97 // No more than 2 per minute sustained over 5 minutes.
98 heuristics->push_back(new SustainedLimit( 98 heuristics->push_back(new SustainedLimit(
99 TimeDelta::FromMinutes(5), k2PerMinute, new Mapper(), kGenericName)); 99 TimeDelta::FromMinutes(5), k2PerMinute, new Mapper(), kGenericName));
100 // No more than 20 per hour. 100 // No more than 20 per hour.
101 heuristics->push_back( 101 heuristics->push_back(
102 new TimedLimit(k20PerHour, new Mapper(), kGenericName)); 102 new TimedLimit(k20PerHour, new Mapper(), kGenericName));
103 } 103 }
104 104
105 private: 105 private:
106 virtual ~ChainedLimitsMockFunction() {} 106 ~ChainedLimitsMockFunction() override {}
107 }; 107 };
108 108
109 class FrozenMockFunction : public MockFunction { 109 class FrozenMockFunction : public MockFunction {
110 public: 110 public:
111 explicit FrozenMockFunction(const std::string& name) : MockFunction(name) {} 111 explicit FrozenMockFunction(const std::string& name) : MockFunction(name) {}
112 virtual void GetQuotaLimitHeuristics(QuotaLimitHeuristics* heuristics) const 112 void GetQuotaLimitHeuristics(
113 override { 113 QuotaLimitHeuristics* heuristics) const override {
114 heuristics->push_back( 114 heuristics->push_back(
115 new TimedLimit(kFrozenConfig, new Mapper(), kGenericName)); 115 new TimedLimit(kFrozenConfig, new Mapper(), kGenericName));
116 } 116 }
117 117
118 private: 118 private:
119 virtual ~FrozenMockFunction() {} 119 ~FrozenMockFunction() override {}
120 }; 120 };
121 } // namespace 121 } // namespace
122 122
123 class QuotaServiceTest : public testing::Test { 123 class QuotaServiceTest : public testing::Test {
124 public: 124 public:
125 QuotaServiceTest() 125 QuotaServiceTest()
126 : extension_a_("a"), 126 : extension_a_("a"),
127 extension_b_("b"), 127 extension_b_("b"),
128 extension_c_("c"), 128 extension_c_("c"),
129 loop_(), 129 loop_(),
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 "", 407 "",
408 service_->Assess( 408 service_->Assess(
409 extension_a_, f.get(), &arg, kStartTime + TimeDelta::FromDays(1))); 409 extension_a_, f.get(), &arg, kStartTime + TimeDelta::FromDays(1)));
410 EXPECT_NE( 410 EXPECT_NE(
411 "", 411 "",
412 service_->Assess( 412 service_->Assess(
413 extension_a_, g.get(), &arg, kStartTime + TimeDelta::FromDays(1))); 413 extension_a_, g.get(), &arg, kStartTime + TimeDelta::FromDays(1)));
414 } 414 }
415 415
416 } // namespace extensions 416 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/quota_service.h ('k') | extensions/browser/renderer_startup_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698