| 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 "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit
ion_attribute.h" | 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit
ion_attribute.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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit
ion.h" | 12 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit
ion.h" |
| 12 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta
nts.h" | 13 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta
nts.h" |
| 13 #include "content/public/browser/resource_request_info.h" | 14 #include "content/public/browser/resource_request_info.h" |
| 14 #include "net/base/request_priority.h" | 15 #include "net/base/request_priority.h" |
| 15 #include "net/test/embedded_test_server/embedded_test_server.h" | 16 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 17 #include "net/url_request/url_request.h" |
| 16 #include "net/url_request/url_request_test_util.h" | 18 #include "net/url_request/url_request_test_util.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 20 |
| 19 using base::DictionaryValue; | 21 using base::DictionaryValue; |
| 20 using base::FundamentalValue; | 22 using base::FundamentalValue; |
| 21 using base::ListValue; | 23 using base::ListValue; |
| 22 using base::StringValue; | 24 using base::StringValue; |
| 23 using base::Value; | 25 using base::Value; |
| 24 using content::ResourceType; | 26 using content::ResourceType; |
| 25 | 27 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 resource_types.Append(new base::StringValue("sub_frame")); | 90 resource_types.Append(new base::StringValue("sub_frame")); |
| 89 | 91 |
| 90 scoped_refptr<const WebRequestConditionAttribute> attribute = | 92 scoped_refptr<const WebRequestConditionAttribute> attribute = |
| 91 WebRequestConditionAttribute::Create( | 93 WebRequestConditionAttribute::Create( |
| 92 keys::kResourceTypeKey, &resource_types, &error); | 94 keys::kResourceTypeKey, &resource_types, &error); |
| 93 EXPECT_EQ("", error); | 95 EXPECT_EQ("", error); |
| 94 ASSERT_TRUE(attribute.get()); | 96 ASSERT_TRUE(attribute.get()); |
| 95 EXPECT_EQ(std::string(keys::kResourceTypeKey), attribute->GetName()); | 97 EXPECT_EQ(std::string(keys::kResourceTypeKey), attribute->GetName()); |
| 96 | 98 |
| 97 net::TestURLRequestContext context; | 99 net::TestURLRequestContext context; |
| 98 net::TestURLRequest url_request_ok( | 100 scoped_ptr<net::URLRequest> url_request_ok(context.CreateRequest( |
| 99 GURL("http://www.example.com"), net::DEFAULT_PRIORITY, NULL, &context); | 101 GURL("http://www.example.com"), net::DEFAULT_PRIORITY, NULL, NULL)); |
| 100 content::ResourceRequestInfo::AllocateForTesting( | 102 content::ResourceRequestInfo::AllocateForTesting( |
| 101 &url_request_ok, | 103 url_request_ok.get(), |
| 102 content::RESOURCE_TYPE_SUB_FRAME, | 104 content::RESOURCE_TYPE_SUB_FRAME, |
| 103 NULL, | 105 NULL, |
| 104 -1, | 106 -1, |
| 105 -1, | 107 -1, |
| 106 -1, | 108 -1, |
| 107 false); | 109 false); |
| 108 EXPECT_TRUE(attribute->IsFulfilled(WebRequestData(&url_request_ok, | 110 EXPECT_TRUE(attribute->IsFulfilled(WebRequestData(url_request_ok.get(), |
| 109 ON_BEFORE_REQUEST))); | 111 ON_BEFORE_REQUEST))); |
| 110 | 112 |
| 111 net::TestURLRequest url_request_fail( | 113 scoped_ptr<net::URLRequest> url_request_fail(context.CreateRequest( |
| 112 GURL("http://www.example.com"), net::DEFAULT_PRIORITY, NULL, &context); | 114 GURL("http://www.example.com"), net::DEFAULT_PRIORITY, NULL, NULL)); |
| 113 content::ResourceRequestInfo::AllocateForTesting( | 115 content::ResourceRequestInfo::AllocateForTesting( |
| 114 &url_request_fail, | 116 url_request_fail.get(), |
| 115 content::RESOURCE_TYPE_MAIN_FRAME, | 117 content::RESOURCE_TYPE_MAIN_FRAME, |
| 116 NULL, | 118 NULL, |
| 117 -1, | 119 -1, |
| 118 -1, | 120 -1, |
| 119 -1, | 121 -1, |
| 120 false); | 122 false); |
| 121 EXPECT_FALSE(attribute->IsFulfilled(WebRequestData(&url_request_fail, | 123 EXPECT_FALSE(attribute->IsFulfilled(WebRequestData(url_request_fail.get(), |
| 122 ON_BEFORE_REQUEST))); | 124 ON_BEFORE_REQUEST))); |
| 123 } | 125 } |
| 124 | 126 |
| 125 TEST(WebRequestConditionAttributeTest, ContentType) { | 127 TEST(WebRequestConditionAttributeTest, ContentType) { |
| 126 // Necessary for TestURLRequest. | 128 // Necessary for TestURLRequest. |
| 127 base::MessageLoopForIO message_loop; | 129 base::MessageLoopForIO message_loop; |
| 128 | 130 |
| 129 std::string error; | 131 std::string error; |
| 130 scoped_refptr<const WebRequestConditionAttribute> result; | 132 scoped_refptr<const WebRequestConditionAttribute> result; |
| 131 | 133 |
| 132 net::test_server::EmbeddedTestServer test_server; | 134 net::test_server::EmbeddedTestServer test_server; |
| 133 test_server.ServeFilesFromDirectory(TestDataPath( | 135 test_server.ServeFilesFromDirectory(TestDataPath( |
| 134 "chrome/test/data/extensions/api_test/webrequest/declarative")); | 136 "chrome/test/data/extensions/api_test/webrequest/declarative")); |
| 135 ASSERT_TRUE(test_server.InitializeAndWaitUntilReady()); | 137 ASSERT_TRUE(test_server.InitializeAndWaitUntilReady()); |
| 136 | 138 |
| 137 net::TestURLRequestContext context; | 139 net::TestURLRequestContext context; |
| 138 net::TestDelegate delegate; | 140 net::TestDelegate delegate; |
| 139 net::TestURLRequest url_request(test_server.GetURL("/headers.html"), | 141 scoped_ptr<net::URLRequest> url_request( |
| 140 net::DEFAULT_PRIORITY, | 142 context.CreateRequest(test_server.GetURL("/headers.html"), |
| 141 &delegate, | 143 net::DEFAULT_PRIORITY, |
| 142 &context); | 144 &delegate, |
| 143 url_request.Start(); | 145 NULL)); |
| 146 url_request->Start(); |
| 144 base::MessageLoop::current()->Run(); | 147 base::MessageLoop::current()->Run(); |
| 145 | 148 |
| 146 base::ListValue content_types; | 149 base::ListValue content_types; |
| 147 content_types.Append(new base::StringValue("text/plain")); | 150 content_types.Append(new base::StringValue("text/plain")); |
| 148 scoped_refptr<const WebRequestConditionAttribute> attribute_include = | 151 scoped_refptr<const WebRequestConditionAttribute> attribute_include = |
| 149 WebRequestConditionAttribute::Create( | 152 WebRequestConditionAttribute::Create( |
| 150 keys::kContentTypeKey, &content_types, &error); | 153 keys::kContentTypeKey, &content_types, &error); |
| 151 EXPECT_EQ("", error); | 154 EXPECT_EQ("", error); |
| 152 ASSERT_TRUE(attribute_include.get()); | 155 ASSERT_TRUE(attribute_include.get()); |
| 153 EXPECT_FALSE(attribute_include->IsFulfilled( | 156 EXPECT_FALSE(attribute_include->IsFulfilled( |
| 154 WebRequestData(&url_request, ON_BEFORE_REQUEST, | 157 WebRequestData(url_request.get(), ON_BEFORE_REQUEST, |
| 155 url_request.response_headers()))); | 158 url_request->response_headers()))); |
| 156 EXPECT_TRUE(attribute_include->IsFulfilled( | 159 EXPECT_TRUE(attribute_include->IsFulfilled( |
| 157 WebRequestData(&url_request, ON_HEADERS_RECEIVED, | 160 WebRequestData(url_request.get(), ON_HEADERS_RECEIVED, |
| 158 url_request.response_headers()))); | 161 url_request->response_headers()))); |
| 159 EXPECT_EQ(std::string(keys::kContentTypeKey), attribute_include->GetName()); | 162 EXPECT_EQ(std::string(keys::kContentTypeKey), attribute_include->GetName()); |
| 160 | 163 |
| 161 scoped_refptr<const WebRequestConditionAttribute> attribute_exclude = | 164 scoped_refptr<const WebRequestConditionAttribute> attribute_exclude = |
| 162 WebRequestConditionAttribute::Create( | 165 WebRequestConditionAttribute::Create( |
| 163 keys::kExcludeContentTypeKey, &content_types, &error); | 166 keys::kExcludeContentTypeKey, &content_types, &error); |
| 164 EXPECT_EQ("", error); | 167 EXPECT_EQ("", error); |
| 165 ASSERT_TRUE(attribute_exclude.get()); | 168 ASSERT_TRUE(attribute_exclude.get()); |
| 166 EXPECT_FALSE(attribute_exclude->IsFulfilled( | 169 EXPECT_FALSE(attribute_exclude->IsFulfilled( |
| 167 WebRequestData(&url_request, ON_HEADERS_RECEIVED, | 170 WebRequestData(url_request.get(), ON_HEADERS_RECEIVED, |
| 168 url_request.response_headers()))); | 171 url_request->response_headers()))); |
| 169 | 172 |
| 170 content_types.Clear(); | 173 content_types.Clear(); |
| 171 content_types.Append(new base::StringValue("something/invalid")); | 174 content_types.Append(new base::StringValue("something/invalid")); |
| 172 scoped_refptr<const WebRequestConditionAttribute> attribute_unincluded = | 175 scoped_refptr<const WebRequestConditionAttribute> attribute_unincluded = |
| 173 WebRequestConditionAttribute::Create( | 176 WebRequestConditionAttribute::Create( |
| 174 keys::kContentTypeKey, &content_types, &error); | 177 keys::kContentTypeKey, &content_types, &error); |
| 175 EXPECT_EQ("", error); | 178 EXPECT_EQ("", error); |
| 176 ASSERT_TRUE(attribute_unincluded.get()); | 179 ASSERT_TRUE(attribute_unincluded.get()); |
| 177 EXPECT_FALSE(attribute_unincluded->IsFulfilled( | 180 EXPECT_FALSE(attribute_unincluded->IsFulfilled( |
| 178 WebRequestData(&url_request, ON_HEADERS_RECEIVED, | 181 WebRequestData(url_request.get(), ON_HEADERS_RECEIVED, |
| 179 url_request.response_headers()))); | 182 url_request->response_headers()))); |
| 180 | 183 |
| 181 scoped_refptr<const WebRequestConditionAttribute> attribute_unexcluded = | 184 scoped_refptr<const WebRequestConditionAttribute> attribute_unexcluded = |
| 182 WebRequestConditionAttribute::Create( | 185 WebRequestConditionAttribute::Create( |
| 183 keys::kExcludeContentTypeKey, &content_types, &error); | 186 keys::kExcludeContentTypeKey, &content_types, &error); |
| 184 EXPECT_EQ("", error); | 187 EXPECT_EQ("", error); |
| 185 ASSERT_TRUE(attribute_unexcluded.get()); | 188 ASSERT_TRUE(attribute_unexcluded.get()); |
| 186 EXPECT_TRUE(attribute_unexcluded->IsFulfilled( | 189 EXPECT_TRUE(attribute_unexcluded->IsFulfilled( |
| 187 WebRequestData(&url_request, ON_HEADERS_RECEIVED, | 190 WebRequestData(url_request.get(), ON_HEADERS_RECEIVED, |
| 188 url_request.response_headers()))); | 191 url_request->response_headers()))); |
| 189 EXPECT_EQ(std::string(keys::kExcludeContentTypeKey), | 192 EXPECT_EQ(std::string(keys::kExcludeContentTypeKey), |
| 190 attribute_unexcluded->GetName()); | 193 attribute_unexcluded->GetName()); |
| 191 } | 194 } |
| 192 | 195 |
| 193 // Testing WebRequestConditionAttributeThirdParty. | 196 // Testing WebRequestConditionAttributeThirdParty. |
| 194 TEST(WebRequestConditionAttributeTest, ThirdParty) { | 197 TEST(WebRequestConditionAttributeTest, ThirdParty) { |
| 195 // Necessary for TestURLRequest. | 198 // Necessary for TestURLRequest. |
| 196 base::MessageLoopForIO message_loop; | 199 base::MessageLoopForIO message_loop; |
| 197 | 200 |
| 198 std::string error; | 201 std::string error; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 215 ASSERT_EQ("", error); | 218 ASSERT_EQ("", error); |
| 216 ASSERT_TRUE(first_party_attribute.get()); | 219 ASSERT_TRUE(first_party_attribute.get()); |
| 217 EXPECT_EQ(std::string(keys::kThirdPartyKey), | 220 EXPECT_EQ(std::string(keys::kThirdPartyKey), |
| 218 first_party_attribute->GetName()); | 221 first_party_attribute->GetName()); |
| 219 | 222 |
| 220 const GURL url_empty; | 223 const GURL url_empty; |
| 221 const GURL url_a("http://a.com"); | 224 const GURL url_a("http://a.com"); |
| 222 const GURL url_b("http://b.com"); | 225 const GURL url_b("http://b.com"); |
| 223 net::TestURLRequestContext context; | 226 net::TestURLRequestContext context; |
| 224 net::TestDelegate delegate; | 227 net::TestDelegate delegate; |
| 225 net::TestURLRequest url_request( | 228 scoped_ptr<net::URLRequest> url_request( |
| 226 url_a, net::DEFAULT_PRIORITY, &delegate, &context); | 229 context.CreateRequest(url_a, net::DEFAULT_PRIORITY, &delegate, NULL)); |
| 227 | 230 |
| 228 for (unsigned int i = 1; i <= kLastActiveStage; i <<= 1) { | 231 for (unsigned int i = 1; i <= kLastActiveStage; i <<= 1) { |
| 229 if (!(kActiveStages & i)) | 232 if (!(kActiveStages & i)) |
| 230 continue; | 233 continue; |
| 231 const RequestStage stage = static_cast<RequestStage>(i); | 234 const RequestStage stage = static_cast<RequestStage>(i); |
| 232 url_request.set_first_party_for_cookies(url_empty); | 235 url_request->set_first_party_for_cookies(url_empty); |
| 233 EXPECT_FALSE(third_party_attribute->IsFulfilled(WebRequestData(&url_request, | 236 EXPECT_FALSE(third_party_attribute->IsFulfilled( |
| 234 stage))); | 237 WebRequestData(url_request.get(), stage))); |
| 235 EXPECT_TRUE(first_party_attribute->IsFulfilled(WebRequestData(&url_request, | 238 EXPECT_TRUE(first_party_attribute->IsFulfilled( |
| 236 stage))); | 239 WebRequestData(url_request.get(), stage))); |
| 237 | 240 |
| 238 url_request.set_first_party_for_cookies(url_b); | 241 url_request->set_first_party_for_cookies(url_b); |
| 239 EXPECT_TRUE(third_party_attribute->IsFulfilled(WebRequestData(&url_request, | 242 EXPECT_TRUE(third_party_attribute->IsFulfilled( |
| 240 stage))); | 243 WebRequestData(url_request.get(), stage))); |
| 241 EXPECT_FALSE(first_party_attribute->IsFulfilled(WebRequestData(&url_request, | 244 EXPECT_FALSE(first_party_attribute->IsFulfilled( |
| 242 stage))); | 245 WebRequestData(url_request.get(), stage))); |
| 243 | 246 |
| 244 url_request.set_first_party_for_cookies(url_a); | 247 url_request->set_first_party_for_cookies(url_a); |
| 245 EXPECT_FALSE(third_party_attribute->IsFulfilled(WebRequestData(&url_request, | 248 EXPECT_FALSE(third_party_attribute->IsFulfilled( |
| 246 stage))); | 249 WebRequestData(url_request.get(), stage))); |
| 247 EXPECT_TRUE(first_party_attribute->IsFulfilled(WebRequestData(&url_request, | 250 EXPECT_TRUE(first_party_attribute->IsFulfilled( |
| 248 stage))); | 251 WebRequestData(url_request.get(), stage))); |
| 249 } | 252 } |
| 250 } | 253 } |
| 251 | 254 |
| 252 // Testing WebRequestConditionAttributeStages. This iterates over all stages, | 255 // Testing WebRequestConditionAttributeStages. This iterates over all stages, |
| 253 // and tests a couple of "stage" attributes -- one created with an empty set of | 256 // and tests a couple of "stage" attributes -- one created with an empty set of |
| 254 // applicable stages, one for each stage applicable for that stage, and one | 257 // applicable stages, one for each stage applicable for that stage, and one |
| 255 // applicable in all stages. | 258 // applicable in all stages. |
| 256 TEST(WebRequestConditionAttributeTest, Stages) { | 259 TEST(WebRequestConditionAttributeTest, Stages) { |
| 257 // Necessary for TestURLRequest. | 260 // Necessary for TestURLRequest. |
| 258 base::MessageLoopForIO message_loop; | 261 base::MessageLoopForIO message_loop; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 WebRequestConditionAttribute::Create(keys::kStagesKey, | 309 WebRequestConditionAttribute::Create(keys::kStagesKey, |
| 307 &single_stage_list, | 310 &single_stage_list, |
| 308 &error)); | 311 &error)); |
| 309 EXPECT_EQ("", error); | 312 EXPECT_EQ("", error); |
| 310 ASSERT_TRUE(one_stage_attributes.back().get() != NULL); | 313 ASSERT_TRUE(one_stage_attributes.back().get() != NULL); |
| 311 } | 314 } |
| 312 | 315 |
| 313 const GURL url_empty; | 316 const GURL url_empty; |
| 314 net::TestURLRequestContext context; | 317 net::TestURLRequestContext context; |
| 315 net::TestDelegate delegate; | 318 net::TestDelegate delegate; |
| 316 net::TestURLRequest url_request( | 319 scoped_ptr<net::URLRequest> url_request( |
| 317 url_empty, net::DEFAULT_PRIORITY, &delegate, &context); | 320 context.CreateRequest(url_empty, net::DEFAULT_PRIORITY, &delegate, NULL)); |
| 318 | 321 |
| 319 for (size_t i = 0; i < arraysize(active_stages); ++i) { | 322 for (size_t i = 0; i < arraysize(active_stages); ++i) { |
| 320 EXPECT_FALSE(empty_attribute->IsFulfilled( | 323 EXPECT_FALSE(empty_attribute->IsFulfilled( |
| 321 WebRequestData(&url_request, active_stages[i].first))); | 324 WebRequestData(url_request.get(), active_stages[i].first))); |
| 322 | 325 |
| 323 for (size_t j = 0; j < one_stage_attributes.size(); ++j) { | 326 for (size_t j = 0; j < one_stage_attributes.size(); ++j) { |
| 324 EXPECT_EQ(i == j, | 327 EXPECT_EQ(i == j, |
| 325 one_stage_attributes[j]->IsFulfilled( | 328 one_stage_attributes[j]->IsFulfilled( |
| 326 WebRequestData(&url_request, active_stages[i].first))); | 329 WebRequestData(url_request.get(), active_stages[i].first))); |
| 327 } | 330 } |
| 328 | 331 |
| 329 EXPECT_TRUE(attribute_with_all->IsFulfilled( | 332 EXPECT_TRUE(attribute_with_all->IsFulfilled( |
| 330 WebRequestData(&url_request, active_stages[i].first))); | 333 WebRequestData(url_request.get(), active_stages[i].first))); |
| 331 } | 334 } |
| 332 } | 335 } |
| 333 | 336 |
| 334 namespace { | 337 namespace { |
| 335 | 338 |
| 336 // Builds a vector of vectors of string pointers from an array of strings. | 339 // Builds a vector of vectors of string pointers from an array of strings. |
| 337 // |array| is in fact a sequence of arrays. The array |sizes| captures the sizes | 340 // |array| is in fact a sequence of arrays. The array |sizes| captures the sizes |
| 338 // of all parts of |array|, and |size| is the length of |sizes| itself. | 341 // of all parts of |array|, and |size| is the length of |sizes| itself. |
| 339 // Example (this is pseudo-code, not C++): | 342 // Example (this is pseudo-code, not C++): |
| 340 // array = { "a", "b", "c", "d", "e", "f" } | 343 // array = { "a", "b", "c", "d", "e", "f" } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 // Here we test WebRequestConditionAttributeRequestHeaders for matching | 434 // Here we test WebRequestConditionAttributeRequestHeaders for matching |
| 432 // correctly against request headers. This test is not as extensive as | 435 // correctly against request headers. This test is not as extensive as |
| 433 // "ResponseHeaders" (below), because the header-matching code is shared | 436 // "ResponseHeaders" (below), because the header-matching code is shared |
| 434 // by both types of condition attributes, so it is enough to test it once. | 437 // by both types of condition attributes, so it is enough to test it once. |
| 435 TEST(WebRequestConditionAttributeTest, RequestHeaders) { | 438 TEST(WebRequestConditionAttributeTest, RequestHeaders) { |
| 436 // Necessary for TestURLRequest. | 439 // Necessary for TestURLRequest. |
| 437 base::MessageLoopForIO message_loop; | 440 base::MessageLoopForIO message_loop; |
| 438 | 441 |
| 439 net::TestURLRequestContext context; | 442 net::TestURLRequestContext context; |
| 440 net::TestDelegate delegate; | 443 net::TestDelegate delegate; |
| 441 net::TestURLRequest url_request(GURL("http://example.com"), // Dummy URL. | 444 scoped_ptr<net::URLRequest> url_request( |
| 442 net::DEFAULT_PRIORITY, | 445 context.CreateRequest(GURL("http://example.com"), // Dummy URL. |
| 443 &delegate, | 446 net::DEFAULT_PRIORITY, |
| 444 &context); | 447 &delegate, |
| 445 url_request.SetExtraRequestHeaderByName( | 448 NULL)); |
| 449 url_request->SetExtraRequestHeaderByName( |
| 446 "Custom-header", "custom/value", true /* overwrite */); | 450 "Custom-header", "custom/value", true /* overwrite */); |
| 447 url_request.Start(); | 451 url_request->Start(); |
| 448 base::MessageLoop::current()->Run(); | 452 base::MessageLoop::current()->Run(); |
| 449 | 453 |
| 450 std::vector<std::vector<const std::string*> > tests; | 454 std::vector<std::vector<const std::string*> > tests; |
| 451 bool result = false; | 455 bool result = false; |
| 452 | 456 |
| 453 const RequestStage stage = ON_BEFORE_SEND_HEADERS; | 457 const RequestStage stage = ON_BEFORE_SEND_HEADERS; |
| 454 | 458 |
| 455 // First set of test data -- passing conjunction. | 459 // First set of test data -- passing conjunction. |
| 456 const std::string kPassingCondition[] = { | 460 const std::string kPassingCondition[] = { |
| 457 keys::kNameContainsKey, "CuStOm", // Header names are case insensitive. | 461 keys::kNameContainsKey, "CuStOm", // Header names are case insensitive. |
| 458 keys::kNameEqualsKey, "custom-header", | 462 keys::kNameEqualsKey, "custom-header", |
| 459 keys::kValueSuffixKey, "alue", | 463 keys::kValueSuffixKey, "alue", |
| 460 keys::kValuePrefixKey, "custom/value" | 464 keys::kValuePrefixKey, "custom/value" |
| 461 }; | 465 }; |
| 462 const size_t kPassingConditionSizes[] = { arraysize(kPassingCondition) }; | 466 const size_t kPassingConditionSizes[] = { arraysize(kPassingCondition) }; |
| 463 GetArrayAsVector(kPassingCondition, kPassingConditionSizes, 1u, &tests); | 467 GetArrayAsVector(kPassingCondition, kPassingConditionSizes, 1u, &tests); |
| 464 // Positive filter, passing (conjunction of tests). | 468 // Positive filter, passing (conjunction of tests). |
| 465 MatchAndCheck(tests, keys::kRequestHeadersKey, stage, &url_request, &result); | 469 MatchAndCheck( |
| 470 tests, keys::kRequestHeadersKey, stage, url_request.get(), &result); |
| 466 EXPECT_TRUE(result); | 471 EXPECT_TRUE(result); |
| 467 // Negative filter, failing (conjunction of tests). | 472 // Negative filter, failing (conjunction of tests). |
| 468 MatchAndCheck( | 473 MatchAndCheck(tests, keys::kExcludeRequestHeadersKey, stage, |
| 469 tests, keys::kExcludeRequestHeadersKey, stage, &url_request, &result); | 474 url_request.get(), &result); |
| 470 EXPECT_FALSE(result); | 475 EXPECT_FALSE(result); |
| 471 | 476 |
| 472 // Second set of test data -- failing disjunction. | 477 // Second set of test data -- failing disjunction. |
| 473 const std::string kFailCondition[] = { | 478 const std::string kFailCondition[] = { |
| 474 keys::kNameSuffixKey, "Custom", // Test 1. | 479 keys::kNameSuffixKey, "Custom", // Test 1. |
| 475 keys::kNameEqualsKey, "ustom-valu", // Test 2. | 480 keys::kNameEqualsKey, "ustom-valu", // Test 2. |
| 476 keys::kValuePrefixKey, "custom ", // Test 3. | 481 keys::kValuePrefixKey, "custom ", // Test 3. |
| 477 keys::kValueContainsKey, " value" // Test 4. | 482 keys::kValueContainsKey, " value" // Test 4. |
| 478 }; | 483 }; |
| 479 const size_t kFailConditionSizes[] = { 2u, 2u, 2u, 2u }; | 484 const size_t kFailConditionSizes[] = { 2u, 2u, 2u, 2u }; |
| 480 GetArrayAsVector(kFailCondition, kFailConditionSizes, 4u, &tests); | 485 GetArrayAsVector(kFailCondition, kFailConditionSizes, 4u, &tests); |
| 481 // Positive filter, failing (disjunction of tests). | 486 // Positive filter, failing (disjunction of tests). |
| 482 MatchAndCheck(tests, keys::kRequestHeadersKey, stage, &url_request, &result); | 487 MatchAndCheck(tests, keys::kRequestHeadersKey, stage, url_request.get(), |
| 488 &result); |
| 483 EXPECT_FALSE(result); | 489 EXPECT_FALSE(result); |
| 484 // Negative filter, passing (disjunction of tests). | 490 // Negative filter, passing (disjunction of tests). |
| 485 MatchAndCheck( | 491 MatchAndCheck(tests, keys::kExcludeRequestHeadersKey, stage, |
| 486 tests, keys::kExcludeRequestHeadersKey, stage, &url_request, &result); | 492 url_request.get(), &result); |
| 487 EXPECT_TRUE(result); | 493 EXPECT_TRUE(result); |
| 488 | 494 |
| 489 // Third set of test data, corner case -- empty disjunction. | 495 // Third set of test data, corner case -- empty disjunction. |
| 490 GetArrayAsVector(NULL, NULL, 0u, &tests); | 496 GetArrayAsVector(NULL, NULL, 0u, &tests); |
| 491 // Positive filter, failing (no test to pass). | 497 // Positive filter, failing (no test to pass). |
| 492 MatchAndCheck(tests, keys::kRequestHeadersKey, stage, &url_request, &result); | 498 MatchAndCheck(tests, keys::kRequestHeadersKey, stage, url_request.get(), |
| 499 &result); |
| 493 EXPECT_FALSE(result); | 500 EXPECT_FALSE(result); |
| 494 // Negative filter, passing (no test to fail). | 501 // Negative filter, passing (no test to fail). |
| 495 MatchAndCheck( | 502 MatchAndCheck(tests, keys::kExcludeRequestHeadersKey, stage, |
| 496 tests, keys::kExcludeRequestHeadersKey, stage, &url_request, &result); | 503 url_request.get(), &result); |
| 497 EXPECT_TRUE(result); | 504 EXPECT_TRUE(result); |
| 498 | 505 |
| 499 // Fourth set of test data, corner case -- empty conjunction. | 506 // Fourth set of test data, corner case -- empty conjunction. |
| 500 const size_t kEmptyConjunctionSizes[] = { 0u }; | 507 const size_t kEmptyConjunctionSizes[] = { 0u }; |
| 501 GetArrayAsVector(NULL, kEmptyConjunctionSizes, 1u, &tests); | 508 GetArrayAsVector(NULL, kEmptyConjunctionSizes, 1u, &tests); |
| 502 // Positive filter, passing (trivial test). | 509 // Positive filter, passing (trivial test). |
| 503 MatchAndCheck(tests, keys::kRequestHeadersKey, stage, &url_request, &result); | 510 MatchAndCheck(tests, keys::kRequestHeadersKey, stage, url_request.get(), |
| 511 &result); |
| 504 EXPECT_TRUE(result); | 512 EXPECT_TRUE(result); |
| 505 // Negative filter, failing. | 513 // Negative filter, failing. |
| 506 MatchAndCheck( | 514 MatchAndCheck(tests, keys::kExcludeRequestHeadersKey, stage, |
| 507 tests, keys::kExcludeRequestHeadersKey, stage, &url_request, &result); | 515 url_request.get(), &result); |
| 508 EXPECT_FALSE(result); | 516 EXPECT_FALSE(result); |
| 509 } | 517 } |
| 510 | 518 |
| 511 // Here we test WebRequestConditionAttributeResponseHeaders for: | 519 // Here we test WebRequestConditionAttributeResponseHeaders for: |
| 512 // 1. Correct implementation of prefix/suffix/contains/equals matching. | 520 // 1. Correct implementation of prefix/suffix/contains/equals matching. |
| 513 // 2. Performing logical disjunction (||) between multiple specifications. | 521 // 2. Performing logical disjunction (||) between multiple specifications. |
| 514 // 3. Negating the match in case of 'doesNotContainHeaders'. | 522 // 3. Negating the match in case of 'doesNotContainHeaders'. |
| 515 TEST(WebRequestConditionAttributeTest, ResponseHeaders) { | 523 TEST(WebRequestConditionAttributeTest, ResponseHeaders) { |
| 516 // Necessary for TestURLRequest. | 524 // Necessary for TestURLRequest. |
| 517 base::MessageLoopForIO message_loop; | 525 base::MessageLoopForIO message_loop; |
| 518 | 526 |
| 519 net::test_server::EmbeddedTestServer test_server; | 527 net::test_server::EmbeddedTestServer test_server; |
| 520 test_server.ServeFilesFromDirectory(TestDataPath( | 528 test_server.ServeFilesFromDirectory(TestDataPath( |
| 521 "chrome/test/data/extensions/api_test/webrequest/declarative")); | 529 "chrome/test/data/extensions/api_test/webrequest/declarative")); |
| 522 ASSERT_TRUE(test_server.InitializeAndWaitUntilReady()); | 530 ASSERT_TRUE(test_server.InitializeAndWaitUntilReady()); |
| 523 | 531 |
| 524 net::TestURLRequestContext context; | 532 net::TestURLRequestContext context; |
| 525 net::TestDelegate delegate; | 533 net::TestDelegate delegate; |
| 526 net::TestURLRequest url_request(test_server.GetURL("/headers.html"), | 534 scoped_ptr<net::URLRequest> url_request( |
| 527 net::DEFAULT_PRIORITY, | 535 context.CreateRequest(test_server.GetURL("/headers.html"), |
| 528 &delegate, | 536 net::DEFAULT_PRIORITY, |
| 529 &context); | 537 &delegate, |
| 530 url_request.Start(); | 538 NULL)); |
| 539 url_request->Start(); |
| 531 base::MessageLoop::current()->Run(); | 540 base::MessageLoop::current()->Run(); |
| 532 | 541 |
| 533 // In all the tests below we assume that the server includes the headers | 542 // In all the tests below we assume that the server includes the headers |
| 534 // Custom-Header: custom/value | 543 // Custom-Header: custom/value |
| 535 // Custom-Header-B: valueA | 544 // Custom-Header-B: valueA |
| 536 // Custom-Header-B: valueB | 545 // Custom-Header-B: valueB |
| 537 // Custom-Header-C: valueC, valueD | 546 // Custom-Header-C: valueC, valueD |
| 538 // Custom-Header-D: | 547 // Custom-Header-D: |
| 539 // in the response, but does not include "Non-existing: void". | 548 // in the response, but does not include "Non-existing: void". |
| 540 | 549 |
| 541 std::vector< std::vector<const std::string*> > tests; | 550 std::vector< std::vector<const std::string*> > tests; |
| 542 bool result; | 551 bool result; |
| 543 | 552 |
| 544 const RequestStage stage = ON_HEADERS_RECEIVED; | 553 const RequestStage stage = ON_HEADERS_RECEIVED; |
| 545 | 554 |
| 546 // 1.a. -- All these tests should pass. | 555 // 1.a. -- All these tests should pass. |
| 547 const std::string kPassingCondition[] = { | 556 const std::string kPassingCondition[] = { |
| 548 keys::kNamePrefixKey, "Custom", | 557 keys::kNamePrefixKey, "Custom", |
| 549 keys::kNameSuffixKey, "m-header", // Header names are case insensitive. | 558 keys::kNameSuffixKey, "m-header", // Header names are case insensitive. |
| 550 keys::kValueContainsKey, "alu", | 559 keys::kValueContainsKey, "alu", |
| 551 keys::kValueEqualsKey, "custom/value" | 560 keys::kValueEqualsKey, "custom/value" |
| 552 }; | 561 }; |
| 553 const size_t kPassingConditionSizes[] = { arraysize(kPassingCondition) }; | 562 const size_t kPassingConditionSizes[] = { arraysize(kPassingCondition) }; |
| 554 GetArrayAsVector(kPassingCondition, kPassingConditionSizes, 1u, &tests); | 563 GetArrayAsVector(kPassingCondition, kPassingConditionSizes, 1u, &tests); |
| 555 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, &url_request, &result); | 564 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, url_request.get(), |
| 565 &result); |
| 556 EXPECT_TRUE(result); | 566 EXPECT_TRUE(result); |
| 557 | 567 |
| 558 // 1.b. -- None of the following tests in the discjunction should pass. | 568 // 1.b. -- None of the following tests in the discjunction should pass. |
| 559 const std::string kFailCondition[] = { | 569 const std::string kFailCondition[] = { |
| 560 keys::kNamePrefixKey, " Custom", // Test 1. | 570 keys::kNamePrefixKey, " Custom", // Test 1. |
| 561 keys::kNameContainsKey, " -", // Test 2. | 571 keys::kNameContainsKey, " -", // Test 2. |
| 562 keys::kValueSuffixKey, "alu", // Test 3. | 572 keys::kValueSuffixKey, "alu", // Test 3. |
| 563 keys::kValueEqualsKey, "custom" // Test 4. | 573 keys::kValueEqualsKey, "custom" // Test 4. |
| 564 }; | 574 }; |
| 565 const size_t kFailConditionSizes[] = { 2u, 2u, 2u, 2u }; | 575 const size_t kFailConditionSizes[] = { 2u, 2u, 2u, 2u }; |
| 566 GetArrayAsVector(kFailCondition, kFailConditionSizes, 4u, &tests); | 576 GetArrayAsVector(kFailCondition, kFailConditionSizes, 4u, &tests); |
| 567 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, &url_request, &result); | 577 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, url_request.get(), |
| 578 &result); |
| 568 EXPECT_FALSE(result); | 579 EXPECT_FALSE(result); |
| 569 | 580 |
| 570 // 1.c. -- This should fail (mixing name and value from different headers) | 581 // 1.c. -- This should fail (mixing name and value from different headers) |
| 571 const std::string kMixingCondition[] = { | 582 const std::string kMixingCondition[] = { |
| 572 keys::kNameSuffixKey, "Header-B", | 583 keys::kNameSuffixKey, "Header-B", |
| 573 keys::kValueEqualsKey, "custom/value" | 584 keys::kValueEqualsKey, "custom/value" |
| 574 }; | 585 }; |
| 575 const size_t kMixingConditionSizes[] = { arraysize(kMixingCondition) }; | 586 const size_t kMixingConditionSizes[] = { arraysize(kMixingCondition) }; |
| 576 GetArrayAsVector(kMixingCondition, kMixingConditionSizes, 1u, &tests); | 587 GetArrayAsVector(kMixingCondition, kMixingConditionSizes, 1u, &tests); |
| 577 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, &url_request, &result); | 588 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, url_request.get(), |
| 589 &result); |
| 578 EXPECT_FALSE(result); | 590 EXPECT_FALSE(result); |
| 579 | 591 |
| 580 // 1.d. -- Test handling multiple values for one header (both should pass). | 592 // 1.d. -- Test handling multiple values for one header (both should pass). |
| 581 const std::string kMoreValues1[] = { | 593 const std::string kMoreValues1[] = { |
| 582 keys::kNameEqualsKey, "Custom-header-b", | 594 keys::kNameEqualsKey, "Custom-header-b", |
| 583 keys::kValueEqualsKey, "valueA" | 595 keys::kValueEqualsKey, "valueA" |
| 584 }; | 596 }; |
| 585 const size_t kMoreValues1Sizes[] = { arraysize(kMoreValues1) }; | 597 const size_t kMoreValues1Sizes[] = { arraysize(kMoreValues1) }; |
| 586 GetArrayAsVector(kMoreValues1, kMoreValues1Sizes, 1u, &tests); | 598 GetArrayAsVector(kMoreValues1, kMoreValues1Sizes, 1u, &tests); |
| 587 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, &url_request, &result); | 599 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, url_request.get(), |
| 600 &result); |
| 588 EXPECT_TRUE(result); | 601 EXPECT_TRUE(result); |
| 589 const std::string kMoreValues2[] = { | 602 const std::string kMoreValues2[] = { |
| 590 keys::kNameEqualsKey, "Custom-header-b", | 603 keys::kNameEqualsKey, "Custom-header-b", |
| 591 keys::kValueEqualsKey, "valueB" | 604 keys::kValueEqualsKey, "valueB" |
| 592 }; | 605 }; |
| 593 const size_t kMoreValues2Sizes[] = { arraysize(kMoreValues2) }; | 606 const size_t kMoreValues2Sizes[] = { arraysize(kMoreValues2) }; |
| 594 GetArrayAsVector(kMoreValues2, kMoreValues2Sizes, 1u, &tests); | 607 GetArrayAsVector(kMoreValues2, kMoreValues2Sizes, 1u, &tests); |
| 595 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, &url_request, &result); | 608 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, url_request.get(), |
| 609 &result); |
| 596 EXPECT_TRUE(result); | 610 EXPECT_TRUE(result); |
| 597 | 611 |
| 598 // 1.e. -- This should fail as conjunction but pass as disjunction. | 612 // 1.e. -- This should fail as conjunction but pass as disjunction. |
| 599 const std::string kConflict[] = { | 613 const std::string kConflict[] = { |
| 600 keys::kNameSuffixKey, "Header", // True for some header. | 614 keys::kNameSuffixKey, "Header", // True for some header. |
| 601 keys::kNameContainsKey, "Header-B" // True for a different header. | 615 keys::kNameContainsKey, "Header-B" // True for a different header. |
| 602 }; | 616 }; |
| 603 // First disjunction, no conflict. | 617 // First disjunction, no conflict. |
| 604 const size_t kNoConflictSizes[] = { 2u, 2u }; | 618 const size_t kNoConflictSizes[] = { 2u, 2u }; |
| 605 GetArrayAsVector(kConflict, kNoConflictSizes, 2u, &tests); | 619 GetArrayAsVector(kConflict, kNoConflictSizes, 2u, &tests); |
| 606 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, &url_request, &result); | 620 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, url_request.get(), |
| 621 &result); |
| 607 EXPECT_TRUE(result); | 622 EXPECT_TRUE(result); |
| 608 // Then conjunction, conflict. | 623 // Then conjunction, conflict. |
| 609 const size_t kConflictSizes[] = { arraysize(kConflict) }; | 624 const size_t kConflictSizes[] = { arraysize(kConflict) }; |
| 610 GetArrayAsVector(kConflict, kConflictSizes, 1u, &tests); | 625 GetArrayAsVector(kConflict, kConflictSizes, 1u, &tests); |
| 611 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, &url_request, &result); | 626 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, url_request.get(), |
| 627 &result); |
| 612 EXPECT_FALSE(result); | 628 EXPECT_FALSE(result); |
| 613 | 629 |
| 614 // 1.f. -- This should pass, checking for correct treatment of ',' in values. | 630 // 1.f. -- This should pass, checking for correct treatment of ',' in values. |
| 615 const std::string kComma[] = { | 631 const std::string kComma[] = { |
| 616 keys::kNameSuffixKey, "Header-C", | 632 keys::kNameSuffixKey, "Header-C", |
| 617 keys::kValueEqualsKey, "valueC, valueD" | 633 keys::kValueEqualsKey, "valueC, valueD" |
| 618 }; | 634 }; |
| 619 const size_t kCommaSizes[] = { arraysize(kComma) }; | 635 const size_t kCommaSizes[] = { arraysize(kComma) }; |
| 620 GetArrayAsVector(kComma, kCommaSizes, 1u, &tests); | 636 GetArrayAsVector(kComma, kCommaSizes, 1u, &tests); |
| 621 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, &url_request, &result); | 637 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, url_request.get(), |
| 638 &result); |
| 622 EXPECT_TRUE(result); | 639 EXPECT_TRUE(result); |
| 623 | 640 |
| 624 // 1.g. -- This should pass, empty values are values as well. | 641 // 1.g. -- This should pass, empty values are values as well. |
| 625 const std::string kEmpty[] = { | 642 const std::string kEmpty[] = { |
| 626 keys::kNameEqualsKey, "custom-header-d", | 643 keys::kNameEqualsKey, "custom-header-d", |
| 627 keys::kValueEqualsKey, "" | 644 keys::kValueEqualsKey, "" |
| 628 }; | 645 }; |
| 629 const size_t kEmptySizes[] = { arraysize(kEmpty) }; | 646 const size_t kEmptySizes[] = { arraysize(kEmpty) }; |
| 630 GetArrayAsVector(kEmpty, kEmptySizes, 1u, &tests); | 647 GetArrayAsVector(kEmpty, kEmptySizes, 1u, &tests); |
| 631 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, &url_request, &result); | 648 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, url_request.get(), |
| 649 &result); |
| 632 EXPECT_TRUE(result); | 650 EXPECT_TRUE(result); |
| 633 | 651 |
| 634 // 1.h. -- Values are case-sensitive, this should fail. | 652 // 1.h. -- Values are case-sensitive, this should fail. |
| 635 const std::string kLowercase[] = { | 653 const std::string kLowercase[] = { |
| 636 keys::kNameEqualsKey, "Custom-header-b", | 654 keys::kNameEqualsKey, "Custom-header-b", |
| 637 keys::kValuePrefixKey, "valueb", // valueb != valueB | 655 keys::kValuePrefixKey, "valueb", // valueb != valueB |
| 638 keys::kNameEqualsKey, "Custom-header-b", | 656 keys::kNameEqualsKey, "Custom-header-b", |
| 639 keys::kValueSuffixKey, "valueb", | 657 keys::kValueSuffixKey, "valueb", |
| 640 keys::kNameEqualsKey, "Custom-header-b", | 658 keys::kNameEqualsKey, "Custom-header-b", |
| 641 keys::kValueContainsKey, "valueb", | 659 keys::kValueContainsKey, "valueb", |
| 642 keys::kNameEqualsKey, "Custom-header-b", | 660 keys::kNameEqualsKey, "Custom-header-b", |
| 643 keys::kValueEqualsKey, "valueb" | 661 keys::kValueEqualsKey, "valueb" |
| 644 }; | 662 }; |
| 645 const size_t kLowercaseSizes[] = { 4u, 4u, 4u, 4u }; // As disjunction. | 663 const size_t kLowercaseSizes[] = { 4u, 4u, 4u, 4u }; // As disjunction. |
| 646 GetArrayAsVector(kLowercase, kLowercaseSizes, 4u, &tests); | 664 GetArrayAsVector(kLowercase, kLowercaseSizes, 4u, &tests); |
| 647 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, &url_request, &result); | 665 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, url_request.get(), |
| 666 &result); |
| 648 EXPECT_FALSE(result); | 667 EXPECT_FALSE(result); |
| 649 | 668 |
| 650 // 1.i. -- Names are case-insensitive, this should pass. | 669 // 1.i. -- Names are case-insensitive, this should pass. |
| 651 const std::string kUppercase[] = { | 670 const std::string kUppercase[] = { |
| 652 keys::kNamePrefixKey, "CUSTOM-HEADER-B", | 671 keys::kNamePrefixKey, "CUSTOM-HEADER-B", |
| 653 keys::kNameSuffixKey, "CUSTOM-HEADER-B", | 672 keys::kNameSuffixKey, "CUSTOM-HEADER-B", |
| 654 keys::kNameEqualsKey, "CUSTOM-HEADER-B", | 673 keys::kNameEqualsKey, "CUSTOM-HEADER-B", |
| 655 keys::kNameContainsKey, "CUSTOM-HEADER-B" | 674 keys::kNameContainsKey, "CUSTOM-HEADER-B" |
| 656 }; | 675 }; |
| 657 const size_t kUppercaseSizes[] = { arraysize(kUppercase) }; // Conjunction. | 676 const size_t kUppercaseSizes[] = { arraysize(kUppercase) }; // Conjunction. |
| 658 GetArrayAsVector(kUppercase, kUppercaseSizes, 1u, &tests); | 677 GetArrayAsVector(kUppercase, kUppercaseSizes, 1u, &tests); |
| 659 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, &url_request, &result); | 678 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, url_request.get(), |
| 679 &result); |
| 660 EXPECT_TRUE(result); | 680 EXPECT_TRUE(result); |
| 661 | 681 |
| 662 // 2.a. -- This should pass as disjunction, because one of the tests passes. | 682 // 2.a. -- This should pass as disjunction, because one of the tests passes. |
| 663 const std::string kDisjunction[] = { | 683 const std::string kDisjunction[] = { |
| 664 keys::kNamePrefixKey, "Non-existing", // This one fails. | 684 keys::kNamePrefixKey, "Non-existing", // This one fails. |
| 665 keys::kNameSuffixKey, "Non-existing", // This one fails. | 685 keys::kNameSuffixKey, "Non-existing", // This one fails. |
| 666 keys::kValueEqualsKey, "void", // This one fails. | 686 keys::kValueEqualsKey, "void", // This one fails. |
| 667 keys::kValueContainsKey, "alu" // This passes. | 687 keys::kValueContainsKey, "alu" // This passes. |
| 668 }; | 688 }; |
| 669 const size_t kDisjunctionSizes[] = { 2u, 2u, 2u, 2u }; | 689 const size_t kDisjunctionSizes[] = { 2u, 2u, 2u, 2u }; |
| 670 GetArrayAsVector(kDisjunction, kDisjunctionSizes, 4u, &tests); | 690 GetArrayAsVector(kDisjunction, kDisjunctionSizes, 4u, &tests); |
| 671 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, &url_request, &result); | 691 MatchAndCheck(tests, keys::kResponseHeadersKey, stage, url_request.get(), |
| 692 &result); |
| 672 EXPECT_TRUE(result); | 693 EXPECT_TRUE(result); |
| 673 | 694 |
| 674 // 3.a. -- This should pass. | 695 // 3.a. -- This should pass. |
| 675 const std::string kNonExistent[] = { | 696 const std::string kNonExistent[] = { |
| 676 keys::kNameEqualsKey, "Non-existing", | 697 keys::kNameEqualsKey, "Non-existing", |
| 677 keys::kValueEqualsKey, "void" | 698 keys::kValueEqualsKey, "void" |
| 678 }; | 699 }; |
| 679 const size_t kNonExistentSizes[] = { arraysize(kNonExistent) }; | 700 const size_t kNonExistentSizes[] = { arraysize(kNonExistent) }; |
| 680 GetArrayAsVector(kNonExistent, kNonExistentSizes, 1u, &tests); | 701 GetArrayAsVector(kNonExistent, kNonExistentSizes, 1u, &tests); |
| 681 MatchAndCheck( | 702 MatchAndCheck(tests, keys::kExcludeResponseHeadersKey, stage, |
| 682 tests, keys::kExcludeResponseHeadersKey, stage, &url_request, &result); | 703 url_request.get(), &result); |
| 683 EXPECT_TRUE(result); | 704 EXPECT_TRUE(result); |
| 684 | 705 |
| 685 // 3.b. -- This should fail. | 706 // 3.b. -- This should fail. |
| 686 const std::string kExisting[] = { | 707 const std::string kExisting[] = { |
| 687 keys::kNameEqualsKey, "custom-header-b", | 708 keys::kNameEqualsKey, "custom-header-b", |
| 688 keys::kValueEqualsKey, "valueB" | 709 keys::kValueEqualsKey, "valueB" |
| 689 }; | 710 }; |
| 690 const size_t kExistingSize[] = { arraysize(kExisting) }; | 711 const size_t kExistingSize[] = { arraysize(kExisting) }; |
| 691 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests); | 712 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests); |
| 692 MatchAndCheck( | 713 MatchAndCheck(tests, keys::kExcludeResponseHeadersKey, stage, |
| 693 tests, keys::kExcludeResponseHeadersKey, stage, &url_request, &result); | 714 url_request.get(), &result); |
| 694 EXPECT_FALSE(result); | 715 EXPECT_FALSE(result); |
| 695 } | 716 } |
| 696 | 717 |
| 697 } // namespace | 718 } // namespace |
| 698 } // namespace extensions | 719 } // namespace extensions |
| OLD | NEW |