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

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

Issue 16915006: Convert most of extensions and some other random stuff to using the base namespace for Values. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
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_webrequest/webrequest_rules_ registry.h" 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 virtual void SetUp() OVERRIDE; 86 virtual void SetUp() OVERRIDE;
87 87
88 virtual void TearDown() OVERRIDE { 88 virtual void TearDown() OVERRIDE {
89 // Make sure that deletion traits of all registries are executed. 89 // Make sure that deletion traits of all registries are executed.
90 message_loop_.RunUntilIdle(); 90 message_loop_.RunUntilIdle();
91 } 91 }
92 92
93 // Returns a rule that roughly matches http://*.example.com and 93 // Returns a rule that roughly matches http://*.example.com and
94 // https://www.example.com and cancels it 94 // https://www.example.com and cancels it
95 linked_ptr<RulesRegistry::Rule> CreateRule1() { 95 linked_ptr<RulesRegistry::Rule> CreateRule1() {
96 ListValue* scheme_http = new ListValue(); 96 base::ListValue* scheme_http = new base::ListValue();
97 scheme_http->Append(Value::CreateStringValue("http")); 97 scheme_http->Append(Value::CreateStringValue("http"));
98 DictionaryValue* http_condition_dict = new DictionaryValue(); 98 base::DictionaryValue* http_condition_dict = new base::DictionaryValue();
99 http_condition_dict->Set(keys2::kSchemesKey, scheme_http); 99 http_condition_dict->Set(keys2::kSchemesKey, scheme_http);
100 http_condition_dict->SetString(keys2::kHostSuffixKey, "example.com"); 100 http_condition_dict->SetString(keys2::kHostSuffixKey, "example.com");
101 DictionaryValue http_condition_url_filter; 101 base::DictionaryValue http_condition_url_filter;
102 http_condition_url_filter.Set(keys::kUrlKey, http_condition_dict); 102 http_condition_url_filter.Set(keys::kUrlKey, http_condition_dict);
103 http_condition_url_filter.SetString(keys::kInstanceTypeKey, 103 http_condition_url_filter.SetString(keys::kInstanceTypeKey,
104 keys::kRequestMatcherType); 104 keys::kRequestMatcherType);
105 105
106 ListValue* scheme_https = new ListValue(); 106 base::ListValue* scheme_https = new base::ListValue();
107 scheme_http->Append(Value::CreateStringValue("https")); 107 scheme_http->Append(Value::CreateStringValue("https"));
108 DictionaryValue* https_condition_dict = new DictionaryValue(); 108 base::DictionaryValue* https_condition_dict = new base::DictionaryValue();
109 https_condition_dict->Set(keys2::kSchemesKey, scheme_https); 109 https_condition_dict->Set(keys2::kSchemesKey, scheme_https);
110 https_condition_dict->SetString(keys2::kHostSuffixKey, "example.com"); 110 https_condition_dict->SetString(keys2::kHostSuffixKey, "example.com");
111 https_condition_dict->SetString(keys2::kHostPrefixKey, "www"); 111 https_condition_dict->SetString(keys2::kHostPrefixKey, "www");
112 DictionaryValue https_condition_url_filter; 112 base::DictionaryValue https_condition_url_filter;
113 https_condition_url_filter.Set(keys::kUrlKey, https_condition_dict); 113 https_condition_url_filter.Set(keys::kUrlKey, https_condition_dict);
114 https_condition_url_filter.SetString(keys::kInstanceTypeKey, 114 https_condition_url_filter.SetString(keys::kInstanceTypeKey,
115 keys::kRequestMatcherType); 115 keys::kRequestMatcherType);
116 116
117 DictionaryValue action_dict; 117 base::DictionaryValue action_dict;
118 action_dict.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType); 118 action_dict.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType);
119 119
120 linked_ptr<RulesRegistry::Rule> rule(new RulesRegistry::Rule); 120 linked_ptr<RulesRegistry::Rule> rule(new RulesRegistry::Rule);
121 rule->id.reset(new std::string(kRuleId1)); 121 rule->id.reset(new std::string(kRuleId1));
122 rule->priority.reset(new int(100)); 122 rule->priority.reset(new int(100));
123 rule->actions.push_back(linked_ptr<base::Value>(action_dict.DeepCopy())); 123 rule->actions.push_back(linked_ptr<base::Value>(action_dict.DeepCopy()));
124 rule->conditions.push_back( 124 rule->conditions.push_back(
125 linked_ptr<base::Value>(http_condition_url_filter.DeepCopy())); 125 linked_ptr<base::Value>(http_condition_url_filter.DeepCopy()));
126 rule->conditions.push_back( 126 rule->conditions.push_back(
127 linked_ptr<base::Value>(https_condition_url_filter.DeepCopy())); 127 linked_ptr<base::Value>(https_condition_url_filter.DeepCopy()));
128 return rule; 128 return rule;
129 } 129 }
130 130
131 // Returns a rule that matches anything and cancels it. 131 // Returns a rule that matches anything and cancels it.
132 linked_ptr<RulesRegistry::Rule> CreateRule2() { 132 linked_ptr<RulesRegistry::Rule> CreateRule2() {
133 DictionaryValue condition_dict; 133 base::DictionaryValue condition_dict;
134 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType); 134 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType);
135 135
136 DictionaryValue action_dict; 136 base::DictionaryValue action_dict;
137 action_dict.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType); 137 action_dict.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType);
138 138
139 linked_ptr<RulesRegistry::Rule> rule(new RulesRegistry::Rule); 139 linked_ptr<RulesRegistry::Rule> rule(new RulesRegistry::Rule);
140 rule->id.reset(new std::string(kRuleId2)); 140 rule->id.reset(new std::string(kRuleId2));
141 rule->priority.reset(new int(100)); 141 rule->priority.reset(new int(100));
142 rule->actions.push_back(linked_ptr<base::Value>(action_dict.DeepCopy())); 142 rule->actions.push_back(linked_ptr<base::Value>(action_dict.DeepCopy()));
143 rule->conditions.push_back( 143 rule->conditions.push_back(
144 linked_ptr<base::Value>(condition_dict.DeepCopy())); 144 linked_ptr<base::Value>(condition_dict.DeepCopy()));
145 return rule; 145 return rule;
146 } 146 }
147 147
148 linked_ptr<RulesRegistry::Rule> CreateRedirectRule( 148 linked_ptr<RulesRegistry::Rule> CreateRedirectRule(
149 const std::string& destination) { 149 const std::string& destination) {
150 DictionaryValue condition_dict; 150 base::DictionaryValue condition_dict;
151 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType); 151 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType);
152 152
153 DictionaryValue action_dict; 153 base::DictionaryValue action_dict;
154 action_dict.SetString(keys::kInstanceTypeKey, keys::kRedirectRequestType); 154 action_dict.SetString(keys::kInstanceTypeKey, keys::kRedirectRequestType);
155 action_dict.SetString(keys::kRedirectUrlKey, destination); 155 action_dict.SetString(keys::kRedirectUrlKey, destination);
156 156
157 linked_ptr<RulesRegistry::Rule> rule(new RulesRegistry::Rule); 157 linked_ptr<RulesRegistry::Rule> rule(new RulesRegistry::Rule);
158 rule->id.reset(new std::string(kRuleId3)); 158 rule->id.reset(new std::string(kRuleId3));
159 rule->priority.reset(new int(100)); 159 rule->priority.reset(new int(100));
160 rule->actions.push_back(linked_ptr<base::Value>(action_dict.DeepCopy())); 160 rule->actions.push_back(linked_ptr<base::Value>(action_dict.DeepCopy()));
161 rule->conditions.push_back( 161 rule->conditions.push_back(
162 linked_ptr<base::Value>(condition_dict.DeepCopy())); 162 linked_ptr<base::Value>(condition_dict.DeepCopy()));
163 return rule; 163 return rule;
164 } 164 }
165 165
166 // Create a rule to ignore all other rules for a destination that 166 // Create a rule to ignore all other rules for a destination that
167 // contains index.html. 167 // contains index.html.
168 linked_ptr<RulesRegistry::Rule> CreateIgnoreRule() { 168 linked_ptr<RulesRegistry::Rule> CreateIgnoreRule() {
169 DictionaryValue condition_dict; 169 base::DictionaryValue condition_dict;
170 DictionaryValue* http_condition_dict = new DictionaryValue(); 170 base::DictionaryValue* http_condition_dict = new base::DictionaryValue();
171 http_condition_dict->SetString(keys2::kPathContainsKey, "index.html"); 171 http_condition_dict->SetString(keys2::kPathContainsKey, "index.html");
172 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType); 172 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType);
173 condition_dict.Set(keys::kUrlKey, http_condition_dict); 173 condition_dict.Set(keys::kUrlKey, http_condition_dict);
174 174
175 DictionaryValue action_dict; 175 base::DictionaryValue action_dict;
176 action_dict.SetString(keys::kInstanceTypeKey, keys::kIgnoreRulesType); 176 action_dict.SetString(keys::kInstanceTypeKey, keys::kIgnoreRulesType);
177 action_dict.SetInteger(keys::kLowerPriorityThanKey, 150); 177 action_dict.SetInteger(keys::kLowerPriorityThanKey, 150);
178 178
179 linked_ptr<RulesRegistry::Rule> rule(new RulesRegistry::Rule); 179 linked_ptr<RulesRegistry::Rule> rule(new RulesRegistry::Rule);
180 rule->id.reset(new std::string(kRuleId4)); 180 rule->id.reset(new std::string(kRuleId4));
181 rule->priority.reset(new int(200)); 181 rule->priority.reset(new int(200));
182 rule->actions.push_back(linked_ptr<base::Value>(action_dict.DeepCopy())); 182 rule->actions.push_back(linked_ptr<base::Value>(action_dict.DeepCopy()));
183 rule->conditions.push_back( 183 rule->conditions.push_back(
184 linked_ptr<base::Value>(condition_dict.DeepCopy())); 184 linked_ptr<base::Value>(condition_dict.DeepCopy()));
185 return rule; 185 return rule;
(...skipping 11 matching lines...) Expand all
197 return linked_ptr<base::Value>( 197 return linked_ptr<base::Value>(
198 base::test::ParseJson(json_description).release()); 198 base::test::ParseJson(json_description).release());
199 } 199 }
200 200
201 // 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
202 // |attributes| specified (one entry one condition). An example value of a 202 // |attributes| specified (one entry one condition). An example value of a
203 // string from |attributes| is: "\"resourceType\": [\"stylesheet\"], \n". 203 // string from |attributes| is: "\"resourceType\": [\"stylesheet\"], \n".
204 linked_ptr<RulesRegistry::Rule> CreateCancellingRule( 204 linked_ptr<RulesRegistry::Rule> CreateCancellingRule(
205 const char* rule_id, 205 const char* rule_id,
206 const std::vector<const std::string*>& attributes) { 206 const std::vector<const std::string*>& attributes) {
207 DictionaryValue action_dict; 207 base::DictionaryValue action_dict;
208 action_dict.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType); 208 action_dict.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType);
209 209
210 linked_ptr<RulesRegistry::Rule> rule(new RulesRegistry::Rule); 210 linked_ptr<RulesRegistry::Rule> rule(new RulesRegistry::Rule);
211 rule->id.reset(new std::string(rule_id)); 211 rule->id.reset(new std::string(rule_id));
212 rule->priority.reset(new int(1)); 212 rule->priority.reset(new int(1));
213 rule->actions.push_back(linked_ptr<base::Value>(action_dict.DeepCopy())); 213 rule->actions.push_back(linked_ptr<base::Value>(action_dict.DeepCopy()));
214 for (std::vector<const std::string*>::const_iterator it = 214 for (std::vector<const std::string*>::const_iterator it =
215 attributes.begin(); 215 attributes.begin();
216 it != attributes.end(); ++it) 216 it != attributes.end(); ++it)
217 rule->conditions.push_back(CreateCondition(**it)); 217 rule->conditions.push_back(CreateCondition(**it));
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 794
795 // This is a correct match. 795 // This is a correct match.
796 GURL url2("http://foo.com/index.html"); 796 GURL url2("http://foo.com/index.html");
797 net::TestURLRequest request2(url2, NULL, &context, NULL); 797 net::TestURLRequest request2(url2, NULL, &context, NULL);
798 WebRequestData request_data2(&request2, ON_BEFORE_REQUEST); 798 WebRequestData request_data2(&request2, ON_BEFORE_REQUEST);
799 deltas = registry->CreateDeltas(NULL, request_data2, false); 799 deltas = registry->CreateDeltas(NULL, request_data2, false);
800 EXPECT_EQ(1u, deltas.size()); 800 EXPECT_EQ(1u, deltas.size());
801 } 801 }
802 802
803 } // namespace extensions 803 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698