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

Side by Side Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc

Issue 1854993002: [Extensions] Remove linked_ptr entirely from extensions generated code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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 "extensions/browser/api/declarative_webrequest/webrequest_rules_registr y.h" 5 #include "extensions/browser/api/declarative_webrequest/webrequest_rules_registr y.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 https_condition_url_filter.Set(keys::kUrlKey, https_condition_dict); 119 https_condition_url_filter.Set(keys::kUrlKey, https_condition_dict);
120 https_condition_url_filter.SetString(keys::kInstanceTypeKey, 120 https_condition_url_filter.SetString(keys::kInstanceTypeKey,
121 keys::kRequestMatcherType); 121 keys::kRequestMatcherType);
122 122
123 base::DictionaryValue action_dict; 123 base::DictionaryValue action_dict;
124 action_dict.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType); 124 action_dict.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType);
125 125
126 linked_ptr<api::events::Rule> rule(new api::events::Rule); 126 linked_ptr<api::events::Rule> rule(new api::events::Rule);
127 rule->id.reset(new std::string(kRuleId1)); 127 rule->id.reset(new std::string(kRuleId1));
128 rule->priority.reset(new int(100)); 128 rule->priority.reset(new int(100));
129 rule->actions.push_back(linked_ptr<base::Value>(action_dict.DeepCopy())); 129 rule->actions.push_back(action_dict.CreateDeepCopy());
130 rule->conditions.push_back( 130 rule->conditions.push_back(http_condition_url_filter.CreateDeepCopy());
131 linked_ptr<base::Value>(http_condition_url_filter.DeepCopy())); 131 rule->conditions.push_back(https_condition_url_filter.CreateDeepCopy());
132 rule->conditions.push_back(
133 linked_ptr<base::Value>(https_condition_url_filter.DeepCopy()));
134 return rule; 132 return rule;
135 } 133 }
136 134
137 // Returns a rule that matches anything and cancels it. 135 // Returns a rule that matches anything and cancels it.
138 linked_ptr<api::events::Rule> CreateRule2() { 136 linked_ptr<api::events::Rule> CreateRule2() {
139 base::DictionaryValue condition_dict; 137 base::DictionaryValue condition_dict;
140 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType); 138 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType);
141 139
142 base::DictionaryValue action_dict; 140 base::DictionaryValue action_dict;
143 action_dict.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType); 141 action_dict.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType);
144 142
145 linked_ptr<api::events::Rule> rule(new api::events::Rule); 143 linked_ptr<api::events::Rule> rule(new api::events::Rule);
146 rule->id.reset(new std::string(kRuleId2)); 144 rule->id.reset(new std::string(kRuleId2));
147 rule->priority.reset(new int(100)); 145 rule->priority.reset(new int(100));
148 rule->actions.push_back(linked_ptr<base::Value>(action_dict.DeepCopy())); 146 rule->actions.push_back(action_dict.CreateDeepCopy());
149 rule->conditions.push_back( 147 rule->conditions.push_back(condition_dict.CreateDeepCopy());
150 linked_ptr<base::Value>(condition_dict.DeepCopy()));
151 return rule; 148 return rule;
152 } 149 }
153 150
154 linked_ptr<api::events::Rule> CreateRedirectRule( 151 linked_ptr<api::events::Rule> CreateRedirectRule(
155 const std::string& destination) { 152 const std::string& destination) {
156 base::DictionaryValue condition_dict; 153 base::DictionaryValue condition_dict;
157 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType); 154 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType);
158 155
159 base::DictionaryValue action_dict; 156 base::DictionaryValue action_dict;
160 action_dict.SetString(keys::kInstanceTypeKey, keys::kRedirectRequestType); 157 action_dict.SetString(keys::kInstanceTypeKey, keys::kRedirectRequestType);
161 action_dict.SetString(keys::kRedirectUrlKey, destination); 158 action_dict.SetString(keys::kRedirectUrlKey, destination);
162 159
163 linked_ptr<api::events::Rule> rule(new api::events::Rule); 160 linked_ptr<api::events::Rule> rule(new api::events::Rule);
164 rule->id.reset(new std::string(kRuleId3)); 161 rule->id.reset(new std::string(kRuleId3));
165 rule->priority.reset(new int(100)); 162 rule->priority.reset(new int(100));
166 rule->actions.push_back(linked_ptr<base::Value>(action_dict.DeepCopy())); 163 rule->actions.push_back(action_dict.CreateDeepCopy());
167 rule->conditions.push_back( 164 rule->conditions.push_back(condition_dict.CreateDeepCopy());
168 linked_ptr<base::Value>(condition_dict.DeepCopy()));
169 return rule; 165 return rule;
170 } 166 }
171 167
172 // Create a rule to ignore all other rules for a destination that 168 // Create a rule to ignore all other rules for a destination that
173 // contains index.html. 169 // contains index.html.
174 linked_ptr<api::events::Rule> CreateIgnoreRule() { 170 linked_ptr<api::events::Rule> CreateIgnoreRule() {
175 base::DictionaryValue condition_dict; 171 base::DictionaryValue condition_dict;
176 base::DictionaryValue* http_condition_dict = new base::DictionaryValue(); 172 base::DictionaryValue* http_condition_dict = new base::DictionaryValue();
177 http_condition_dict->SetString(keys2::kPathContainsKey, "index.html"); 173 http_condition_dict->SetString(keys2::kPathContainsKey, "index.html");
178 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType); 174 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType);
179 condition_dict.Set(keys::kUrlKey, http_condition_dict); 175 condition_dict.Set(keys::kUrlKey, http_condition_dict);
180 176
181 base::DictionaryValue action_dict; 177 base::DictionaryValue action_dict;
182 action_dict.SetString(keys::kInstanceTypeKey, keys::kIgnoreRulesType); 178 action_dict.SetString(keys::kInstanceTypeKey, keys::kIgnoreRulesType);
183 action_dict.SetInteger(keys::kLowerPriorityThanKey, 150); 179 action_dict.SetInteger(keys::kLowerPriorityThanKey, 150);
184 180
185 linked_ptr<api::events::Rule> rule(new api::events::Rule); 181 linked_ptr<api::events::Rule> rule(new api::events::Rule);
186 rule->id.reset(new std::string(kRuleId4)); 182 rule->id.reset(new std::string(kRuleId4));
187 rule->priority.reset(new int(200)); 183 rule->priority.reset(new int(200));
188 rule->actions.push_back(linked_ptr<base::Value>(action_dict.DeepCopy())); 184 rule->actions.push_back(action_dict.CreateDeepCopy());
189 rule->conditions.push_back( 185 rule->conditions.push_back(condition_dict.CreateDeepCopy());
190 linked_ptr<base::Value>(condition_dict.DeepCopy()));
191 return rule; 186 return rule;
192 } 187 }
193 188
194 // Create a condition with the attributes specified. An example value of 189 // Create a condition with the attributes specified. An example value of
195 // |attributes| is: "\"resourceType\": [\"stylesheet\"], \n". 190 // |attributes| is: "\"resourceType\": [\"stylesheet\"], \n".
196 linked_ptr<base::Value> CreateCondition(const std::string& attributes) { 191 scoped_ptr<base::Value> CreateCondition(const std::string& attributes) {
197 std::string json_description = 192 std::string json_description =
198 "{ \n" 193 "{ \n"
199 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n"; 194 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n";
200 json_description += attributes; 195 json_description += attributes;
201 json_description += "}"; 196 json_description += "}";
202 197
203 return linked_ptr<base::Value>( 198 return base::test::ParseJson(json_description);
204 base::test::ParseJson(json_description).release());
205 } 199 }
206 200
207 // Create a rule with the ID |rule_id| and with conditions created from the 201 // Create a rule with the ID |rule_id| and with conditions created from the
208 // |attributes| specified (one entry one condition). An example value of a 202 // |attributes| specified (one entry one condition). An example value of a
209 // string from |attributes| is: "\"resourceType\": [\"stylesheet\"], \n". 203 // string from |attributes| is: "\"resourceType\": [\"stylesheet\"], \n".
210 linked_ptr<api::events::Rule> CreateCancellingRule( 204 linked_ptr<api::events::Rule> CreateCancellingRule(
211 const char* rule_id, 205 const char* rule_id,
212 const std::vector<const std::string*>& attributes) { 206 const std::vector<const std::string*>& attributes) {
213 base::DictionaryValue action_dict; 207 base::DictionaryValue action_dict;
214 action_dict.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType); 208 action_dict.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType);
215 209
216 linked_ptr<api::events::Rule> rule(new api::events::Rule); 210 linked_ptr<api::events::Rule> rule(new api::events::Rule);
217 rule->id.reset(new std::string(rule_id)); 211 rule->id.reset(new std::string(rule_id));
218 rule->priority.reset(new int(1)); 212 rule->priority.reset(new int(1));
219 rule->actions.push_back(linked_ptr<base::Value>(action_dict.DeepCopy())); 213 rule->actions.push_back(action_dict.CreateDeepCopy());
220 for (std::vector<const std::string*>::const_iterator it = 214 for (std::vector<const std::string*>::const_iterator it =
221 attributes.begin(); 215 attributes.begin();
222 it != attributes.end(); ++it) 216 it != attributes.end(); ++it)
223 rule->conditions.push_back(CreateCondition(**it)); 217 rule->conditions.push_back(CreateCondition(**it));
224 return rule; 218 return rule;
225 } 219 }
226 220
227 protected: 221 protected:
228 base::MessageLoopForIO message_loop_; 222 base::MessageLoopForIO message_loop_;
229 content::TestBrowserThread ui_; 223 content::TestBrowserThread ui_;
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 TEST(WebRequestRulesRegistrySimpleTest, HostPermissionsChecker) { 723 TEST(WebRequestRulesRegistrySimpleTest, HostPermissionsChecker) {
730 const char kAction[] = // This action requires all URLs host permission. 724 const char kAction[] = // This action requires all URLs host permission.
731 "{ \n" 725 "{ \n"
732 " \"instanceType\": \"declarativeWebRequest.RedirectRequest\",\n" 726 " \"instanceType\": \"declarativeWebRequest.RedirectRequest\",\n"
733 " \"redirectUrl\": \"http://bar.com\" \n" 727 " \"redirectUrl\": \"http://bar.com\" \n"
734 "} "; 728 "} ";
735 scoped_ptr<base::Value> action_value = base::JSONReader::Read(kAction); 729 scoped_ptr<base::Value> action_value = base::JSONReader::Read(kAction);
736 ASSERT_TRUE(action_value); 730 ASSERT_TRUE(action_value);
737 731
738 WebRequestActionSet::Values actions; 732 WebRequestActionSet::Values actions;
739 actions.push_back(linked_ptr<base::Value>(action_value.release())); 733 actions.push_back(std::move(action_value));
740 ASSERT_TRUE(actions.back().get()); 734 ASSERT_TRUE(actions.back().get());
741 735
742 std::string error; 736 std::string error;
743 bool bad_message = false; 737 bool bad_message = false;
744 scoped_ptr<WebRequestActionSet> action_set( 738 scoped_ptr<WebRequestActionSet> action_set(
745 WebRequestActionSet::Create(NULL, NULL, actions, &error, &bad_message)); 739 WebRequestActionSet::Create(NULL, NULL, actions, &error, &bad_message));
746 ASSERT_TRUE(error.empty()) << error; 740 ASSERT_TRUE(error.empty()) << error;
747 ASSERT_FALSE(bad_message); 741 ASSERT_FALSE(bad_message);
748 ASSERT_TRUE(action_set); 742 ASSERT_TRUE(action_set);
749 743
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 // This is a correct match. 810 // This is a correct match.
817 GURL url2("http://foo.com/index.html"); 811 GURL url2("http://foo.com/index.html");
818 scoped_ptr<net::URLRequest> request2(context.CreateRequest( 812 scoped_ptr<net::URLRequest> request2(context.CreateRequest(
819 url2, net::DEFAULT_PRIORITY, NULL)); 813 url2, net::DEFAULT_PRIORITY, NULL));
820 WebRequestData request_data2(request2.get(), ON_BEFORE_REQUEST); 814 WebRequestData request_data2(request2.get(), ON_BEFORE_REQUEST);
821 deltas = registry->CreateDeltas(NULL, request_data2, false); 815 deltas = registry->CreateDeltas(NULL, request_data2, false);
822 EXPECT_EQ(1u, deltas.size()); 816 EXPECT_EQ(1u, deltas.size());
823 } 817 }
824 818
825 } // namespace extensions 819 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698