| 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_condition_att
ribute.h" | 5 #include "extensions/browser/api/declarative_webrequest/webrequest_condition_att
ribute.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> |
| 10 | 11 |
| 11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "content/public/browser/resource_request_info.h" | 16 #include "content/public/browser/resource_request_info.h" |
| 16 #include "extensions/browser/api/declarative_webrequest/webrequest_condition.h" | 17 #include "extensions/browser/api/declarative_webrequest/webrequest_condition.h" |
| 17 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" | 18 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" |
| 18 #include "net/base/request_priority.h" | 19 #include "net/base/request_priority.h" |
| 19 #include "net/test/embedded_test_server/embedded_test_server.h" | 20 #include "net/test/embedded_test_server/embedded_test_server.h" |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 std::unique_ptr<base::Value> entry_owned; | 382 std::unique_ptr<base::Value> entry_owned; |
| 382 base::ListValue* list = NULL; | 383 base::ListValue* list = NULL; |
| 383 if (!dictionary->GetWithoutPathExpansion(*name, &entry)) | 384 if (!dictionary->GetWithoutPathExpansion(*name, &entry)) |
| 384 return std::unique_ptr<base::DictionaryValue>(); | 385 return std::unique_ptr<base::DictionaryValue>(); |
| 385 switch (entry->GetType()) { | 386 switch (entry->GetType()) { |
| 386 case base::Value::TYPE_STRING: | 387 case base::Value::TYPE_STRING: |
| 387 // Replace the present string with a list. | 388 // Replace the present string with a list. |
| 388 list = new base::ListValue; | 389 list = new base::ListValue; |
| 389 // Ignoring return value, we already verified the entry is there. | 390 // Ignoring return value, we already verified the entry is there. |
| 390 dictionary->RemoveWithoutPathExpansion(*name, &entry_owned); | 391 dictionary->RemoveWithoutPathExpansion(*name, &entry_owned); |
| 391 list->Append(entry_owned.release()); | 392 list->Append(std::move(entry_owned)); |
| 392 list->AppendString(*value); | 393 list->AppendString(*value); |
| 393 dictionary->SetWithoutPathExpansion(*name, list); | 394 dictionary->SetWithoutPathExpansion(*name, list); |
| 394 break; | 395 break; |
| 395 case base::Value::TYPE_LIST: // Just append to the list. | 396 case base::Value::TYPE_LIST: // Just append to the list. |
| 396 CHECK(entry->GetAsList(&list)); | 397 CHECK(entry->GetAsList(&list)); |
| 397 list->AppendString(*value); | 398 list->AppendString(*value); |
| 398 break; | 399 break; |
| 399 default: | 400 default: |
| 400 NOTREACHED(); // We never put other Values here. | 401 NOTREACHED(); // We never put other Values here. |
| 401 return std::unique_ptr<base::DictionaryValue>(); | 402 return std::unique_ptr<base::DictionaryValue>(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 415 void MatchAndCheck(const std::vector< std::vector<const std::string*> >& tests, | 416 void MatchAndCheck(const std::vector< std::vector<const std::string*> >& tests, |
| 416 const std::string& key, | 417 const std::string& key, |
| 417 RequestStage stage, | 418 RequestStage stage, |
| 418 net::URLRequest* url_request, | 419 net::URLRequest* url_request, |
| 419 bool* result) { | 420 bool* result) { |
| 420 base::ListValue contains_headers; | 421 base::ListValue contains_headers; |
| 421 for (size_t i = 0; i < tests.size(); ++i) { | 422 for (size_t i = 0; i < tests.size(); ++i) { |
| 422 std::unique_ptr<base::DictionaryValue> temp( | 423 std::unique_ptr<base::DictionaryValue> temp( |
| 423 GetDictionaryFromArray(tests[i])); | 424 GetDictionaryFromArray(tests[i])); |
| 424 ASSERT_TRUE(temp.get()); | 425 ASSERT_TRUE(temp.get()); |
| 425 contains_headers.Append(temp.release()); | 426 contains_headers.Append(std::move(temp)); |
| 426 } | 427 } |
| 427 | 428 |
| 428 std::string error; | 429 std::string error; |
| 429 scoped_refptr<const WebRequestConditionAttribute> attribute = | 430 scoped_refptr<const WebRequestConditionAttribute> attribute = |
| 430 WebRequestConditionAttribute::Create(key, &contains_headers, &error); | 431 WebRequestConditionAttribute::Create(key, &contains_headers, &error); |
| 431 ASSERT_EQ("", error); | 432 ASSERT_EQ("", error); |
| 432 ASSERT_TRUE(attribute.get()); | 433 ASSERT_TRUE(attribute.get()); |
| 433 EXPECT_EQ(key, attribute->GetName()); | 434 EXPECT_EQ(key, attribute->GetName()); |
| 434 | 435 |
| 435 *result = attribute->IsFulfilled(WebRequestData( | 436 *result = attribute->IsFulfilled(WebRequestData( |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 }; | 713 }; |
| 713 const size_t kExistingSize[] = { arraysize(kExisting) }; | 714 const size_t kExistingSize[] = { arraysize(kExisting) }; |
| 714 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests); | 715 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests); |
| 715 MatchAndCheck(tests, keys::kExcludeResponseHeadersKey, stage, | 716 MatchAndCheck(tests, keys::kExcludeResponseHeadersKey, stage, |
| 716 url_request.get(), &result); | 717 url_request.get(), &result); |
| 717 EXPECT_FALSE(result); | 718 EXPECT_FALSE(result); |
| 718 } | 719 } |
| 719 | 720 |
| 720 } // namespace | 721 } // namespace |
| 721 } // namespace extensions | 722 } // namespace extensions |
| OLD | NEW |