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_rules_
registry.h" | 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_
registry.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 rules.push_back(CreateRule1()); | 220 rules.push_back(CreateRule1()); |
221 rules.push_back(CreateRule2()); | 221 rules.push_back(CreateRule2()); |
222 | 222 |
223 error = registry->AddRules(kExtensionId, rules); | 223 error = registry->AddRules(kExtensionId, rules); |
224 EXPECT_EQ("", error); | 224 EXPECT_EQ("", error); |
225 EXPECT_EQ(1, registry->num_clear_cache_calls()); | 225 EXPECT_EQ(1, registry->num_clear_cache_calls()); |
226 | 226 |
227 std::set<WebRequestRule::GlobalRuleId> matches; | 227 std::set<WebRequestRule::GlobalRuleId> matches; |
228 | 228 |
229 GURL http_url("http://www.example.com"); | 229 GURL http_url("http://www.example.com"); |
230 TestURLRequestContext context; | 230 net::TestURLRequestContext context; |
231 TestURLRequest http_request(http_url, NULL, &context); | 231 net::TestURLRequest http_request(http_url, NULL, &context); |
232 matches = registry->GetMatches( | 232 matches = registry->GetMatches( |
233 WebRequestRule::RequestData(&http_request, ON_BEFORE_REQUEST)); | 233 WebRequestRule::RequestData(&http_request, ON_BEFORE_REQUEST)); |
234 EXPECT_EQ(2u, matches.size()); | 234 EXPECT_EQ(2u, matches.size()); |
235 EXPECT_TRUE(matches.find(std::make_pair(kExtensionId, kRuleId1)) != | 235 EXPECT_TRUE(matches.find(std::make_pair(kExtensionId, kRuleId1)) != |
236 matches.end()); | 236 matches.end()); |
237 EXPECT_TRUE(matches.find(std::make_pair(kExtensionId, kRuleId2)) != | 237 EXPECT_TRUE(matches.find(std::make_pair(kExtensionId, kRuleId2)) != |
238 matches.end()); | 238 matches.end()); |
239 | 239 |
240 GURL foobar_url("http://www.foobar.com"); | 240 GURL foobar_url("http://www.foobar.com"); |
241 TestURLRequest foobar_request(foobar_url, NULL, &context); | 241 net::TestURLRequest foobar_request(foobar_url, NULL, &context); |
242 matches = registry->GetMatches( | 242 matches = registry->GetMatches( |
243 WebRequestRule::RequestData(&foobar_request, ON_BEFORE_REQUEST)); | 243 WebRequestRule::RequestData(&foobar_request, ON_BEFORE_REQUEST)); |
244 EXPECT_EQ(1u, matches.size()); | 244 EXPECT_EQ(1u, matches.size()); |
245 EXPECT_TRUE(matches.find(std::make_pair(kExtensionId, kRuleId2)) != | 245 EXPECT_TRUE(matches.find(std::make_pair(kExtensionId, kRuleId2)) != |
246 matches.end()); | 246 matches.end()); |
247 } | 247 } |
248 | 248 |
249 TEST_F(WebRequestRulesRegistryTest, RemoveRulesImpl) { | 249 TEST_F(WebRequestRulesRegistryTest, RemoveRulesImpl) { |
250 scoped_refptr<TestWebRequestRulesRegistry> registry( | 250 scoped_refptr<TestWebRequestRulesRegistry> registry( |
251 new TestWebRequestRulesRegistry()); | 251 new TestWebRequestRulesRegistry()); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 rules_to_add_1[0] = CreateRedirectRule("http://www.foo.com"); | 352 rules_to_add_1[0] = CreateRedirectRule("http://www.foo.com"); |
353 error = registry->AddRules(kExtensionId, rules_to_add_1); | 353 error = registry->AddRules(kExtensionId, rules_to_add_1); |
354 EXPECT_EQ("", error); | 354 EXPECT_EQ("", error); |
355 | 355 |
356 std::vector<linked_ptr<RulesRegistry::Rule> > rules_to_add_2(1); | 356 std::vector<linked_ptr<RulesRegistry::Rule> > rules_to_add_2(1); |
357 rules_to_add_2[0] = CreateRedirectRule("http://www.bar.com"); | 357 rules_to_add_2[0] = CreateRedirectRule("http://www.bar.com"); |
358 error = registry->AddRules(kExtensionId2, rules_to_add_2); | 358 error = registry->AddRules(kExtensionId2, rules_to_add_2); |
359 EXPECT_EQ("", error); | 359 EXPECT_EQ("", error); |
360 | 360 |
361 GURL url("http://www.google.com"); | 361 GURL url("http://www.google.com"); |
362 TestURLRequestContext context; | 362 net::TestURLRequestContext context; |
363 TestURLRequest request(url, NULL, &context); | 363 net::TestURLRequest request(url, NULL, &context); |
364 std::list<LinkedPtrEventResponseDelta> deltas = | 364 std::list<LinkedPtrEventResponseDelta> deltas = |
365 registry->CreateDeltas( | 365 registry->CreateDeltas( |
366 NULL, | 366 NULL, |
367 WebRequestRule::RequestData(&request, ON_BEFORE_REQUEST), | 367 WebRequestRule::RequestData(&request, ON_BEFORE_REQUEST), |
368 false); | 368 false); |
369 | 369 |
370 // The second extension is installed later and will win for this reason | 370 // The second extension is installed later and will win for this reason |
371 // in conflict resolution. | 371 // in conflict resolution. |
372 ASSERT_EQ(2u, deltas.size()); | 372 ASSERT_EQ(2u, deltas.size()); |
373 deltas.sort(&helpers::InDecreasingExtensionInstallationTimeOrder); | 373 deltas.sort(&helpers::InDecreasingExtensionInstallationTimeOrder); |
(...skipping 28 matching lines...) Expand all Loading... |
402 rules_to_add_2[0] = CreateRedirectRule("http://www.bar.com"); | 402 rules_to_add_2[0] = CreateRedirectRule("http://www.bar.com"); |
403 error = registry->AddRules(kExtensionId2, rules_to_add_2); | 403 error = registry->AddRules(kExtensionId2, rules_to_add_2); |
404 EXPECT_EQ("", error); | 404 EXPECT_EQ("", error); |
405 | 405 |
406 std::vector<linked_ptr<RulesRegistry::Rule> > rules_to_add_3(1); | 406 std::vector<linked_ptr<RulesRegistry::Rule> > rules_to_add_3(1); |
407 rules_to_add_3[0] = CreateIgnoreRule(); | 407 rules_to_add_3[0] = CreateIgnoreRule(); |
408 error = registry->AddRules(kExtensionId, rules_to_add_3); | 408 error = registry->AddRules(kExtensionId, rules_to_add_3); |
409 EXPECT_EQ("", error); | 409 EXPECT_EQ("", error); |
410 | 410 |
411 GURL url("http://www.google.com/index.html"); | 411 GURL url("http://www.google.com/index.html"); |
412 TestURLRequestContext context; | 412 net::TestURLRequestContext context; |
413 TestURLRequest request(url, NULL, &context); | 413 net::TestURLRequest request(url, NULL, &context); |
414 std::list<LinkedPtrEventResponseDelta> deltas = | 414 std::list<LinkedPtrEventResponseDelta> deltas = |
415 registry->CreateDeltas( | 415 registry->CreateDeltas( |
416 NULL, | 416 NULL, |
417 WebRequestRule::RequestData(&request, ON_BEFORE_REQUEST), | 417 WebRequestRule::RequestData(&request, ON_BEFORE_REQUEST), |
418 false); | 418 false); |
419 | 419 |
420 // The redirect by the first extension is ignored due to the ignore rule. | 420 // The redirect by the first extension is ignored due to the ignore rule. |
421 ASSERT_EQ(1u, deltas.size()); | 421 ASSERT_EQ(1u, deltas.size()); |
422 LinkedPtrEventResponseDelta effective_rule = *(deltas.begin()); | 422 LinkedPtrEventResponseDelta effective_rule = *(deltas.begin()); |
423 | 423 |
424 EXPECT_EQ(kExtensionId2, effective_rule->extension_id); | 424 EXPECT_EQ(kExtensionId2, effective_rule->extension_id); |
425 EXPECT_EQ(base::Time() + base::TimeDelta::FromDays(2), | 425 EXPECT_EQ(base::Time() + base::TimeDelta::FromDays(2), |
426 effective_rule->extension_install_time); | 426 effective_rule->extension_install_time); |
427 EXPECT_EQ(GURL("http://www.bar.com"), effective_rule->new_url); | 427 EXPECT_EQ(GURL("http://www.bar.com"), effective_rule->new_url); |
428 } | 428 } |
429 } // namespace extensions | 429 } // namespace extensions |
OLD | NEW |