| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/declarative_rule.h" | 5 #include "chrome/browser/extensions/api/declarative/declarative_rule.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 7 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 8 #include "base/test/values_test_util.h" | 9 #include "base/test/values_test_util.h" |
| 9 #include "base/values.h" | 10 #include "base/values.h" |
| 10 #include "extensions/common/matcher/url_matcher_constants.h" | 11 #include "extensions/common/matcher/url_matcher_constants.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace extensions { | 15 namespace extensions { |
| 15 | 16 |
| 16 using base::test::ParseJson; | 17 using base::test::ParseJson; |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 " \"priority\": 200 \n" | 299 " \"priority\": 200 \n" |
| 299 "}"), | 300 "}"), |
| 300 json_rule.get())); | 301 json_rule.get())); |
| 301 | 302 |
| 302 const char kExtensionId[] = "ext1"; | 303 const char kExtensionId[] = "ext1"; |
| 303 | 304 |
| 304 base::Time install_time = base::Time::Now(); | 305 base::Time install_time = base::Time::Now(); |
| 305 | 306 |
| 306 URLMatcher matcher; | 307 URLMatcher matcher; |
| 307 std::string error; | 308 std::string error; |
| 308 scoped_ptr<Rule> rule(Rule::Create(matcher.condition_factory(), kExtensionId, | 309 scoped_ptr<Rule> rule(Rule::Create(matcher.condition_factory(), |
| 309 install_time, json_rule, NULL, &error)); | 310 kExtensionId, |
| 311 install_time, |
| 312 json_rule, |
| 313 Rule::ConsistencyChecker(), |
| 314 &error)); |
| 310 EXPECT_EQ("", error); | 315 EXPECT_EQ("", error); |
| 311 ASSERT_TRUE(rule.get()); | 316 ASSERT_TRUE(rule.get()); |
| 312 | 317 |
| 313 EXPECT_EQ(kExtensionId, rule->id().first); | 318 EXPECT_EQ(kExtensionId, rule->id().first); |
| 314 EXPECT_EQ("rule1", rule->id().second); | 319 EXPECT_EQ("rule1", rule->id().second); |
| 315 | 320 |
| 316 EXPECT_EQ(200, rule->priority()); | 321 EXPECT_EQ(200, rule->priority()); |
| 317 | 322 |
| 318 const Rule::ConditionSet& condition_set = rule->conditions(); | 323 const Rule::ConditionSet& condition_set = rule->conditions(); |
| 319 const Rule::ConditionSet::Conditions& conditions = | 324 const Rule::ConditionSet::Conditions& conditions = |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 " \"actions\": [ \n" | 365 " \"actions\": [ \n" |
| 361 " { \n" | 366 " { \n" |
| 362 " \"value\": 2 \n" | 367 " \"value\": 2 \n" |
| 363 " } \n" | 368 " } \n" |
| 364 " ], \n" | 369 " ], \n" |
| 365 " \"priority\": 200 \n" | 370 " \"priority\": 200 \n" |
| 366 "}"), | 371 "}"), |
| 367 json_rule.get())); | 372 json_rule.get())); |
| 368 scoped_ptr<Rule> rule( | 373 scoped_ptr<Rule> rule( |
| 369 Rule::Create(matcher.condition_factory(), kExtensionId, base::Time(), | 374 Rule::Create(matcher.condition_factory(), kExtensionId, base::Time(), |
| 370 json_rule, &AtLeastOneCondition, &error)); | 375 json_rule, base::Bind(AtLeastOneCondition), &error)); |
| 371 EXPECT_TRUE(rule); | 376 EXPECT_TRUE(rule); |
| 372 EXPECT_EQ("", error); | 377 EXPECT_EQ("", error); |
| 373 | 378 |
| 374 ASSERT_TRUE(Rule::JsonRule::Populate( | 379 ASSERT_TRUE(Rule::JsonRule::Populate( |
| 375 *ParseJson("{ \n" | 380 *ParseJson("{ \n" |
| 376 " \"id\": \"rule1\", \n" | 381 " \"id\": \"rule1\", \n" |
| 377 " \"conditions\": [ \n" | 382 " \"conditions\": [ \n" |
| 378 " ], \n" | 383 " ], \n" |
| 379 " \"actions\": [ \n" | 384 " \"actions\": [ \n" |
| 380 " { \n" | 385 " { \n" |
| 381 " \"value\": 2 \n" | 386 " \"value\": 2 \n" |
| 382 " } \n" | 387 " } \n" |
| 383 " ], \n" | 388 " ], \n" |
| 384 " \"priority\": 200 \n" | 389 " \"priority\": 200 \n" |
| 385 "}"), | 390 "}"), |
| 386 json_rule.get())); | 391 json_rule.get())); |
| 387 rule = Rule::Create(matcher.condition_factory(), kExtensionId, base::Time(), | 392 rule = Rule::Create(matcher.condition_factory(), kExtensionId, base::Time(), |
| 388 json_rule, &AtLeastOneCondition, &error); | 393 json_rule, base::Bind(AtLeastOneCondition), &error); |
| 389 EXPECT_FALSE(rule); | 394 EXPECT_FALSE(rule); |
| 390 EXPECT_EQ("No conditions", error); | 395 EXPECT_EQ("No conditions", error); |
| 391 } | 396 } |
| 392 | 397 |
| 393 } // namespace extensions | 398 } // namespace extensions |
| OLD | NEW |