Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc

Issue 12328079: Update TestURLRequest constructor interface in extensions unit tests. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Rebase onto master. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 resource_types.Append(Value::CreateStringValue("sub_frame")); 81 resource_types.Append(Value::CreateStringValue("sub_frame"));
82 82
83 scoped_ptr<WebRequestConditionAttribute> attribute = 83 scoped_ptr<WebRequestConditionAttribute> attribute =
84 WebRequestConditionAttribute::Create( 84 WebRequestConditionAttribute::Create(
85 keys::kResourceTypeKey, &resource_types, &error); 85 keys::kResourceTypeKey, &resource_types, &error);
86 EXPECT_EQ("", error); 86 EXPECT_EQ("", error);
87 ASSERT_TRUE(attribute.get()); 87 ASSERT_TRUE(attribute.get());
88 88
89 net::TestURLRequestContext context; 89 net::TestURLRequestContext context;
90 net::TestURLRequest url_request_ok( 90 net::TestURLRequest url_request_ok(
91 GURL("http://www.example.com"), NULL, &context); 91 GURL("http://www.example.com"), NULL, &context, NULL);
92 content::ResourceRequestInfo::AllocateForTesting(&url_request_ok, 92 content::ResourceRequestInfo::AllocateForTesting(&url_request_ok,
93 ResourceType::SUB_FRAME, NULL, -1, -1); 93 ResourceType::SUB_FRAME, NULL, -1, -1);
94 EXPECT_TRUE(attribute->IsFulfilled(WebRequestData(&url_request_ok, 94 EXPECT_TRUE(attribute->IsFulfilled(WebRequestData(&url_request_ok,
95 ON_BEFORE_REQUEST))); 95 ON_BEFORE_REQUEST)));
96 96
97 net::TestURLRequest url_request_fail( 97 net::TestURLRequest url_request_fail(
98 GURL("http://www.example.com"), NULL, &context); 98 GURL("http://www.example.com"), NULL, &context, NULL);
99 content::ResourceRequestInfo::AllocateForTesting(&url_request_fail, 99 content::ResourceRequestInfo::AllocateForTesting(&url_request_fail,
100 ResourceType::MAIN_FRAME, NULL, -1, -1); 100 ResourceType::MAIN_FRAME, NULL, -1, -1);
101 EXPECT_FALSE(attribute->IsFulfilled(WebRequestData(&url_request_fail, 101 EXPECT_FALSE(attribute->IsFulfilled(WebRequestData(&url_request_fail,
102 ON_BEFORE_REQUEST))); 102 ON_BEFORE_REQUEST)));
103 } 103 }
104 104
105 TEST(WebRequestConditionAttributeTest, ContentType) { 105 TEST(WebRequestConditionAttributeTest, ContentType) {
106 // Necessary for TestURLRequest. 106 // Necessary for TestURLRequest.
107 MessageLoop message_loop(MessageLoop::TYPE_IO); 107 MessageLoop message_loop(MessageLoop::TYPE_IO);
108 108
109 std::string error; 109 std::string error;
110 scoped_ptr<WebRequestConditionAttribute> result; 110 scoped_ptr<WebRequestConditionAttribute> result;
111 111
112 net::TestServer test_server( 112 net::TestServer test_server(
113 net::TestServer::TYPE_HTTP, 113 net::TestServer::TYPE_HTTP,
114 net::TestServer::kLocalhost, 114 net::TestServer::kLocalhost,
115 base::FilePath(FILE_PATH_LITERAL( 115 base::FilePath(FILE_PATH_LITERAL(
116 "chrome/test/data/extensions/api_test/webrequest/declarative"))); 116 "chrome/test/data/extensions/api_test/webrequest/declarative")));
117 ASSERT_TRUE(test_server.Start()); 117 ASSERT_TRUE(test_server.Start());
118 118
119 net::TestURLRequestContext context; 119 net::TestURLRequestContext context;
120 net::TestDelegate delegate; 120 net::TestDelegate delegate;
121 net::TestURLRequest url_request(test_server.GetURL("files/headers.html"), 121 net::TestURLRequest url_request(
122 &delegate, &context); 122 test_server.GetURL("files/headers.html"), &delegate, &context, NULL);
123 url_request.Start(); 123 url_request.Start();
124 MessageLoop::current()->Run(); 124 MessageLoop::current()->Run();
125 125
126 ListValue content_types; 126 ListValue content_types;
127 content_types.Append(Value::CreateStringValue("text/plain")); 127 content_types.Append(Value::CreateStringValue("text/plain"));
128 scoped_ptr<WebRequestConditionAttribute> attribute_include = 128 scoped_ptr<WebRequestConditionAttribute> attribute_include =
129 WebRequestConditionAttribute::Create( 129 WebRequestConditionAttribute::Create(
130 keys::kContentTypeKey, &content_types, &error); 130 keys::kContentTypeKey, &content_types, &error);
131 EXPECT_EQ("", error); 131 EXPECT_EQ("", error);
132 ASSERT_TRUE(attribute_include.get()); 132 ASSERT_TRUE(attribute_include.get());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 &value_false, 188 &value_false,
189 &error); 189 &error);
190 ASSERT_EQ("", error); 190 ASSERT_EQ("", error);
191 ASSERT_TRUE(first_party_attribute.get()); 191 ASSERT_TRUE(first_party_attribute.get());
192 192
193 const GURL url_empty; 193 const GURL url_empty;
194 const GURL url_a("http://a.com"); 194 const GURL url_a("http://a.com");
195 const GURL url_b("http://b.com"); 195 const GURL url_b("http://b.com");
196 net::TestURLRequestContext context; 196 net::TestURLRequestContext context;
197 net::TestDelegate delegate; 197 net::TestDelegate delegate;
198 net::TestURLRequest url_request(url_a, &delegate, &context); 198 net::TestURLRequest url_request(url_a, &delegate, &context, NULL);
199 199
200 for (unsigned int i = 1; i <= kLastActiveStage; i <<= 1) { 200 for (unsigned int i = 1; i <= kLastActiveStage; i <<= 1) {
201 if (!(kActiveStages & i)) 201 if (!(kActiveStages & i))
202 continue; 202 continue;
203 const RequestStage stage = static_cast<RequestStage>(i); 203 const RequestStage stage = static_cast<RequestStage>(i);
204 url_request.set_first_party_for_cookies(url_empty); 204 url_request.set_first_party_for_cookies(url_empty);
205 EXPECT_FALSE(third_party_attribute->IsFulfilled(WebRequestData(&url_request, 205 EXPECT_FALSE(third_party_attribute->IsFulfilled(WebRequestData(&url_request,
206 stage))); 206 stage)));
207 EXPECT_TRUE(first_party_attribute->IsFulfilled(WebRequestData(&url_request, 207 EXPECT_TRUE(first_party_attribute->IsFulfilled(WebRequestData(&url_request,
208 stage))); 208 stage)));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 WebRequestConditionAttribute::Create(keys::kStagesKey, 275 WebRequestConditionAttribute::Create(keys::kStagesKey,
276 &single_stage_list, 276 &single_stage_list,
277 &error).release()); 277 &error).release());
278 EXPECT_EQ("", error); 278 EXPECT_EQ("", error);
279 ASSERT_TRUE(one_stage_attributes.back() != NULL); 279 ASSERT_TRUE(one_stage_attributes.back() != NULL);
280 } 280 }
281 281
282 const GURL url_empty; 282 const GURL url_empty;
283 net::TestURLRequestContext context; 283 net::TestURLRequestContext context;
284 net::TestDelegate delegate; 284 net::TestDelegate delegate;
285 net::TestURLRequest url_request(url_empty, &delegate, &context); 285 net::TestURLRequest url_request(url_empty, &delegate, &context, NULL);
286 286
287 for (size_t i = 0; i < arraysize(active_stages); ++i) { 287 for (size_t i = 0; i < arraysize(active_stages); ++i) {
288 EXPECT_FALSE(empty_attribute->IsFulfilled( 288 EXPECT_FALSE(empty_attribute->IsFulfilled(
289 WebRequestData(&url_request, active_stages[i].first))); 289 WebRequestData(&url_request, active_stages[i].first)));
290 290
291 for (size_t j = 0; j < one_stage_attributes.size(); ++j) { 291 for (size_t j = 0; j < one_stage_attributes.size(); ++j) {
292 EXPECT_EQ(i == j, 292 EXPECT_EQ(i == j,
293 one_stage_attributes[j]->IsFulfilled( 293 one_stage_attributes[j]->IsFulfilled(
294 WebRequestData(&url_request, active_stages[i].first))); 294 WebRequestData(&url_request, active_stages[i].first)));
295 } 295 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 // correctly against request headers. This test is not as extensive as 397 // correctly against request headers. This test is not as extensive as
398 // "ResponseHeaders" (below), because the header-matching code is shared 398 // "ResponseHeaders" (below), because the header-matching code is shared
399 // by both types of condition attributes, so it is enough to test it once. 399 // by both types of condition attributes, so it is enough to test it once.
400 TEST(WebRequestConditionAttributeTest, RequestHeaders) { 400 TEST(WebRequestConditionAttributeTest, RequestHeaders) {
401 // Necessary for TestURLRequest. 401 // Necessary for TestURLRequest.
402 MessageLoop message_loop(MessageLoop::TYPE_IO); 402 MessageLoop message_loop(MessageLoop::TYPE_IO);
403 403
404 net::TestURLRequestContext context; 404 net::TestURLRequestContext context;
405 net::TestDelegate delegate; 405 net::TestDelegate delegate;
406 net::TestURLRequest url_request(GURL("http://example.com"), // Dummy URL. 406 net::TestURLRequest url_request(GURL("http://example.com"), // Dummy URL.
407 &delegate, &context); 407 &delegate, &context, NULL);
408 url_request.SetExtraRequestHeaderByName( 408 url_request.SetExtraRequestHeaderByName(
409 "Custom-header", "custom/value", true /* overwrite */); 409 "Custom-header", "custom/value", true /* overwrite */);
410 url_request.Start(); 410 url_request.Start();
411 MessageLoop::current()->Run(); 411 MessageLoop::current()->Run();
412 412
413 std::vector<std::vector<const std::string*> > tests; 413 std::vector<std::vector<const std::string*> > tests;
414 bool result = false; 414 bool result = false;
415 415
416 const RequestStage stage = ON_BEFORE_SEND_HEADERS; 416 const RequestStage stage = ON_BEFORE_SEND_HEADERS;
417 417
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 net::TestServer test_server( 482 net::TestServer test_server(
483 net::TestServer::TYPE_HTTP, 483 net::TestServer::TYPE_HTTP,
484 net::TestServer::kLocalhost, 484 net::TestServer::kLocalhost,
485 base::FilePath(FILE_PATH_LITERAL( 485 base::FilePath(FILE_PATH_LITERAL(
486 "chrome/test/data/extensions/api_test/webrequest/declarative"))); 486 "chrome/test/data/extensions/api_test/webrequest/declarative")));
487 ASSERT_TRUE(test_server.Start()); 487 ASSERT_TRUE(test_server.Start());
488 488
489 net::TestURLRequestContext context; 489 net::TestURLRequestContext context;
490 net::TestDelegate delegate; 490 net::TestDelegate delegate;
491 net::TestURLRequest url_request(test_server.GetURL("files/headers.html"), 491 net::TestURLRequest url_request(test_server.GetURL("files/headers.html"),
492 &delegate, &context); 492 &delegate, &context, NULL);
493 url_request.Start(); 493 url_request.Start();
494 MessageLoop::current()->Run(); 494 MessageLoop::current()->Run();
495 495
496 // In all the tests below we assume that the server includes the headers 496 // In all the tests below we assume that the server includes the headers
497 // Custom-Header: custom/value 497 // Custom-Header: custom/value
498 // Custom-Header-B: valueA 498 // Custom-Header-B: valueA
499 // Custom-Header-B: valueB 499 // Custom-Header-B: valueB
500 // Custom-Header-C: valueC, valueD 500 // Custom-Header-C: valueC, valueD
501 // Custom-Header-D: 501 // Custom-Header-D:
502 // in the response, but does not include "Non-existing: void". 502 // in the response, but does not include "Non-existing: void".
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 keys::kValueEqualsKey, "valueB" 651 keys::kValueEqualsKey, "valueB"
652 }; 652 };
653 const size_t kExistingSize[] = { arraysize(kExisting) }; 653 const size_t kExistingSize[] = { arraysize(kExisting) };
654 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests); 654 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests);
655 MatchAndCheck( 655 MatchAndCheck(
656 tests, keys::kExcludeResponseHeadersKey, stage, &url_request, &result); 656 tests, keys::kExcludeResponseHeadersKey, stage, &url_request, &result);
657 EXPECT_FALSE(result); 657 EXPECT_FALSE(result);
658 } 658 }
659 659
660 } // namespace extensions 660 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698