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

Side by Side Diff: chrome/browser/extensions/api/declarative_content/chrome_content_rules_registry_unittest.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/declarative_content/chrome_content_rules _registry.h" 5 #include "chrome/browser/extensions/api/declarative_content/chrome_content_rules _registry.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ptr_util.h"
9 #include "base/test/values_test_util.h" 10 #include "base/test/values_test_util.h"
10 #include "chrome/browser/extensions/api/declarative_content/content_predicate.h" 11 #include "chrome/browser/extensions/api/declarative_content/content_predicate.h"
11 #include "chrome/browser/extensions/api/declarative_content/content_predicate_ev aluator.h" 12 #include "chrome/browser/extensions/api/declarative_content/content_predicate_ev aluator.h"
12 #include "chrome/browser/extensions/test_extension_environment.h" 13 #include "chrome/browser/extensions/test_extension_environment.h"
13 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
14 #include "content/public/browser/navigation_details.h" 15 #include "content/public/browser/navigation_details.h"
15 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
16 #include "content/public/common/frame_navigate_params.h" 17 #include "content/public/common/frame_navigate_params.h"
17 #include "extensions/common/extension.h" 18 #include "extensions/common/extension.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 25 matching lines...) Expand all
44 explicit TestPredicateEvaluator(ContentPredicateEvaluator::Delegate* delegate) 45 explicit TestPredicateEvaluator(ContentPredicateEvaluator::Delegate* delegate)
45 : delegate_(delegate), 46 : delegate_(delegate),
46 contents_for_next_operation_evaluation_(nullptr), 47 contents_for_next_operation_evaluation_(nullptr),
47 next_evaluation_result_(false) { 48 next_evaluation_result_(false) {
48 } 49 }
49 50
50 std::string GetPredicateApiAttributeName() const override { 51 std::string GetPredicateApiAttributeName() const override {
51 return "test_predicate"; 52 return "test_predicate";
52 } 53 }
53 54
54 scoped_ptr<const ContentPredicate> CreatePredicate( 55 std::unique_ptr<const ContentPredicate> CreatePredicate(
55 const Extension* extension, 56 const Extension* extension,
56 const base::Value& value, 57 const base::Value& value,
57 std::string* error) override { 58 std::string* error) override {
58 RequestEvaluationIfSpecified(); 59 RequestEvaluationIfSpecified();
59 return make_scoped_ptr(new TestPredicate(this)); 60 return base::WrapUnique(new TestPredicate(this));
60 } 61 }
61 62
62 void TrackPredicates( 63 void TrackPredicates(
63 const std::map<const void*, 64 const std::map<const void*,
64 std::vector<const ContentPredicate*>>& predicates) override { 65 std::vector<const ContentPredicate*>>& predicates) override {
65 RequestEvaluationIfSpecified(); 66 RequestEvaluationIfSpecified();
66 } 67 }
67 68
68 void StopTrackingPredicates( 69 void StopTrackingPredicates(
69 const std::vector<const void*>& predicate_groups) override { 70 const std::vector<const void*>& predicate_groups) override {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 109 }
109 110
110 ContentPredicateEvaluator::Delegate* delegate_; 111 ContentPredicateEvaluator::Delegate* delegate_;
111 content::WebContents* contents_for_next_operation_evaluation_; 112 content::WebContents* contents_for_next_operation_evaluation_;
112 mutable bool next_evaluation_result_; 113 mutable bool next_evaluation_result_;
113 114
114 DISALLOW_COPY_AND_ASSIGN(TestPredicateEvaluator); 115 DISALLOW_COPY_AND_ASSIGN(TestPredicateEvaluator);
115 }; 116 };
116 117
117 // Create the test evaluator and set |evaluator| to its pointer. 118 // Create the test evaluator and set |evaluator| to its pointer.
118 std::vector<scoped_ptr<ContentPredicateEvaluator>> CreateTestEvaluator( 119 std::vector<std::unique_ptr<ContentPredicateEvaluator>> CreateTestEvaluator(
119 TestPredicateEvaluator** evaluator, 120 TestPredicateEvaluator** evaluator,
120 ContentPredicateEvaluator::Delegate* delegate) { 121 ContentPredicateEvaluator::Delegate* delegate) {
121 std::vector<scoped_ptr<ContentPredicateEvaluator>> evaluators; 122 std::vector<std::unique_ptr<ContentPredicateEvaluator>> evaluators;
122 *evaluator = new TestPredicateEvaluator(delegate); 123 *evaluator = new TestPredicateEvaluator(delegate);
123 evaluators.push_back(scoped_ptr<ContentPredicateEvaluator>(*evaluator)); 124 evaluators.push_back(std::unique_ptr<ContentPredicateEvaluator>(*evaluator));
124 return evaluators; 125 return evaluators;
125 } 126 }
126 127
127 } // namespace 128 } // namespace
128 129
129 class DeclarativeChromeContentRulesRegistryTest : public testing::Test { 130 class DeclarativeChromeContentRulesRegistryTest : public testing::Test {
130 public: 131 public:
131 DeclarativeChromeContentRulesRegistryTest() {} 132 DeclarativeChromeContentRulesRegistryTest() {}
132 133
133 protected: 134 protected:
134 TestExtensionEnvironment* env() { return &env_; } 135 TestExtensionEnvironment* env() { return &env_; }
135 136
136 private: 137 private:
137 TestExtensionEnvironment env_; 138 TestExtensionEnvironment env_;
138 139
139 DISALLOW_COPY_AND_ASSIGN(DeclarativeChromeContentRulesRegistryTest); 140 DISALLOW_COPY_AND_ASSIGN(DeclarativeChromeContentRulesRegistryTest);
140 }; 141 };
141 142
142 TEST_F(DeclarativeChromeContentRulesRegistryTest, ActiveRulesDoesntGrow) { 143 TEST_F(DeclarativeChromeContentRulesRegistryTest, ActiveRulesDoesntGrow) {
143 TestPredicateEvaluator* evaluator = nullptr; 144 TestPredicateEvaluator* evaluator = nullptr;
144 scoped_refptr<ChromeContentRulesRegistry> registry( 145 scoped_refptr<ChromeContentRulesRegistry> registry(
145 new ChromeContentRulesRegistry(env()->profile(), nullptr, 146 new ChromeContentRulesRegistry(env()->profile(), nullptr,
146 base::Bind(&CreateTestEvaluator, 147 base::Bind(&CreateTestEvaluator,
147 &evaluator))); 148 &evaluator)));
148 149
149 EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting()); 150 EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting());
150 151
151 scoped_ptr<content::WebContents> tab = env()->MakeTab(); 152 std::unique_ptr<content::WebContents> tab = env()->MakeTab();
152 registry->MonitorWebContentsForRuleEvaluation(tab.get()); 153 registry->MonitorWebContentsForRuleEvaluation(tab.get());
153 registry->DidNavigateMainFrame(tab.get(), content::LoadCommittedDetails(), 154 registry->DidNavigateMainFrame(tab.get(), content::LoadCommittedDetails(),
154 content::FrameNavigateParams()); 155 content::FrameNavigateParams());
155 EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting()); 156 EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting());
156 157
157 // Add a rule. 158 // Add a rule.
158 linked_ptr<api::events::Rule> rule(new api::events::Rule); 159 linked_ptr<api::events::Rule> rule(new api::events::Rule);
159 api::events::Rule::Populate( 160 api::events::Rule::Populate(
160 *base::test::ParseJson( 161 *base::test::ParseJson(
161 "{\n" 162 "{\n"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 evaluator->RequestImmediateEvaluation(tab.get(), true); 195 evaluator->RequestImmediateEvaluation(tab.get(), true);
195 EXPECT_EQ(1u, registry->GetActiveRulesCountForTesting()); 196 EXPECT_EQ(1u, registry->GetActiveRulesCountForTesting());
196 197
197 evaluator->RequestEvaluationOnNextOperation(tab.get(), false); 198 evaluator->RequestEvaluationOnNextOperation(tab.get(), false);
198 registry->DidNavigateMainFrame(tab.get(), content::LoadCommittedDetails(), 199 registry->DidNavigateMainFrame(tab.get(), content::LoadCommittedDetails(),
199 content::FrameNavigateParams()); 200 content::FrameNavigateParams());
200 EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting()); 201 EXPECT_EQ(0u, registry->GetActiveRulesCountForTesting());
201 } 202 }
202 203
203 } // namespace extensions 204 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698