| 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 #include <utility> |
| 11 | 11 |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/run_loop.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "content/public/browser/resource_request_info.h" | 17 #include "content/public/browser/resource_request_info.h" |
| 17 #include "extensions/browser/api/declarative_webrequest/webrequest_condition.h" | 18 #include "extensions/browser/api/declarative_webrequest/webrequest_condition.h" |
| 18 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" | 19 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" |
| 19 #include "net/base/request_priority.h" | 20 #include "net/base/request_priority.h" |
| 20 #include "net/test/embedded_test_server/embedded_test_server.h" | 21 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 21 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
| 22 #include "net/url_request/url_request_test_util.h" | 23 #include "net/url_request/url_request_test_util.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 25 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 net::EmbeddedTestServer test_server; | 145 net::EmbeddedTestServer test_server; |
| 145 test_server.ServeFilesFromDirectory(TestDataPath( | 146 test_server.ServeFilesFromDirectory(TestDataPath( |
| 146 "chrome/test/data/extensions/api_test/webrequest/declarative")); | 147 "chrome/test/data/extensions/api_test/webrequest/declarative")); |
| 147 ASSERT_TRUE(test_server.Start()); | 148 ASSERT_TRUE(test_server.Start()); |
| 148 | 149 |
| 149 net::TestURLRequestContext context; | 150 net::TestURLRequestContext context; |
| 150 net::TestDelegate delegate; | 151 net::TestDelegate delegate; |
| 151 std::unique_ptr<net::URLRequest> url_request(context.CreateRequest( | 152 std::unique_ptr<net::URLRequest> url_request(context.CreateRequest( |
| 152 test_server.GetURL("/headers.html"), net::DEFAULT_PRIORITY, &delegate)); | 153 test_server.GetURL("/headers.html"), net::DEFAULT_PRIORITY, &delegate)); |
| 153 url_request->Start(); | 154 url_request->Start(); |
| 154 base::MessageLoop::current()->Run(); | 155 base::RunLoop().Run(); |
| 155 | 156 |
| 156 base::ListValue content_types; | 157 base::ListValue content_types; |
| 157 content_types.AppendString("text/plain"); | 158 content_types.AppendString("text/plain"); |
| 158 scoped_refptr<const WebRequestConditionAttribute> attribute_include = | 159 scoped_refptr<const WebRequestConditionAttribute> attribute_include = |
| 159 WebRequestConditionAttribute::Create( | 160 WebRequestConditionAttribute::Create( |
| 160 keys::kContentTypeKey, &content_types, &error); | 161 keys::kContentTypeKey, &content_types, &error); |
| 161 EXPECT_EQ("", error); | 162 EXPECT_EQ("", error); |
| 162 ASSERT_TRUE(attribute_include.get()); | 163 ASSERT_TRUE(attribute_include.get()); |
| 163 EXPECT_FALSE(attribute_include->IsFulfilled( | 164 EXPECT_FALSE(attribute_include->IsFulfilled( |
| 164 WebRequestData(url_request.get(), ON_BEFORE_REQUEST, | 165 WebRequestData(url_request.get(), ON_BEFORE_REQUEST, |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 base::MessageLoopForIO message_loop; | 449 base::MessageLoopForIO message_loop; |
| 449 | 450 |
| 450 net::TestURLRequestContext context; | 451 net::TestURLRequestContext context; |
| 451 net::TestDelegate delegate; | 452 net::TestDelegate delegate; |
| 452 std::unique_ptr<net::URLRequest> url_request( | 453 std::unique_ptr<net::URLRequest> url_request( |
| 453 context.CreateRequest(GURL("http://example.com"), // Dummy URL. | 454 context.CreateRequest(GURL("http://example.com"), // Dummy URL. |
| 454 net::DEFAULT_PRIORITY, &delegate)); | 455 net::DEFAULT_PRIORITY, &delegate)); |
| 455 url_request->SetExtraRequestHeaderByName( | 456 url_request->SetExtraRequestHeaderByName( |
| 456 "Custom-header", "custom/value", true /* overwrite */); | 457 "Custom-header", "custom/value", true /* overwrite */); |
| 457 url_request->Start(); | 458 url_request->Start(); |
| 458 base::MessageLoop::current()->Run(); | 459 base::RunLoop().Run(); |
| 459 | 460 |
| 460 std::vector<std::vector<const std::string*> > tests; | 461 std::vector<std::vector<const std::string*> > tests; |
| 461 bool result = false; | 462 bool result = false; |
| 462 | 463 |
| 463 const RequestStage stage = ON_BEFORE_SEND_HEADERS; | 464 const RequestStage stage = ON_BEFORE_SEND_HEADERS; |
| 464 | 465 |
| 465 // First set of test data -- passing conjunction. | 466 // First set of test data -- passing conjunction. |
| 466 const std::string kPassingCondition[] = { | 467 const std::string kPassingCondition[] = { |
| 467 keys::kNameContainsKey, "CuStOm", // Header names are case insensitive. | 468 keys::kNameContainsKey, "CuStOm", // Header names are case insensitive. |
| 468 keys::kNameEqualsKey, "custom-header", | 469 keys::kNameEqualsKey, "custom-header", |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 net::EmbeddedTestServer test_server; | 534 net::EmbeddedTestServer test_server; |
| 534 test_server.ServeFilesFromDirectory(TestDataPath( | 535 test_server.ServeFilesFromDirectory(TestDataPath( |
| 535 "chrome/test/data/extensions/api_test/webrequest/declarative")); | 536 "chrome/test/data/extensions/api_test/webrequest/declarative")); |
| 536 ASSERT_TRUE(test_server.Start()); | 537 ASSERT_TRUE(test_server.Start()); |
| 537 | 538 |
| 538 net::TestURLRequestContext context; | 539 net::TestURLRequestContext context; |
| 539 net::TestDelegate delegate; | 540 net::TestDelegate delegate; |
| 540 std::unique_ptr<net::URLRequest> url_request(context.CreateRequest( | 541 std::unique_ptr<net::URLRequest> url_request(context.CreateRequest( |
| 541 test_server.GetURL("/headers.html"), net::DEFAULT_PRIORITY, &delegate)); | 542 test_server.GetURL("/headers.html"), net::DEFAULT_PRIORITY, &delegate)); |
| 542 url_request->Start(); | 543 url_request->Start(); |
| 543 base::MessageLoop::current()->Run(); | 544 base::RunLoop().Run(); |
| 544 | 545 |
| 545 // In all the tests below we assume that the server includes the headers | 546 // In all the tests below we assume that the server includes the headers |
| 546 // Custom-Header: custom/value | 547 // Custom-Header: custom/value |
| 547 // Custom-Header-B: valueA | 548 // Custom-Header-B: valueA |
| 548 // Custom-Header-B: valueB | 549 // Custom-Header-B: valueB |
| 549 // Custom-Header-C: valueC, valueD | 550 // Custom-Header-C: valueC, valueD |
| 550 // Custom-Header-D: | 551 // Custom-Header-D: |
| 551 // in the response, but does not include "Non-existing: void". | 552 // in the response, but does not include "Non-existing: void". |
| 552 | 553 |
| 553 std::vector< std::vector<const std::string*> > tests; | 554 std::vector< std::vector<const std::string*> > tests; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 }; | 714 }; |
| 714 const size_t kExistingSize[] = { arraysize(kExisting) }; | 715 const size_t kExistingSize[] = { arraysize(kExisting) }; |
| 715 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests); | 716 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests); |
| 716 MatchAndCheck(tests, keys::kExcludeResponseHeadersKey, stage, | 717 MatchAndCheck(tests, keys::kExcludeResponseHeadersKey, stage, |
| 717 url_request.get(), &result); | 718 url_request.get(), &result); |
| 718 EXPECT_FALSE(result); | 719 EXPECT_FALSE(result); |
| 719 } | 720 } |
| 720 | 721 |
| 721 } // namespace | 722 } // namespace |
| 722 } // namespace extensions | 723 } // namespace extensions |
| OLD | NEW |