| 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 "extensions/browser/api/declarative_webrequest/webrequest_action.h" | 5 #include "extensions/browser/api/declarative_webrequest/webrequest_action.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 scoped_ptr<base::Value> parsed_value(base::test::ParseJson(json)); | 47 scoped_ptr<base::Value> parsed_value(base::test::ParseJson(json)); |
| 48 const base::ListValue* parsed_list; | 48 const base::ListValue* parsed_list; |
| 49 CHECK(parsed_value->GetAsList(&parsed_list)); | 49 CHECK(parsed_value->GetAsList(&parsed_list)); |
| 50 | 50 |
| 51 WebRequestActionSet::Values actions; | 51 WebRequestActionSet::Values actions; |
| 52 for (base::ListValue::const_iterator it = parsed_list->begin(); | 52 for (base::ListValue::const_iterator it = parsed_list->begin(); |
| 53 it != parsed_list->end(); | 53 it != parsed_list->end(); |
| 54 ++it) { | 54 ++it) { |
| 55 const base::DictionaryValue* dict; | 55 const base::DictionaryValue* dict; |
| 56 CHECK((*it)->GetAsDictionary(&dict)); | 56 CHECK((*it)->GetAsDictionary(&dict)); |
| 57 actions.push_back(linked_ptr<base::Value>(dict->DeepCopy())); | 57 actions.push_back(dict->CreateDeepCopy()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 std::string error; | 60 std::string error; |
| 61 bool bad_message = false; | 61 bool bad_message = false; |
| 62 | 62 |
| 63 scoped_ptr<WebRequestActionSet> action_set( | 63 scoped_ptr<WebRequestActionSet> action_set( |
| 64 WebRequestActionSet::Create(NULL, NULL, actions, &error, &bad_message)); | 64 WebRequestActionSet::Create(NULL, NULL, actions, &error, &bad_message)); |
| 65 EXPECT_EQ("", error); | 65 EXPECT_EQ("", error); |
| 66 EXPECT_FALSE(bad_message); | 66 EXPECT_FALSE(bad_message); |
| 67 CHECK(action_set); | 67 CHECK(action_set); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 EXPECT_TRUE(result->actions().empty()); | 235 EXPECT_TRUE(result->actions().empty()); |
| 236 EXPECT_EQ(std::numeric_limits<int>::min(), result->GetMinimumPriority()); | 236 EXPECT_EQ(std::numeric_limits<int>::min(), result->GetMinimumPriority()); |
| 237 | 237 |
| 238 base::DictionaryValue correct_action; | 238 base::DictionaryValue correct_action; |
| 239 correct_action.SetString(keys::kInstanceTypeKey, keys::kIgnoreRulesType); | 239 correct_action.SetString(keys::kInstanceTypeKey, keys::kIgnoreRulesType); |
| 240 correct_action.SetInteger(keys::kLowerPriorityThanKey, 10); | 240 correct_action.SetInteger(keys::kLowerPriorityThanKey, 10); |
| 241 base::DictionaryValue incorrect_action; | 241 base::DictionaryValue incorrect_action; |
| 242 incorrect_action.SetString(keys::kInstanceTypeKey, kUnknownActionType); | 242 incorrect_action.SetString(keys::kInstanceTypeKey, kUnknownActionType); |
| 243 | 243 |
| 244 // Test success. | 244 // Test success. |
| 245 input.push_back(linked_ptr<base::Value>(correct_action.DeepCopy())); | 245 input.push_back(correct_action.CreateDeepCopy()); |
| 246 error.clear(); | 246 error.clear(); |
| 247 result = WebRequestActionSet::Create(NULL, NULL, input, &error, &bad_message); | 247 result = WebRequestActionSet::Create(NULL, NULL, input, &error, &bad_message); |
| 248 EXPECT_TRUE(error.empty()) << error; | 248 EXPECT_TRUE(error.empty()) << error; |
| 249 EXPECT_FALSE(bad_message); | 249 EXPECT_FALSE(bad_message); |
| 250 ASSERT_TRUE(result.get()); | 250 ASSERT_TRUE(result.get()); |
| 251 ASSERT_EQ(1u, result->actions().size()); | 251 ASSERT_EQ(1u, result->actions().size()); |
| 252 EXPECT_EQ(WebRequestAction::ACTION_IGNORE_RULES, | 252 EXPECT_EQ(WebRequestAction::ACTION_IGNORE_RULES, |
| 253 result->actions()[0]->type()); | 253 result->actions()[0]->type()); |
| 254 EXPECT_EQ(10, result->GetMinimumPriority()); | 254 EXPECT_EQ(10, result->GetMinimumPriority()); |
| 255 | 255 |
| 256 // Test failure. | 256 // Test failure. |
| 257 input.push_back(linked_ptr<base::Value>(incorrect_action.DeepCopy())); | 257 input.push_back(incorrect_action.CreateDeepCopy()); |
| 258 error.clear(); | 258 error.clear(); |
| 259 result = WebRequestActionSet::Create(NULL, NULL, input, &error, &bad_message); | 259 result = WebRequestActionSet::Create(NULL, NULL, input, &error, &bad_message); |
| 260 EXPECT_NE("", error); | 260 EXPECT_NE("", error); |
| 261 EXPECT_FALSE(result.get()); | 261 EXPECT_FALSE(result.get()); |
| 262 } | 262 } |
| 263 | 263 |
| 264 // Test capture group syntax conversions of WebRequestRedirectByRegExAction | 264 // Test capture group syntax conversions of WebRequestRedirectByRegExAction |
| 265 TEST(WebRequestActionTest, PerlToRe2Style) { | 265 TEST(WebRequestActionTest, PerlToRe2Style) { |
| 266 #define CallPerlToRe2Style WebRequestRedirectByRegExAction::PerlToRe2Style | 266 #define CallPerlToRe2Style WebRequestRedirectByRegExAction::PerlToRe2Style |
| 267 // foo$1bar -> foo\1bar | 267 // foo$1bar -> foo\1bar |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 for (WebRequestActionSet::Actions::const_iterator it = | 586 for (WebRequestActionSet::Actions::const_iterator it = |
| 587 action_set->actions().begin(); | 587 action_set->actions().begin(); |
| 588 it != action_set->actions().end(); | 588 it != action_set->actions().end(); |
| 589 ++it) { | 589 ++it) { |
| 590 EXPECT_EQ(kExpectedNames[index], (*it)->GetName()); | 590 EXPECT_EQ(kExpectedNames[index], (*it)->GetName()); |
| 591 ++index; | 591 ++index; |
| 592 } | 592 } |
| 593 } | 593 } |
| 594 | 594 |
| 595 } // namespace extensions | 595 } // namespace extensions |
| OLD | NEW |