OLD | NEW |
---|---|
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_condit ion.h" | 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit ion.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | |
8 | 9 |
9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
10 #include "base/test/values_test_util.h" | 11 #include "base/test/values_test_util.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta nts.h" | 13 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta nts.h" |
13 #include "chrome/common/extensions/matcher/url_matcher_constants.h" | 14 #include "chrome/common/extensions/matcher/url_matcher_constants.h" |
14 #include "content/public/browser/resource_request_info.h" | 15 #include "content/public/browser/resource_request_info.h" |
15 #include "net/url_request/url_request_test_util.h" | 16 #include "net/url_request/url_request_test_util.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 namespace extensions { | 19 namespace extensions { |
19 | 20 |
20 namespace keys = declarative_webrequest_constants; | 21 namespace keys = declarative_webrequest_constants; |
21 namespace keys2 = url_matcher_constants; | 22 namespace keys2 = url_matcher_constants; |
22 | 23 |
23 TEST(WebRequestConditionTest, CreateCondition) { | 24 TEST(WebRequestConditionTest, CreateCondition) { |
24 // Necessary for TestURLRequest. | 25 // Necessary for TestURLRequest. |
25 MessageLoop message_loop(MessageLoop::TYPE_IO); | 26 MessageLoop message_loop(MessageLoop::TYPE_IO); |
26 URLMatcher matcher; | 27 URLMatcher matcher; |
28 URLMatcher first_party_matcher; | |
27 | 29 |
28 std::string error; | 30 std::string error; |
29 scoped_ptr<WebRequestCondition> result; | 31 scoped_ptr<WebRequestCondition> result; |
30 | 32 |
33 std::vector<URLMatcherConditionFactory*> factories; | |
34 factories.push_back(matcher.condition_factory()); | |
35 factories.push_back(first_party_matcher.condition_factory()); | |
31 | 36 |
32 // Test wrong condition name passed. | 37 // Test wrong condition name passed. |
33 error.clear(); | 38 error.clear(); |
34 result = WebRequestCondition::Create( | 39 result = WebRequestCondition::Create( |
35 matcher.condition_factory(), | 40 factories, |
36 *base::test::ParseJson( | 41 *base::test::ParseJson( |
37 "{ \"invalid\": \"foobar\", \n" | 42 "{ \"invalid\": \"foobar\", \n" |
38 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" | 43 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" |
39 "}"), | 44 "}"), |
40 &error); | 45 &error); |
41 EXPECT_FALSE(error.empty()); | 46 EXPECT_FALSE(error.empty()); |
42 EXPECT_FALSE(result.get()); | 47 EXPECT_FALSE(result.get()); |
43 | 48 |
44 // Test wrong datatype in host_suffix. | 49 // Test wrong datatype in host_suffix. |
45 error.clear(); | 50 error.clear(); |
46 result = WebRequestCondition::Create( | 51 result = WebRequestCondition::Create( |
47 matcher.condition_factory(), | 52 factories, |
48 *base::test::ParseJson( | 53 *base::test::ParseJson( |
49 "{ \n" | 54 "{ \n" |
50 " \"url\": [], \n" | 55 " \"url\": [], \n" |
51 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" | 56 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" |
52 "}"), | 57 "}"), |
53 &error); | 58 &error); |
54 EXPECT_FALSE(error.empty()); | 59 EXPECT_FALSE(error.empty()); |
55 EXPECT_FALSE(result.get()); | 60 EXPECT_FALSE(result.get()); |
56 | 61 |
57 // Test success (can we support multiple criteria?) | 62 // Test success (can we support multiple criteria?) |
58 error.clear(); | 63 error.clear(); |
59 result = WebRequestCondition::Create( | 64 result = WebRequestCondition::Create( |
60 matcher.condition_factory(), | 65 factories, |
61 *base::test::ParseJson( | 66 *base::test::ParseJson( |
62 "{ \n" | 67 "{ \n" |
63 " \"resourceType\": [\"main_frame\"], \n" | 68 " \"resourceType\": [\"main_frame\"], \n" |
64 " \"url\": { \"hostSuffix\": \"example.com\" }, \n" | 69 " \"url\": { \"hostSuffix\": \"example.com\" }, \n" |
70 " \"firstPartyForCookiesUrl\": { \"hostPrefix\": \"fpfc\"}, \n" | |
65 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" | 71 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" |
66 "}"), | 72 "}"), |
67 &error); | 73 &error); |
68 EXPECT_EQ("", error); | 74 EXPECT_EQ("", error); |
69 ASSERT_TRUE(result.get()); | 75 ASSERT_TRUE(result.get()); |
70 | 76 |
71 URLMatcherConditionSet::Vector url_matcher_condition_set; | 77 URLMatcherConditionSet::Vector url_matcher_condition_set; |
72 result->GetURLMatcherConditionSets(&url_matcher_condition_set); | 78 result->GetURLMatcherConditionSets(&url_matcher_condition_set, 0); |
battre
2013/01/21 17:32:08
check return value? also after line 81?
also check
vabr (Chromium)
2013/01/21 18:39:29
Done.
| |
73 matcher.AddConditionSets(url_matcher_condition_set); | 79 matcher.AddConditionSets(url_matcher_condition_set); |
74 std::set<URLMatcherConditionSet::ID> url_match_ids; | 80 url_matcher_condition_set.clear(); |
81 result->GetURLMatcherConditionSets(&url_matcher_condition_set, 1); | |
82 first_party_matcher.AddConditionSets(url_matcher_condition_set); | |
75 | 83 |
76 net::TestURLRequestContext context; | 84 net::TestURLRequestContext context; |
77 GURL http_url("http://www.example.com"); | 85 GURL http_url("http://www.example.com"); |
86 GURL first_party_url("http://fpfc.example.com"); | |
78 net::TestURLRequest match_request(http_url, NULL, &context); | 87 net::TestURLRequest match_request(http_url, NULL, &context); |
79 url_match_ids = matcher.MatchURL(http_url); | 88 std::set<URLMatcherConditionSet::ID> url_match_ids = matcher.MatchURL( |
80 EXPECT_EQ(1u, url_match_ids.size()); | 89 http_url); |
battre
2013/01/21 17:32:08
nit: in my opinion a strange indentation
vabr (Chromium)
2013/01/21 18:39:29
Done. I was playing with the automatic indentation
| |
90 std::set<URLMatcherConditionSet::ID> first_party_url_match_ids = | |
91 first_party_matcher.MatchURL(first_party_url); | |
92 url_match_ids.insert(first_party_url_match_ids.begin(), | |
93 first_party_url_match_ids.end()); | |
94 EXPECT_EQ(2u, url_match_ids.size()); | |
81 content::ResourceRequestInfo::AllocateForTesting(&match_request, | 95 content::ResourceRequestInfo::AllocateForTesting(&match_request, |
82 ResourceType::MAIN_FRAME, NULL, -1, -1); | 96 ResourceType::MAIN_FRAME, NULL, -1, -1); |
83 EXPECT_TRUE(result->IsFulfilled( | 97 EXPECT_TRUE(result->IsFulfilled( |
84 url_match_ids, | 98 url_match_ids, |
85 DeclarativeWebRequestData(&match_request, ON_BEFORE_REQUEST))); | 99 DeclarativeWebRequestData(&match_request, ON_BEFORE_REQUEST))); |
86 | 100 |
87 GURL https_url("https://www.example.com"); | 101 GURL https_url("https://www.example.com"); |
88 net::TestURLRequest wrong_resource_type(https_url, NULL, &context); | 102 net::TestURLRequest wrong_resource_type(https_url, NULL, &context); |
89 url_match_ids = matcher.MatchURL(https_url); | 103 url_match_ids = matcher.MatchURL(https_url); |
104 url_match_ids.insert(first_party_url_match_ids.begin(), | |
105 first_party_url_match_ids.end()); | |
90 // Make sure IsFulfilled does not fail because of URL matching. | 106 // Make sure IsFulfilled does not fail because of URL matching. |
91 EXPECT_EQ(1u, url_match_ids.size()); | 107 EXPECT_EQ(2u, url_match_ids.size()); |
92 content::ResourceRequestInfo::AllocateForTesting(&wrong_resource_type, | 108 content::ResourceRequestInfo::AllocateForTesting(&wrong_resource_type, |
93 ResourceType::SUB_FRAME, NULL, -1, -1); | 109 ResourceType::SUB_FRAME, NULL, -1, -1); |
94 EXPECT_FALSE(result->IsFulfilled( | 110 EXPECT_FALSE(result->IsFulfilled( |
95 url_match_ids, | 111 url_match_ids, |
96 DeclarativeWebRequestData(&wrong_resource_type, ON_BEFORE_REQUEST))); | 112 DeclarativeWebRequestData(&wrong_resource_type, ON_BEFORE_REQUEST))); |
97 } | 113 } |
98 | 114 |
99 // Conditions without UrlFilter attributes need to be independent of URL | 115 // Conditions without UrlFilter attributes need to be independent of URL |
100 // matching results. We test here that: | 116 // matching results. We test here that: |
101 // 1. A non-empty condition without UrlFilter attributes is fulfilled iff its | 117 // 1. A non-empty condition without UrlFilter attributes is fulfilled iff its |
102 // attributes are fulfilled. | 118 // attributes are fulfilled. |
103 // 2. An empty condition (in particular, without UrlFilter attributes) is | 119 // 2. An empty condition (in particular, without UrlFilter attributes) is |
104 // always fulfilled. | 120 // always fulfilled. |
105 TEST(WebRequestConditionTest, NoUrlAttributes) { | 121 TEST(WebRequestConditionTest, NoUrlAttributes) { |
106 // Necessary for TestURLRequest. | 122 // Necessary for TestURLRequest. |
107 MessageLoop message_loop(MessageLoop::TYPE_IO); | 123 MessageLoop message_loop(MessageLoop::TYPE_IO); |
108 URLMatcher matcher; | 124 URLMatcher matcher; |
109 std::string error; | 125 std::string error; |
110 | 126 |
127 std::vector<URLMatcherConditionFactory*> factories; | |
128 factories.push_back(matcher.condition_factory()); | |
129 // The second factory is usually from a different matcher, but in this test | |
130 // we don't care, since we never use it. | |
131 factories.push_back(matcher.condition_factory()); | |
132 | |
111 // The empty condition. | 133 // The empty condition. |
112 error.clear(); | 134 error.clear(); |
113 scoped_ptr<WebRequestCondition> condition_empty = WebRequestCondition::Create( | 135 scoped_ptr<WebRequestCondition> condition_empty = WebRequestCondition::Create( |
114 matcher.condition_factory(), | 136 factories, |
115 *base::test::ParseJson( | 137 *base::test::ParseJson( |
116 "{ \n" | 138 "{ \n" |
117 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" | 139 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" |
118 "}"), | 140 "}"), |
119 &error); | 141 &error); |
120 EXPECT_EQ("", error); | 142 EXPECT_EQ("", error); |
121 ASSERT_TRUE(condition_empty.get()); | 143 ASSERT_TRUE(condition_empty.get()); |
122 | 144 |
123 // A condition without a UrlFilter attribute, which is always true. | 145 // A condition without a UrlFilter attribute, which is always true. |
124 error.clear(); | 146 error.clear(); |
125 scoped_ptr<WebRequestCondition> condition_no_url_true = | 147 scoped_ptr<WebRequestCondition> condition_no_url_true = |
126 WebRequestCondition::Create( | 148 WebRequestCondition::Create( |
127 matcher.condition_factory(), | 149 factories, |
128 *base::test::ParseJson( | 150 *base::test::ParseJson( |
129 "{ \n" | 151 "{ \n" |
130 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" | 152 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" |
131 // There is no "1st party for cookies" URL in the requests below, | 153 // There is no "1st party for cookies" URL in the requests below, |
132 // therefore all requests are considered first party for cookies. | 154 // therefore all requests are considered first party for cookies. |
133 " \"thirdPartyForCookies\": false, \n" | 155 " \"thirdPartyForCookies\": false, \n" |
134 "}"), | 156 "}"), |
135 &error); | 157 &error); |
136 EXPECT_EQ("", error); | 158 EXPECT_EQ("", error); |
137 ASSERT_TRUE(condition_no_url_true.get()); | 159 ASSERT_TRUE(condition_no_url_true.get()); |
138 | 160 |
139 // A condition without a UrlFilter attribute, which is always false. | 161 // A condition without a UrlFilter attribute, which is always false. |
140 error.clear(); | 162 error.clear(); |
141 scoped_ptr<WebRequestCondition> condition_no_url_false = | 163 scoped_ptr<WebRequestCondition> condition_no_url_false = |
142 WebRequestCondition::Create( | 164 WebRequestCondition::Create( |
143 matcher.condition_factory(), | 165 factories, |
144 *base::test::ParseJson( | 166 *base::test::ParseJson( |
145 "{ \n" | 167 "{ \n" |
146 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" | 168 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" |
147 " \"thirdPartyForCookies\": true, \n" | 169 " \"thirdPartyForCookies\": true, \n" |
148 "}"), | 170 "}"), |
149 &error); | 171 &error); |
150 EXPECT_EQ("", error); | 172 EXPECT_EQ("", error); |
151 ASSERT_TRUE(condition_no_url_false.get()); | 173 ASSERT_TRUE(condition_no_url_false.get()); |
152 | 174 |
153 net::TestURLRequestContext context; | 175 net::TestURLRequestContext context; |
(...skipping 16 matching lines...) Expand all Loading... | |
170 EXPECT_TRUE(condition_empty->IsFulfilled( | 192 EXPECT_TRUE(condition_empty->IsFulfilled( |
171 dummy_match_set, | 193 dummy_match_set, |
172 DeclarativeWebRequestData(&https_request, ON_BEFORE_REQUEST))); | 194 DeclarativeWebRequestData(&https_request, ON_BEFORE_REQUEST))); |
173 } | 195 } |
174 | 196 |
175 TEST(WebRequestConditionTest, CreateConditionSet) { | 197 TEST(WebRequestConditionTest, CreateConditionSet) { |
176 // Necessary for TestURLRequest. | 198 // Necessary for TestURLRequest. |
177 MessageLoop message_loop(MessageLoop::TYPE_IO); | 199 MessageLoop message_loop(MessageLoop::TYPE_IO); |
178 URLMatcher matcher; | 200 URLMatcher matcher; |
179 | 201 |
202 std::vector<URLMatcherConditionFactory*> factories; | |
203 factories.push_back(matcher.condition_factory()); | |
204 // The second factory is usually from a different matcher, but in this test | |
205 // we don't care, since we never use it. | |
206 factories.push_back(matcher.condition_factory()); | |
207 | |
180 WebRequestConditionSet::AnyVector conditions; | 208 WebRequestConditionSet::AnyVector conditions; |
181 conditions.push_back(linked_ptr<base::Value>(base::test::ParseJson( | 209 conditions.push_back(linked_ptr<base::Value>(base::test::ParseJson( |
182 "{ \n" | 210 "{ \n" |
183 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" | 211 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" |
184 " \"url\": { \n" | 212 " \"url\": { \n" |
185 " \"hostSuffix\": \"example.com\", \n" | 213 " \"hostSuffix\": \"example.com\", \n" |
186 " \"schemes\": [\"http\"], \n" | 214 " \"schemes\": [\"http\"], \n" |
187 " }, \n" | 215 " }, \n" |
188 "}").release())); | 216 "}").release())); |
189 conditions.push_back(linked_ptr<base::Value>(base::test::ParseJson( | 217 conditions.push_back(linked_ptr<base::Value>(base::test::ParseJson( |
190 "{ \n" | 218 "{ \n" |
191 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" | 219 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" |
192 " \"url\": { \n" | 220 " \"url\": { \n" |
193 " \"hostSuffix\": \"example.com\", \n" | 221 " \"hostSuffix\": \"example.com\", \n" |
194 " \"hostPrefix\": \"www\", \n" | 222 " \"hostPrefix\": \"www\", \n" |
195 " \"schemes\": [\"https\"], \n" | 223 " \"schemes\": [\"https\"], \n" |
196 " }, \n" | 224 " }, \n" |
197 "}").release())); | 225 "}").release())); |
198 | 226 |
199 // Test insertion | 227 // Test insertion |
200 std::string error; | 228 std::string error; |
201 scoped_ptr<WebRequestConditionSet> result = | 229 scoped_ptr<WebRequestConditionSet> result = |
202 WebRequestConditionSet::Create(matcher.condition_factory(), | 230 WebRequestConditionSet::Create(factories, conditions, &error); |
203 conditions, &error); | |
204 EXPECT_EQ("", error); | 231 EXPECT_EQ("", error); |
205 ASSERT_TRUE(result.get()); | 232 ASSERT_TRUE(result.get()); |
206 EXPECT_EQ(2u, result->conditions().size()); | 233 EXPECT_EQ(2u, result->conditions().size()); |
207 | 234 |
208 // Tell the URLMatcher about our shiny new patterns. | 235 // Tell the URLMatcher about our shiny new patterns. |
209 URLMatcherConditionSet::Vector url_matcher_condition_set; | 236 URLMatcherConditionSet::Vector url_matcher_condition_set; |
210 result->GetURLMatcherConditionSets(&url_matcher_condition_set); | 237 result->GetURLMatcherConditionSets(&url_matcher_condition_set, 0); |
211 matcher.AddConditionSets(url_matcher_condition_set); | 238 matcher.AddConditionSets(url_matcher_condition_set); |
212 | 239 |
213 std::set<URLMatcherConditionSet::ID> url_match_ids; | 240 std::set<URLMatcherConditionSet::ID> url_match_ids; |
214 | 241 |
215 // Test that the result is correct and matches http://www.example.com and | 242 // Test that the result is correct and matches http://www.example.com and |
216 // https://www.example.com | 243 // https://www.example.com |
217 GURL http_url("http://www.example.com"); | 244 GURL http_url("http://www.example.com"); |
218 net::TestURLRequestContext context; | 245 net::TestURLRequestContext context; |
219 net::TestURLRequest http_request(http_url, NULL, &context); | 246 net::TestURLRequest http_request(http_url, NULL, &context); |
220 url_match_ids = matcher.MatchURL(http_url); | 247 url_match_ids = matcher.MatchURL(http_url); |
(...skipping 21 matching lines...) Expand all Loading... | |
242 -1, | 269 -1, |
243 url_match_ids, | 270 url_match_ids, |
244 DeclarativeWebRequestData(&https_foo_request, ON_BEFORE_REQUEST))); | 271 DeclarativeWebRequestData(&https_foo_request, ON_BEFORE_REQUEST))); |
245 } | 272 } |
246 | 273 |
247 TEST(WebRequestConditionTest, TestPortFilter) { | 274 TEST(WebRequestConditionTest, TestPortFilter) { |
248 // Necessary for TestURLRequest. | 275 // Necessary for TestURLRequest. |
249 MessageLoop message_loop(MessageLoop::TYPE_IO); | 276 MessageLoop message_loop(MessageLoop::TYPE_IO); |
250 URLMatcher matcher; | 277 URLMatcher matcher; |
251 | 278 |
279 std::vector<URLMatcherConditionFactory*> factories; | |
280 factories.push_back(matcher.condition_factory()); | |
281 // The second factory is usually from a different matcher, but in this test | |
282 // we don't care, since we never use it. | |
283 factories.push_back(matcher.condition_factory()); | |
284 | |
252 WebRequestConditionSet::AnyVector conditions; | 285 WebRequestConditionSet::AnyVector conditions; |
253 conditions.push_back(linked_ptr<base::Value>(base::test::ParseJson( | 286 conditions.push_back(linked_ptr<base::Value>(base::test::ParseJson( |
254 "{ \n" | 287 "{ \n" |
255 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" | 288 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" |
256 " \"url\": { \n" | 289 " \"url\": { \n" |
257 " \"ports\": [80, [1000, 1010]], \n" // Allow 80;1000-1010. | 290 " \"ports\": [80, [1000, 1010]], \n" // Allow 80;1000-1010. |
258 " \"hostSuffix\": \"example.com\", \n" | 291 " \"hostSuffix\": \"example.com\", \n" |
259 " }, \n" | 292 " }, \n" |
260 "}").release())); | 293 "}").release())); |
261 | 294 |
262 // Test insertion | 295 // Test insertion |
263 std::string error; | 296 std::string error; |
264 scoped_ptr<WebRequestConditionSet> result = | 297 scoped_ptr<WebRequestConditionSet> result = |
265 WebRequestConditionSet::Create(matcher.condition_factory(), | 298 WebRequestConditionSet::Create(factories, conditions, &error); |
266 conditions, &error); | |
267 EXPECT_EQ("", error); | 299 EXPECT_EQ("", error); |
268 ASSERT_TRUE(result.get()); | 300 ASSERT_TRUE(result.get()); |
269 EXPECT_EQ(1u, result->conditions().size()); | 301 EXPECT_EQ(1u, result->conditions().size()); |
270 | 302 |
271 // Tell the URLMatcher about our shiny new patterns. | 303 // Tell the URLMatcher about our shiny new patterns. |
272 URLMatcherConditionSet::Vector url_matcher_condition_set; | 304 URLMatcherConditionSet::Vector url_matcher_condition_set; |
273 result->GetURLMatcherConditionSets(&url_matcher_condition_set); | 305 result->GetURLMatcherConditionSets(&url_matcher_condition_set, 0); |
274 matcher.AddConditionSets(url_matcher_condition_set); | 306 matcher.AddConditionSets(url_matcher_condition_set); |
275 | 307 |
276 std::set<URLMatcherConditionSet::ID> url_match_ids; | 308 std::set<URLMatcherConditionSet::ID> url_match_ids; |
277 | 309 |
278 // Test various URLs. | 310 // Test various URLs. |
279 GURL http_url("http://www.example.com"); | 311 GURL http_url("http://www.example.com"); |
280 net::TestURLRequestContext context; | 312 net::TestURLRequestContext context; |
281 net::TestURLRequest http_request(http_url, NULL, &context); | 313 net::TestURLRequest http_request(http_url, NULL, &context); |
282 url_match_ids = matcher.MatchURL(http_url); | 314 url_match_ids = matcher.MatchURL(http_url); |
283 ASSERT_EQ(1u, url_match_ids.size()); | 315 ASSERT_EQ(1u, url_match_ids.size()); |
(...skipping 18 matching lines...) Expand all Loading... | |
302 // the response header. The Create() method should fail and complain that it is | 334 // the response header. The Create() method should fail and complain that it is |
303 // impossible that both conditions are fulfilled at the same time. | 335 // impossible that both conditions are fulfilled at the same time. |
304 TEST(WebRequestConditionTest, ConditionsWithConflictingStages) { | 336 TEST(WebRequestConditionTest, ConditionsWithConflictingStages) { |
305 // Necessary for TestURLRequest. | 337 // Necessary for TestURLRequest. |
306 MessageLoop message_loop(MessageLoop::TYPE_IO); | 338 MessageLoop message_loop(MessageLoop::TYPE_IO); |
307 URLMatcher matcher; | 339 URLMatcher matcher; |
308 | 340 |
309 std::string error; | 341 std::string error; |
310 scoped_ptr<WebRequestCondition> result; | 342 scoped_ptr<WebRequestCondition> result; |
311 | 343 |
312 DictionaryValue condition_value; | 344 std::vector<URLMatcherConditionFactory*> factories; |
313 condition_value.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType); | 345 factories.push_back(matcher.condition_factory()); |
314 | 346 // The second factory is usually from a different matcher, but in this test |
347 // we don't care, since we never use it. | |
348 factories.push_back(matcher.condition_factory()); | |
315 | 349 |
316 // Test error on incompatible application stages for involved attributes. | 350 // Test error on incompatible application stages for involved attributes. |
317 error.clear(); | 351 error.clear(); |
318 result = WebRequestCondition::Create( | 352 result = WebRequestCondition::Create( |
319 matcher.condition_factory(), | 353 factories, |
320 *base::test::ParseJson( | 354 *base::test::ParseJson( |
321 "{ \n" | 355 "{ \n" |
322 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" | 356 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" |
323 // Pass a JS array with one empty object to each of the header | 357 // Pass a JS array with one empty object to each of the header |
324 // filters. | 358 // filters. |
325 " \"requestHeaders\": [{}], \n" | 359 " \"requestHeaders\": [{}], \n" |
326 " \"responseHeaders\": [{}], \n" | 360 " \"responseHeaders\": [{}], \n" |
327 "}"), | 361 "}"), |
328 &error); | 362 &error); |
329 EXPECT_FALSE(error.empty()); | 363 EXPECT_FALSE(error.empty()); |
330 EXPECT_FALSE(result.get()); | 364 EXPECT_FALSE(result.get()); |
331 } | 365 } |
332 | 366 |
333 } // namespace extensions | 367 } // namespace extensions |
OLD | NEW |