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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 ON_BEFORE_REQUEST))); | 130 ON_BEFORE_REQUEST))); |
131 } | 131 } |
132 | 132 |
133 TEST(WebRequestConditionAttributeTest, ContentType) { | 133 TEST(WebRequestConditionAttributeTest, ContentType) { |
134 // Necessary for TestURLRequest. | 134 // Necessary for TestURLRequest. |
135 base::MessageLoopForIO message_loop; | 135 base::MessageLoopForIO message_loop; |
136 | 136 |
137 std::string error; | 137 std::string error; |
138 scoped_refptr<const WebRequestConditionAttribute> result; | 138 scoped_refptr<const WebRequestConditionAttribute> result; |
139 | 139 |
140 net::test_server::EmbeddedTestServer test_server; | 140 net::EmbeddedTestServer test_server; |
141 test_server.ServeFilesFromDirectory(TestDataPath( | 141 test_server.ServeFilesFromDirectory(TestDataPath( |
142 "chrome/test/data/extensions/api_test/webrequest/declarative")); | 142 "chrome/test/data/extensions/api_test/webrequest/declarative")); |
143 ASSERT_TRUE(test_server.InitializeAndWaitUntilReady()); | 143 ASSERT_TRUE(test_server.Start()); |
144 | 144 |
145 net::TestURLRequestContext context; | 145 net::TestURLRequestContext context; |
146 net::TestDelegate delegate; | 146 net::TestDelegate delegate; |
147 scoped_ptr<net::URLRequest> url_request(context.CreateRequest( | 147 scoped_ptr<net::URLRequest> url_request(context.CreateRequest( |
148 test_server.GetURL("/headers.html"), net::DEFAULT_PRIORITY, &delegate)); | 148 test_server.GetURL("/headers.html"), net::DEFAULT_PRIORITY, &delegate)); |
149 url_request->Start(); | 149 url_request->Start(); |
150 base::MessageLoop::current()->Run(); | 150 base::MessageLoop::current()->Run(); |
151 | 151 |
152 base::ListValue content_types; | 152 base::ListValue content_types; |
153 content_types.Append(new base::StringValue("text/plain")); | 153 content_types.Append(new base::StringValue("text/plain")); |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 } | 518 } |
519 | 519 |
520 // Here we test WebRequestConditionAttributeResponseHeaders for: | 520 // Here we test WebRequestConditionAttributeResponseHeaders for: |
521 // 1. Correct implementation of prefix/suffix/contains/equals matching. | 521 // 1. Correct implementation of prefix/suffix/contains/equals matching. |
522 // 2. Performing logical disjunction (||) between multiple specifications. | 522 // 2. Performing logical disjunction (||) between multiple specifications. |
523 // 3. Negating the match in case of 'doesNotContainHeaders'. | 523 // 3. Negating the match in case of 'doesNotContainHeaders'. |
524 TEST(WebRequestConditionAttributeTest, ResponseHeaders) { | 524 TEST(WebRequestConditionAttributeTest, ResponseHeaders) { |
525 // Necessary for TestURLRequest. | 525 // Necessary for TestURLRequest. |
526 base::MessageLoopForIO message_loop; | 526 base::MessageLoopForIO message_loop; |
527 | 527 |
528 net::test_server::EmbeddedTestServer test_server; | 528 net::EmbeddedTestServer test_server; |
529 test_server.ServeFilesFromDirectory(TestDataPath( | 529 test_server.ServeFilesFromDirectory(TestDataPath( |
530 "chrome/test/data/extensions/api_test/webrequest/declarative")); | 530 "chrome/test/data/extensions/api_test/webrequest/declarative")); |
531 ASSERT_TRUE(test_server.InitializeAndWaitUntilReady()); | 531 ASSERT_TRUE(test_server.Start()); |
532 | 532 |
533 net::TestURLRequestContext context; | 533 net::TestURLRequestContext context; |
534 net::TestDelegate delegate; | 534 net::TestDelegate delegate; |
535 scoped_ptr<net::URLRequest> url_request(context.CreateRequest( | 535 scoped_ptr<net::URLRequest> url_request(context.CreateRequest( |
536 test_server.GetURL("/headers.html"), net::DEFAULT_PRIORITY, &delegate)); | 536 test_server.GetURL("/headers.html"), net::DEFAULT_PRIORITY, &delegate)); |
537 url_request->Start(); | 537 url_request->Start(); |
538 base::MessageLoop::current()->Run(); | 538 base::MessageLoop::current()->Run(); |
539 | 539 |
540 // In all the tests below we assume that the server includes the headers | 540 // In all the tests below we assume that the server includes the headers |
541 // Custom-Header: custom/value | 541 // Custom-Header: custom/value |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 }; | 708 }; |
709 const size_t kExistingSize[] = { arraysize(kExisting) }; | 709 const size_t kExistingSize[] = { arraysize(kExisting) }; |
710 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests); | 710 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests); |
711 MatchAndCheck(tests, keys::kExcludeResponseHeadersKey, stage, | 711 MatchAndCheck(tests, keys::kExcludeResponseHeadersKey, stage, |
712 url_request.get(), &result); | 712 url_request.get(), &result); |
713 EXPECT_FALSE(result); | 713 EXPECT_FALSE(result); |
714 } | 714 } |
715 | 715 |
716 } // namespace | 716 } // namespace |
717 } // namespace extensions | 717 } // namespace extensions |
OLD | NEW |