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 <map> | 5 #include <map> |
6 #include <queue> | 6 #include <queue> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 232 |
233 net::URLRequestJobFactoryImpl job_factory; | 233 net::URLRequestJobFactoryImpl job_factory; |
234 job_factory.SetProtocolHandler( | 234 job_factory.SetProtocolHandler( |
235 url::kAboutScheme, new chrome_browser_net::AboutProtocolHandler()); | 235 url::kAboutScheme, new chrome_browser_net::AboutProtocolHandler()); |
236 context_->set_job_factory(&job_factory); | 236 context_->set_job_factory(&job_factory); |
237 | 237 |
238 GURL redirect_url("about:redirected"); | 238 GURL redirect_url("about:redirected"); |
239 GURL not_chosen_redirect_url("about:not_chosen"); | 239 GURL not_chosen_redirect_url("about:not_chosen"); |
240 | 240 |
241 scoped_ptr<net::URLRequest> request(context_->CreateRequest( | 241 scoped_ptr<net::URLRequest> request(context_->CreateRequest( |
242 GURL("about:blank"), net::DEFAULT_PRIORITY, &delegate_, NULL)); | 242 GURL("about:blank"), net::DEFAULT_PRIORITY, &delegate_)); |
243 { | 243 { |
244 // onBeforeRequest will be dispatched twice initially. The second response - | 244 // onBeforeRequest will be dispatched twice initially. The second response - |
245 // the redirect - should win, since it has a later |install_time|. The | 245 // the redirect - should win, since it has a later |install_time|. The |
246 // redirect will dispatch another pair of onBeforeRequest. There, the first | 246 // redirect will dispatch another pair of onBeforeRequest. There, the first |
247 // response should win (later |install_time|). | 247 // response should win (later |install_time|). |
248 ExtensionWebRequestEventRouter::EventResponse* response = NULL; | 248 ExtensionWebRequestEventRouter::EventResponse* response = NULL; |
249 | 249 |
250 // Extension1 response. Arrives first, but ignored due to install_time. | 250 // Extension1 response. Arrives first, but ignored due to install_time. |
251 response = new ExtensionWebRequestEventRouter::EventResponse( | 251 response = new ExtensionWebRequestEventRouter::EventResponse( |
252 extension1_id, base::Time::FromDoubleT(1)); | 252 extension1_id, base::Time::FromDoubleT(1)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 EXPECT_TRUE(!request->is_pending()); | 287 EXPECT_TRUE(!request->is_pending()); |
288 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); | 288 EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status()); |
289 EXPECT_EQ(0, request->status().error()); | 289 EXPECT_EQ(0, request->status().error()); |
290 EXPECT_EQ(redirect_url, request->url()); | 290 EXPECT_EQ(redirect_url, request->url()); |
291 EXPECT_EQ(2U, request->url_chain().size()); | 291 EXPECT_EQ(2U, request->url_chain().size()); |
292 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); | 292 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); |
293 } | 293 } |
294 | 294 |
295 // Now test the same thing but the extensions answer in reverse order. | 295 // Now test the same thing but the extensions answer in reverse order. |
296 scoped_ptr<net::URLRequest> request2(context_->CreateRequest( | 296 scoped_ptr<net::URLRequest> request2(context_->CreateRequest( |
297 GURL("about:blank"), net::DEFAULT_PRIORITY, &delegate_, NULL)); | 297 GURL("about:blank"), net::DEFAULT_PRIORITY, &delegate_)); |
298 { | 298 { |
299 ExtensionWebRequestEventRouter::EventResponse* response = NULL; | 299 ExtensionWebRequestEventRouter::EventResponse* response = NULL; |
300 | 300 |
301 // Extension2 response. Arrives first, and chosen because of install_time. | 301 // Extension2 response. Arrives first, and chosen because of install_time. |
302 response = new ExtensionWebRequestEventRouter::EventResponse( | 302 response = new ExtensionWebRequestEventRouter::EventResponse( |
303 extension2_id, base::Time::FromDoubleT(2)); | 303 extension2_id, base::Time::FromDoubleT(2)); |
304 response->new_url = redirect_url; | 304 response->new_url = redirect_url; |
305 ipc_sender_.PushTask( | 305 ipc_sender_.PushTask( |
306 base::Bind(&EventHandledOnIOThread, | 306 base::Bind(&EventHandledOnIOThread, |
307 &profile_, extension2_id, kEventName, kEventName + "/2", | 307 &profile_, extension2_id, kEventName, kEventName + "/2", |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 &profile_, extension1_id, extension1_id, kEventName, kEventName + "/1", | 361 &profile_, extension1_id, extension1_id, kEventName, kEventName + "/1", |
362 filter, ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING, 0, 0, | 362 filter, ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING, 0, 0, |
363 ipc_sender_factory.GetWeakPtr()); | 363 ipc_sender_factory.GetWeakPtr()); |
364 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | 364 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
365 &profile_, extension2_id, extension2_id, kEventName, kEventName + "/2", | 365 &profile_, extension2_id, extension2_id, kEventName, kEventName + "/2", |
366 filter, ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING, 0, 0, | 366 filter, ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING, 0, 0, |
367 ipc_sender_factory.GetWeakPtr()); | 367 ipc_sender_factory.GetWeakPtr()); |
368 | 368 |
369 GURL request_url("about:blank"); | 369 GURL request_url("about:blank"); |
370 scoped_ptr<net::URLRequest> request(context_->CreateRequest( | 370 scoped_ptr<net::URLRequest> request(context_->CreateRequest( |
371 request_url, net::DEFAULT_PRIORITY, &delegate_, NULL)); | 371 request_url, net::DEFAULT_PRIORITY, &delegate_)); |
372 | 372 |
373 // onBeforeRequest will be dispatched twice. The second response - | 373 // onBeforeRequest will be dispatched twice. The second response - |
374 // the redirect - would win, since it has a later |install_time|, but | 374 // the redirect - would win, since it has a later |install_time|, but |
375 // the first response takes precedence because cancel >> redirect. | 375 // the first response takes precedence because cancel >> redirect. |
376 GURL redirect_url("about:redirected"); | 376 GURL redirect_url("about:redirected"); |
377 ExtensionWebRequestEventRouter::EventResponse* response = NULL; | 377 ExtensionWebRequestEventRouter::EventResponse* response = NULL; |
378 | 378 |
379 // Extension1 response. Arrives first, would be ignored in principle due to | 379 // Extension1 response. Arrives first, would be ignored in principle due to |
380 // install_time but "cancel" always wins. | 380 // install_time but "cancel" always wins. |
381 response = new ExtensionWebRequestEventRouter::EventResponse( | 381 response = new ExtensionWebRequestEventRouter::EventResponse( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | 429 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
430 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", | 430 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", |
431 filter, ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING, 0, 0, | 431 filter, ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING, 0, 0, |
432 ipc_sender_factory.GetWeakPtr()); | 432 ipc_sender_factory.GetWeakPtr()); |
433 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | 433 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
434 &profile_, extension_id, extension_id, kEventName2, kEventName2 + "/1", | 434 &profile_, extension_id, extension_id, kEventName2, kEventName2 + "/1", |
435 filter, 0, 0, 0, ipc_sender_factory.GetWeakPtr()); | 435 filter, 0, 0, 0, ipc_sender_factory.GetWeakPtr()); |
436 | 436 |
437 GURL request_url("about:blank"); | 437 GURL request_url("about:blank"); |
438 scoped_ptr<net::URLRequest> request(context_->CreateRequest( | 438 scoped_ptr<net::URLRequest> request(context_->CreateRequest( |
439 request_url, net::DEFAULT_PRIORITY, &delegate_, NULL)); | 439 request_url, net::DEFAULT_PRIORITY, &delegate_)); |
440 | 440 |
441 ExtensionWebRequestEventRouter::EventResponse* response = NULL; | 441 ExtensionWebRequestEventRouter::EventResponse* response = NULL; |
442 | 442 |
443 // Extension response for the OnBeforeRequest handler. This should not be | 443 // Extension response for the OnBeforeRequest handler. This should not be |
444 // processed because request is canceled before the handler responds. | 444 // processed because request is canceled before the handler responds. |
445 response = new ExtensionWebRequestEventRouter::EventResponse( | 445 response = new ExtensionWebRequestEventRouter::EventResponse( |
446 extension_id, base::Time::FromDoubleT(1)); | 446 extension_id, base::Time::FromDoubleT(1)); |
447 GURL redirect_url("about:redirected"); | 447 GURL redirect_url("about:redirected"); |
448 response->new_url = redirect_url; | 448 response->new_url = redirect_url; |
449 ipc_sender_.PushTask( | 449 ipc_sender_.PushTask( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 } // namespace | 493 } // namespace |
494 | 494 |
495 void ExtensionWebRequestTest::FireURLRequestWithData( | 495 void ExtensionWebRequestTest::FireURLRequestWithData( |
496 const std::string& method, | 496 const std::string& method, |
497 const char* content_type, | 497 const char* content_type, |
498 const std::vector<char>& bytes_1, | 498 const std::vector<char>& bytes_1, |
499 const std::vector<char>& bytes_2) { | 499 const std::vector<char>& bytes_2) { |
500 // The request URL can be arbitrary but must have an HTTP or HTTPS scheme. | 500 // The request URL can be arbitrary but must have an HTTP or HTTPS scheme. |
501 GURL request_url("http://www.example.com"); | 501 GURL request_url("http://www.example.com"); |
502 scoped_ptr<net::URLRequest> request(context_->CreateRequest( | 502 scoped_ptr<net::URLRequest> request(context_->CreateRequest( |
503 request_url, net::DEFAULT_PRIORITY, &delegate_, NULL)); | 503 request_url, net::DEFAULT_PRIORITY, &delegate_)); |
504 request->set_method(method); | 504 request->set_method(method); |
505 if (content_type != NULL) { | 505 if (content_type != NULL) { |
506 request->SetExtraRequestHeaderByName(net::HttpRequestHeaders::kContentType, | 506 request->SetExtraRequestHeaderByName(net::HttpRequestHeaders::kContentType, |
507 content_type, | 507 content_type, |
508 true /* overwrite */); | 508 true /* overwrite */); |
509 } | 509 } |
510 ScopedVector<net::UploadElementReader> element_readers; | 510 ScopedVector<net::UploadElementReader> element_readers; |
511 element_readers.push_back(new net::UploadBytesElementReader( | 511 element_readers.push_back(new net::UploadBytesElementReader( |
512 &(bytes_1[0]), bytes_1.size())); | 512 &(bytes_1[0]), bytes_1.size())); |
513 element_readers.push_back( | 513 element_readers.push_back( |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 // Subscribe to OnBeforeRequest with requestBody requirement. | 709 // Subscribe to OnBeforeRequest with requestBody requirement. |
710 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | 710 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
711 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", | 711 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", |
712 filter, extra_info_spec, 0, 0, ipc_sender_factory.GetWeakPtr()); | 712 filter, extra_info_spec, 0, 0, ipc_sender_factory.GetWeakPtr()); |
713 | 713 |
714 // The request URL can be arbitrary but must have an HTTP or HTTPS scheme. | 714 // The request URL can be arbitrary but must have an HTTP or HTTPS scheme. |
715 const GURL request_url("http://www.example.com"); | 715 const GURL request_url("http://www.example.com"); |
716 | 716 |
717 for (size_t i = 0; i < arraysize(kMethods); ++i) { | 717 for (size_t i = 0; i < arraysize(kMethods); ++i) { |
718 scoped_ptr<net::URLRequest> request(context_->CreateRequest( | 718 scoped_ptr<net::URLRequest> request(context_->CreateRequest( |
719 request_url, net::DEFAULT_PRIORITY, &delegate_, NULL)); | 719 request_url, net::DEFAULT_PRIORITY, &delegate_)); |
720 request->set_method(kMethods[i]); | 720 request->set_method(kMethods[i]); |
721 ipc_sender_.PushTask(base::Bind(&base::DoNothing)); | 721 ipc_sender_.PushTask(base::Bind(&base::DoNothing)); |
722 request->Start(); | 722 request->Start(); |
723 } | 723 } |
724 | 724 |
725 // We inspect the result in the message list of |ipc_sender_| later. | 725 // We inspect the result in the message list of |ipc_sender_| later. |
726 base::MessageLoop::current()->RunUntilIdle(); | 726 base::MessageLoop::current()->RunUntilIdle(); |
727 | 727 |
728 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 728 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
729 &profile_, extension_id, kEventName + "/1", 0, 0); | 729 &profile_, extension_id, kEventName + "/1", 0, 0); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 | 830 |
831 // Install one extension that observes the final headers. | 831 // Install one extension that observes the final headers. |
832 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | 832 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
833 &profile_, extension3_id, extension3_id, keys::kOnSendHeadersEvent, | 833 &profile_, extension3_id, extension3_id, keys::kOnSendHeadersEvent, |
834 std::string(keys::kOnSendHeadersEvent) + "/3", filter, | 834 std::string(keys::kOnSendHeadersEvent) + "/3", filter, |
835 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS, 0, 0, | 835 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS, 0, 0, |
836 ipc_sender_factory.GetWeakPtr()); | 836 ipc_sender_factory.GetWeakPtr()); |
837 | 837 |
838 GURL request_url("http://doesnotexist/does_not_exist.html"); | 838 GURL request_url("http://doesnotexist/does_not_exist.html"); |
839 scoped_ptr<net::URLRequest> request(context_->CreateRequest( | 839 scoped_ptr<net::URLRequest> request(context_->CreateRequest( |
840 request_url, net::DEFAULT_PRIORITY, &delegate_, NULL)); | 840 request_url, net::DEFAULT_PRIORITY, &delegate_)); |
841 | 841 |
842 // Initialize headers available before extensions are notified of the | 842 // Initialize headers available before extensions are notified of the |
843 // onBeforeSendHeaders event. | 843 // onBeforeSendHeaders event. |
844 HeaderModificationTest test = GetParam(); | 844 HeaderModificationTest test = GetParam(); |
845 net::HttpRequestHeaders before_headers; | 845 net::HttpRequestHeaders before_headers; |
846 for (int i = 0; i < test.before_size; ++i) | 846 for (int i = 0; i < test.before_size; ++i) |
847 before_headers.SetHeader(test.before[i].name, test.before[i].value); | 847 before_headers.SetHeader(test.before[i].name, test.before[i].value); |
848 request->SetExtraRequestHeaders(before_headers); | 848 request->SetExtraRequestHeaders(before_headers); |
849 | 849 |
850 // Gather the modifications to the headers for the respective extensions. | 850 // Gather the modifications to the headers for the respective extensions. |
(...skipping 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2227 EXPECT_TRUE(credentials_set); | 2227 EXPECT_TRUE(credentials_set); |
2228 EXPECT_FALSE(auth3.Empty()); | 2228 EXPECT_FALSE(auth3.Empty()); |
2229 EXPECT_EQ(username, auth1.username()); | 2229 EXPECT_EQ(username, auth1.username()); |
2230 EXPECT_EQ(password, auth1.password()); | 2230 EXPECT_EQ(password, auth1.password()); |
2231 EXPECT_EQ(1u, warning_set.size()); | 2231 EXPECT_EQ(1u, warning_set.size()); |
2232 EXPECT_TRUE(HasWarning(warning_set, "extid2")); | 2232 EXPECT_TRUE(HasWarning(warning_set, "extid2")); |
2233 EXPECT_EQ(3u, capturing_net_log.GetSize()); | 2233 EXPECT_EQ(3u, capturing_net_log.GetSize()); |
2234 } | 2234 } |
2235 | 2235 |
2236 } // namespace extensions | 2236 } // namespace extensions |
OLD | NEW |