Chromium Code Reviews| 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 <queue> | 5 #include <queue> |
| 6 #include <map> | 6 #include <map> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/file_path.h" | |
| 10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/json/json_reader.h" | |
| 11 #include "base/json/json_string_value_serializer.h" | 13 #include "base/json/json_string_value_serializer.h" |
| 12 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 13 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 14 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 15 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 18 #include "base/string_piece.h" | |
| 16 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/content_settings/cookie_settings.h" | 20 #include "chrome/browser/content_settings/cookie_settings.h" |
| 18 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 21 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
| 19 #include "chrome/browser/extensions/api/web_request/web_request_api_constants.h" | 22 #include "chrome/browser/extensions/api/web_request/web_request_api_constants.h" |
| 20 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" | 23 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" |
| 21 #include "chrome/browser/extensions/event_router_forwarder.h" | 24 #include "chrome/browser/extensions/event_router_forwarder.h" |
| 22 #include "chrome/browser/net/chrome_network_delegate.h" | 25 #include "chrome/browser/net/chrome_network_delegate.h" |
| 23 #include "chrome/browser/prefs/pref_member.h" | 26 #include "chrome/browser/prefs/pref_member.h" |
| 24 #include "chrome/common/extensions/extension_messages.h" | 27 #include "chrome/common/extensions/extension_messages.h" |
| 28 #include "chrome/common/extensions/features/feature.h" | |
| 25 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/test/base/testing_browser_process.h" | 30 #include "chrome/test/base/testing_browser_process.h" |
| 27 #include "chrome/test/base/testing_pref_service.h" | 31 #include "chrome/test/base/testing_pref_service.h" |
| 28 #include "chrome/test/base/testing_profile.h" | 32 #include "chrome/test/base/testing_profile.h" |
| 29 #include "content/public/test/test_browser_thread.h" | 33 #include "content/public/test/test_browser_thread.h" |
| 30 #include "net/base/auth.h" | 34 #include "net/base/auth.h" |
| 31 #include "net/base/capturing_net_log.h" | 35 #include "net/base/capturing_net_log.h" |
| 32 #include "net/base/mock_host_resolver.h" | 36 #include "net/base/mock_host_resolver.h" |
| 33 #include "net/base/net_util.h" | 37 #include "net/base/net_util.h" |
| 38 #include "net/base/upload_data.h" | |
| 34 #include "net/url_request/url_request_test_util.h" | 39 #include "net/url_request/url_request_test_util.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 40 #include "testing/gtest/include/gtest/gtest.h" |
| 36 | 41 |
| 37 namespace helpers = extension_web_request_api_helpers; | 42 namespace helpers = extension_web_request_api_helpers; |
| 38 namespace keys = extension_web_request_api_constants; | 43 namespace keys = extension_web_request_api_constants; |
| 39 | 44 |
| 45 using base::BinaryValue; | |
| 46 using base::DictionaryValue; | |
| 47 using base::ListValue; | |
| 48 using base::StringValue; | |
| 49 using base::Value; | |
| 50 using chrome::VersionInfo; | |
| 51 using extensions::Feature; | |
| 40 using helpers::CalculateOnAuthRequiredDelta; | 52 using helpers::CalculateOnAuthRequiredDelta; |
| 41 using helpers::CalculateOnBeforeRequestDelta; | 53 using helpers::CalculateOnBeforeRequestDelta; |
| 42 using helpers::CalculateOnBeforeSendHeadersDelta; | 54 using helpers::CalculateOnBeforeSendHeadersDelta; |
| 43 using helpers::CalculateOnHeadersReceivedDelta; | 55 using helpers::CalculateOnHeadersReceivedDelta; |
| 44 using helpers::CharListToString; | 56 using helpers::CharListToString; |
| 45 using helpers::EventResponseDelta; | 57 using helpers::EventResponseDelta; |
| 46 using helpers::EventResponseDeltas; | 58 using helpers::EventResponseDeltas; |
| 47 using helpers::EventResponseDeltas; | 59 using helpers::EventResponseDeltas; |
| 48 using helpers::InDecreasingExtensionInstallationTimeOrder; | 60 using helpers::InDecreasingExtensionInstallationTimeOrder; |
| 49 using helpers::MergeCancelOfResponses; | 61 using helpers::MergeCancelOfResponses; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 68 } | 80 } |
| 69 | 81 |
| 70 // Searches |key| in |collection| by iterating over its elements and returns | 82 // Searches |key| in |collection| by iterating over its elements and returns |
| 71 // true if found. | 83 // true if found. |
| 72 template <typename Collection, typename Key> | 84 template <typename Collection, typename Key> |
| 73 bool Contains(const Collection& collection, const Key& key) { | 85 bool Contains(const Collection& collection, const Key& key) { |
| 74 return std::find(collection.begin(), collection.end(), key) != | 86 return std::find(collection.begin(), collection.end(), key) != |
| 75 collection.end(); | 87 collection.end(); |
| 76 } | 88 } |
| 77 | 89 |
| 90 // Parses the JSON data attached to the |message| and tries to return it. | |
| 91 // |param| must outlive |out|. Returns NULL on failure. | |
| 92 void GetPartOfMessageArguments(IPC::Message* message, | |
| 93 const DictionaryValue** out, | |
| 94 ExtensionMsg_MessageInvoke::Param* param) { | |
| 95 ASSERT_EQ(ExtensionMsg_MessageInvoke::ID, message->type()); | |
| 96 ASSERT_TRUE(ExtensionMsg_MessageInvoke::Read(message, param)); | |
| 97 ASSERT_GE(param->c.GetSize(), 2u); | |
| 98 const Value* value = NULL; | |
| 99 ASSERT_TRUE(param->c.Get(1, &value)); | |
| 100 const ListValue* list = NULL; | |
| 101 ASSERT_TRUE(value->GetAsList(&list)); | |
| 102 ASSERT_EQ(1u, list->GetSize()); | |
| 103 ASSERT_TRUE(list->GetDictionary(0, out)); | |
| 104 } | |
| 105 | |
| 78 } // namespace | 106 } // namespace |
| 79 | 107 |
| 80 // A mock event router that responds to events with a pre-arranged queue of | 108 // A mock event router that responds to events with a pre-arranged queue of |
| 81 // Tasks. | 109 // Tasks. |
| 82 class TestIPCSender : public IPC::Sender { | 110 class TestIPCSender : public IPC::Sender { |
| 83 public: | 111 public: |
| 84 typedef std::list<linked_ptr<IPC::Message> > SentMessages; | 112 typedef std::list<linked_ptr<IPC::Message> > SentMessages; |
| 85 | 113 |
| 86 // Adds a Task to the queue. We will fire these in order as events are | 114 // Adds a Task to the queue. We will fire these in order as events are |
| 87 // dispatched. | 115 // dispatched. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 prefs::kEnableReferrers, profile_.GetTestingPrefService(), NULL); | 157 prefs::kEnableReferrers, profile_.GetTestingPrefService(), NULL); |
| 130 network_delegate_.reset(new ChromeNetworkDelegate( | 158 network_delegate_.reset(new ChromeNetworkDelegate( |
| 131 event_router_.get(), NULL, NULL, NULL, &profile_, | 159 event_router_.get(), NULL, NULL, NULL, &profile_, |
| 132 CookieSettings::Factory::GetForProfile(&profile_), &enable_referrers_, | 160 CookieSettings::Factory::GetForProfile(&profile_), &enable_referrers_, |
| 133 NULL)); | 161 NULL)); |
| 134 context_.reset(new TestURLRequestContext(true)); | 162 context_.reset(new TestURLRequestContext(true)); |
| 135 context_->set_network_delegate(network_delegate_.get()); | 163 context_->set_network_delegate(network_delegate_.get()); |
| 136 context_->Init(); | 164 context_->Init(); |
| 137 } | 165 } |
| 138 | 166 |
| 167 // Fires a URLRequest with the specified |method|, |content_type| and three | |
| 168 // elements of upload data: bytes_1, a dummy empty file, bytes_2. | |
| 169 void FireURLRequestWithData(const std::string& method, | |
| 170 const char* content_type, | |
| 171 const std::vector<char>& bytes_1, | |
| 172 const std::vector<char>& bytes_2); | |
| 173 | |
| 139 MessageLoopForIO message_loop_; | 174 MessageLoopForIO message_loop_; |
| 140 content::TestBrowserThread ui_thread_; | 175 content::TestBrowserThread ui_thread_; |
| 141 content::TestBrowserThread io_thread_; | 176 content::TestBrowserThread io_thread_; |
| 142 TestingProfile profile_; | 177 TestingProfile profile_; |
| 143 TestDelegate delegate_; | 178 TestDelegate delegate_; |
| 144 BooleanPrefMember enable_referrers_; | 179 BooleanPrefMember enable_referrers_; |
| 145 TestIPCSender ipc_sender_; | 180 TestIPCSender ipc_sender_; |
| 146 scoped_refptr<extensions::EventRouterForwarder> event_router_; | 181 scoped_refptr<extensions::EventRouterForwarder> event_router_; |
| 147 scoped_refptr<ExtensionInfoMap> extension_info_map_; | 182 scoped_refptr<ExtensionInfoMap> extension_info_map_; |
| 148 scoped_ptr<ChromeNetworkDelegate> network_delegate_; | 183 scoped_ptr<ChromeNetworkDelegate> network_delegate_; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 EXPECT_TRUE(!request.is_pending()); | 429 EXPECT_TRUE(!request.is_pending()); |
| 395 EXPECT_EQ(net::URLRequestStatus::CANCELED, request.status().status()); | 430 EXPECT_EQ(net::URLRequestStatus::CANCELED, request.status().status()); |
| 396 EXPECT_EQ(net::ERR_ABORTED, request.status().error()); | 431 EXPECT_EQ(net::ERR_ABORTED, request.status().error()); |
| 397 EXPECT_EQ(request_url, request.url()); | 432 EXPECT_EQ(request_url, request.url()); |
| 398 EXPECT_EQ(1U, request.url_chain().size()); | 433 EXPECT_EQ(1U, request.url_chain().size()); |
| 399 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); | 434 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); |
| 400 | 435 |
| 401 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 436 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
| 402 &profile_, extension_id, kEventName + "/1"); | 437 &profile_, extension_id, kEventName + "/1"); |
| 403 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 438 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
| 404 &profile_, extension_id, kEventName2 + "/1"); | 439 &profile_, extension_id, kEventName2 + "/1"); |
| 440 } | |
| 441 | |
| 442 namespace { | |
| 443 | |
| 444 // Create the numerical representation of |values|, strings passed as | |
| 445 // extraInfoSpec by the event handler. Returns true on success, otherwise false. | |
| 446 bool GenerateInfoSpec(const std::string& values, int* result) { | |
| 447 // Create a ListValue of strings. | |
| 448 std::vector<std::string> split_values; | |
| 449 base::ListValue list_value; | |
| 450 size_t num_values = Tokenize(values, ",", &split_values); | |
| 451 for (size_t i = 0; i < num_values ; ++i) | |
| 452 list_value.Append(new base::StringValue(split_values[i])); | |
| 453 return ExtensionWebRequestEventRouter::ExtraInfoSpec::InitFromValue( | |
| 454 list_value, result); | |
| 455 } | |
| 456 | |
| 457 } // namespace | |
| 458 | |
| 459 void ExtensionWebRequestTest::FireURLRequestWithData( | |
| 460 const std::string& method, | |
| 461 const char* content_type, | |
| 462 const std::vector<char>& bytes_1, | |
| 463 const std::vector<char>& bytes_2) { | |
| 464 // The request URL can be arbitrary but must have an HTTP or HTTPS scheme. | |
| 465 GURL request_url("http://www.example.com"); | |
| 466 net::URLRequest request(request_url, &delegate_, context_.get()); | |
| 467 request.set_method(method); | |
| 468 if (content_type != NULL) | |
| 469 request.SetExtraRequestHeaderByName(net::HttpRequestHeaders::kContentType, | |
| 470 content_type, | |
| 471 true /* overwrite */); | |
| 472 request.AppendBytesToUpload(&(bytes_1[0]), bytes_1.size()); | |
| 473 net::UploadData* data = request.get_upload_mutable(); | |
| 474 data->AppendFileRange(::FilePath(), 0, 0, base::Time()); | |
| 475 request.AppendBytesToUpload(&(bytes_2[0]), bytes_2.size()); | |
| 476 ipc_sender_.PushTask(base::Bind(&base::DoNothing)); | |
| 477 request.Start(); | |
| 478 } | |
| 479 | |
| 480 TEST_F(ExtensionWebRequestTest, AccessRequestBodyData) { | |
| 481 // We verify that URLRequest body is accessible to OnBeforeRequest listeners. | |
| 482 // These testing steps are repeated twice in a row: | |
| 483 // 1. Register an extension requesting "requestBody" in ExtraInfoSpec and | |
| 484 // file a POST URLRequest with a multipart-encoded form. See it getting | |
| 485 // parsed. | |
| 486 // 2. Do the same, but without requesting "requestBody". Nothing should be | |
| 487 // parsed. | |
| 488 // 3. With "requestBody" again, fire a POST URLRequest with a chunked upload. | |
| 489 // Get the error message. | |
| 490 // 4. With "requestBody", fire a POST URLRequest which is not a parseable | |
| 491 // HTML form. Raw data should be returned. | |
| 492 // 5. Do the same, but with a PUT method. Result should be the same. | |
| 493 // Each of these steps is done once as if the channel was DEV or CANARY, | |
| 494 // and once as if it was BETA or STABLE. It is checked that parsed data is | |
| 495 // available on DEV/CANARY but not on BETA/STABLE. | |
| 496 const std::string kMethodPost("POST"); | |
| 497 const std::string kMethodPut("PUT"); | |
| 498 | |
| 499 // Input. | |
| 500 const char kPlainBlock1[] = "abcd\n"; | |
| 501 const size_t kPlainBlock1Length = strlen(kPlainBlock1); | |
| 502 std::vector<char> plain_1(kPlainBlock1, kPlainBlock1 + kPlainBlock1Length); | |
| 503 const char kPlainBlock2[] = "1234\n"; | |
| 504 const size_t kPlainBlock2Length = strlen(kPlainBlock2); | |
| 505 std::vector<char> plain_2(kPlainBlock2, kPlainBlock2 + kPlainBlock2Length); | |
| 506 #define kBoundary "THIS_IS_A_BOUNDARY" | |
| 507 const char kFormBlock1[] = "--" kBoundary "\r\n" | |
| 508 "Content-Disposition: form-data; name=\"A\"\r\n" | |
| 509 "\r\n" | |
| 510 "test text\r\n" | |
| 511 "--" kBoundary "\r\n" | |
| 512 "Content-Disposition: form-data; name=\"B\"; filename=\"\"\r\n" | |
| 513 "Content-Type: application/octet-stream\r\n" | |
| 514 "\r\n"; | |
| 515 std::vector<char> form_1(kFormBlock1, kFormBlock1 + strlen(kFormBlock1)); | |
| 516 const char kFormBlock2[] = "\r\n" | |
| 517 "--" kBoundary "\r\n" | |
| 518 "Content-Disposition: form-data; name=\"C\"\r\n" | |
| 519 "\r\n" | |
| 520 "test password\r\n" | |
| 521 "--" kBoundary "--"; | |
| 522 std::vector<char> form_2(kFormBlock2, kFormBlock2 + strlen(kFormBlock2)); | |
| 523 | |
| 524 // Expected output. | |
| 525 // Paths to look for in returned dictionaries. | |
| 526 const std::string kBodyPath(keys::kRequestBodyKey); | |
| 527 const std::string kFormDataPath( | |
| 528 kBodyPath + "." + keys::kRequestBodyFormDataKey); | |
| 529 const std::string kRawPath(kBodyPath + "." + keys::kRequestBodyRawKey); | |
| 530 const std::string kErrorPath(kBodyPath + "." + keys::kRequestBodyErrorKey); | |
| 531 const std::string* const kPath[] = { | |
| 532 &kFormDataPath, | |
| 533 &kBodyPath, | |
| 534 &kErrorPath, | |
| 535 &kRawPath, | |
| 536 &kRawPath | |
| 537 }; | |
| 538 // Contents of formData. | |
| 539 const char kFormData[] = | |
| 540 "{\"A\":[\"test text\"],\"B\":[\"\"],\"C\":[\"test password\"]}"; | |
| 541 scoped_ptr<const Value> form_data(base::JSONReader::Read(kFormData)); | |
| 542 ASSERT_TRUE(form_data.get() != NULL); | |
| 543 ASSERT_TRUE(form_data->GetType() == Value::TYPE_DICTIONARY); | |
| 544 // Contents of error. | |
| 545 const StringValue error("Not supported: data is uploaded chunked."); | |
| 546 // Contents of raw. | |
| 547 ListValue raw; | |
| 548 raw.Append( | |
| 549 BinaryValue::CreateWithCopiedBuffer(kPlainBlock1, kPlainBlock1Length)); | |
| 550 raw.Append(new StringValue("")); | |
| 551 raw.Append( | |
| 552 BinaryValue::CreateWithCopiedBuffer(kPlainBlock2, kPlainBlock2Length)); | |
| 553 // Summary. | |
| 554 const Value* const kExpected[] = { | |
| 555 form_data.get(), | |
| 556 NULL, | |
| 557 &error, | |
| 558 &raw, | |
| 559 &raw, | |
| 560 NULL, NULL, NULL, NULL, NULL // These are for the disabled cases. | |
| 561 }; | |
| 562 // Header. | |
| 563 const char kMultipart[] = "multipart/form-data; boundary=" kBoundary; | |
| 564 #undef kBoundary | |
| 565 | |
| 566 // Set up a dummy extension name. | |
| 567 const std::string kEventName(keys::kOnBeforeRequest); | |
| 568 ExtensionWebRequestEventRouter::RequestFilter filter; | |
| 569 std::string extension_id("1"); | |
| 570 const std::string string_spec_post("blocking,requestBody"); | |
| 571 const std::string string_spec_no_post("blocking"); | |
| 572 int extra_info_spec_empty = 0; | |
| 573 int extra_info_spec_body = 0; | |
| 574 base::WeakPtrFactory<TestIPCSender> ipc_sender_factory(&ipc_sender_); | |
| 575 | |
| 576 // All the tests are done twice, once with the release channel pretending to | |
| 577 // be one of DEV/CANARY, once BETA/STABLE. Hence two passes. | |
| 578 for (int pass = 0; pass < 2; ++pass) { | |
| 579 { | |
| 580 Feature::ScopedCurrentChannel sc( | |
| 581 pass > 0 ? VersionInfo::CHANNEL_BETA : VersionInfo::CHANNEL_CANARY); | |
| 582 | |
| 583 // Part 1. | |
| 584 // Subscribe to OnBeforeRequest with requestBody requirement. | |
| 585 ASSERT_TRUE(GenerateInfoSpec(string_spec_post, &extra_info_spec_body)); | |
| 586 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | |
| 587 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", | |
| 588 filter, extra_info_spec_body, ipc_sender_factory.GetWeakPtr()); | |
| 589 | |
| 590 FireURLRequestWithData(kMethodPost, kMultipart, form_1, form_2); | |
| 591 | |
| 592 MessageLoop::current()->RunAllPending(); | |
|
battre
2012/08/20 12:09:39
Please add comment that result of this operation g
vabr (Chromium)
2012/08/23 15:41:54
Done.
| |
| 593 } | |
| 594 | |
| 595 { | |
| 596 Feature::ScopedCurrentChannel sc( | |
| 597 pass > 0 ? VersionInfo::CHANNEL_STABLE : VersionInfo::CHANNEL_DEV); | |
| 598 | |
| 599 // Part 2. | |
| 600 // Now remove the requirement of requestBody. | |
| 601 ASSERT_TRUE( | |
| 602 GenerateInfoSpec(string_spec_no_post, &extra_info_spec_empty)); | |
| 603 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | |
| 604 &profile_, extension_id, kEventName + "/1"); | |
|
battre
2012/08/20 12:09:39
Can you move this to the previous loop?
vabr (Chromium)
2012/08/23 15:41:54
Done. (Moved to the previous scope, not loop.)
| |
| 605 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | |
| 606 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", | |
| 607 filter, extra_info_spec_empty, ipc_sender_factory.GetWeakPtr()); | |
|
battre
2012/08/20 12:09:39
Can you point out that the difference to the previ
vabr (Chromium)
2012/08/23 15:41:54
I tried to clarify the comment just below "Part 2.
| |
| 608 | |
| 609 FireURLRequestWithData(kMethodPost, kMultipart, form_1, form_2); | |
| 610 | |
| 611 // Part 3. | |
| 612 // Get back the requirement of requestBody. | |
| 613 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | |
| 614 &profile_, extension_id, kEventName + "/1"); | |
| 615 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | |
| 616 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", | |
| 617 filter, extra_info_spec_body, ipc_sender_factory.GetWeakPtr()); | |
| 618 { // Fire the request with chunked upload. | |
| 619 GURL request_url("http://www.example.com"); | |
| 620 net::URLRequest request(request_url, &delegate_, context_.get()); | |
| 621 request.set_method("POST"); | |
| 622 request.EnableChunkedUpload(); | |
| 623 const char kDummyBytes[] = "dummy"; | |
| 624 request.AppendChunkToUpload(kDummyBytes, strlen(kDummyBytes), true); | |
| 625 net::HttpRequestHeaders headers(request.extra_request_headers()); | |
| 626 headers.SetHeader( | |
| 627 net::HttpRequestHeaders::kTransferEncoding, "chunked"); | |
| 628 request.SetExtraRequestHeaders(headers); | |
| 629 ipc_sender_.PushTask(base::Bind(&base::DoNothing)); | |
| 630 request.Start(); | |
| 631 } | |
| 632 | |
| 633 // Part 4. | |
| 634 // Now send a POST request with body which is not parseable as a form. | |
| 635 FireURLRequestWithData(kMethodPost, NULL /*no header*/, plain_1, plain_2); | |
| 636 | |
| 637 // Part 5. | |
| 638 // Now send a PUT request with the same body as above. | |
| 639 FireURLRequestWithData(kMethodPut, NULL /*no header*/, plain_1, plain_2); | |
| 640 | |
| 641 MessageLoop::current()->RunAllPending(); | |
| 642 | |
| 643 // Clean-up. | |
| 644 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | |
| 645 &profile_, extension_id, kEventName + "/1"); | |
| 646 } | |
| 647 } | |
| 648 | |
| 649 IPC::Message* message = NULL; | |
| 650 TestIPCSender::SentMessages::const_iterator i = ipc_sender_.sent_begin(); | |
| 651 for (size_t test = 0; test < arraysize(kExpected); ++test) { | |
| 652 EXPECT_NE(i, ipc_sender_.sent_end()); | |
| 653 message = (i++)->get(); | |
| 654 const DictionaryValue* details; | |
| 655 ExtensionMsg_MessageInvoke::Param param; | |
| 656 GetPartOfMessageArguments(message, &details, ¶m); | |
| 657 ASSERT_TRUE(details != NULL); | |
| 658 const Value* result = NULL; | |
| 659 EXPECT_EQ( | |
| 660 kExpected[test] != NULL, | |
| 661 details->Get(*(kPath[test % arraysize(kPath)]), &result)); | |
| 662 if (kExpected[test] != NULL) { | |
| 663 EXPECT_TRUE(kExpected[test]->Equals(result)); | |
| 664 } | |
| 665 } | |
| 666 | |
| 667 EXPECT_EQ(i, ipc_sender_.sent_end()); | |
| 405 } | 668 } |
| 406 | 669 |
| 407 struct HeaderModificationTest_Header { | 670 struct HeaderModificationTest_Header { |
| 408 const char* name; | 671 const char* name; |
| 409 const char* value; | 672 const char* value; |
| 410 }; | 673 }; |
| 411 | 674 |
| 412 struct HeaderModificationTest_Modification { | 675 struct HeaderModificationTest_Modification { |
| 413 enum Type { | 676 enum Type { |
| 414 SET, | 677 SET, |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 880 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
| 618 &profile_, extension2_id, kEventName + "/2"); | 881 &profile_, extension2_id, kEventName + "/2"); |
| 619 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 882 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
| 620 &profile_, extension3_id, std::string(keys::kOnSendHeaders) + "/3"); | 883 &profile_, extension3_id, std::string(keys::kOnSendHeaders) + "/3"); |
| 621 }; | 884 }; |
| 622 | 885 |
| 623 namespace { | 886 namespace { |
| 624 | 887 |
| 625 void TestInitFromValue(const std::string& values, bool expected_return_code, | 888 void TestInitFromValue(const std::string& values, bool expected_return_code, |
| 626 int expected_extra_info_spec) { | 889 int expected_extra_info_spec) { |
| 627 // Create a ListValue of strings. | |
| 628 std::vector<std::string> split_values; | |
| 629 scoped_ptr<base::ListValue> list_value(new base::ListValue()); | |
| 630 size_t num_values = Tokenize(values, ",", &split_values); | |
| 631 for (size_t i = 0; i < num_values ; ++i) | |
| 632 list_value->Append(new base::StringValue(split_values[i])); | |
| 633 int actual_info_spec; | 890 int actual_info_spec; |
| 634 bool actual_return_code = | 891 bool actual_return_code = GenerateInfoSpec(values, &actual_info_spec); |
| 635 ExtensionWebRequestEventRouter::ExtraInfoSpec::InitFromValue( | |
| 636 *list_value, &actual_info_spec); | |
| 637 EXPECT_EQ(expected_return_code, actual_return_code); | 892 EXPECT_EQ(expected_return_code, actual_return_code); |
| 638 if (expected_return_code) | 893 if (expected_return_code) |
| 639 EXPECT_EQ(expected_extra_info_spec, actual_info_spec); | 894 EXPECT_EQ(expected_extra_info_spec, actual_info_spec); |
| 640 } | 895 } |
| 641 | 896 |
| 642 } | 897 } |
| 643 TEST_F(ExtensionWebRequestTest, InitFromValue) { | 898 TEST_F(ExtensionWebRequestTest, InitFromValue) { |
| 644 TestInitFromValue("", true, 0); | 899 TestInitFromValue("", true, 0); |
| 645 | 900 |
| 646 // Single valid values. | 901 // Single valid values. |
| 647 TestInitFromValue( | 902 TestInitFromValue( |
| 648 "requestHeaders", | 903 "requestHeaders", |
| 649 true, | 904 true, |
| 650 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS); | 905 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS); |
| 651 TestInitFromValue( | 906 TestInitFromValue( |
| 652 "responseHeaders", | 907 "responseHeaders", |
| 653 true, | 908 true, |
| 654 ExtensionWebRequestEventRouter::ExtraInfoSpec::RESPONSE_HEADERS); | 909 ExtensionWebRequestEventRouter::ExtraInfoSpec::RESPONSE_HEADERS); |
| 655 TestInitFromValue( | 910 TestInitFromValue( |
| 656 "blocking", | 911 "blocking", |
| 657 true, | 912 true, |
| 658 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); | 913 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); |
| 659 TestInitFromValue( | 914 TestInitFromValue( |
| 660 "asyncBlocking", | 915 "asyncBlocking", |
| 661 true, | 916 true, |
| 662 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING); | 917 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING); |
| 918 { | |
| 919 Feature::ScopedCurrentChannel sc(VersionInfo::CHANNEL_BETA); | |
| 920 TestInitFromValue( | |
| 921 "requestBody", | |
| 922 true, | |
| 923 0); | |
| 924 } | |
| 925 { | |
| 926 Feature::ScopedCurrentChannel sc(VersionInfo::CHANNEL_DEV); | |
| 927 TestInitFromValue( | |
| 928 "requestBody", | |
| 929 true, | |
| 930 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_BODY); | |
| 931 } | |
| 663 | 932 |
| 664 // Multiple valid values are bitwise-or'ed. | 933 // Multiple valid values are bitwise-or'ed. |
| 665 TestInitFromValue( | 934 TestInitFromValue( |
| 666 "requestHeaders,blocking", | 935 "requestHeaders,blocking", |
| 667 true, | 936 true, |
| 668 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS | | 937 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS | |
| 669 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); | 938 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); |
| 670 | 939 |
| 671 // Any invalid values lead to a bad parse. | 940 // Any invalid values lead to a bad parse. |
| 672 TestInitFromValue("invalidValue", false, 0); | 941 TestInitFromValue("invalidValue", false, 0); |
| (...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1632 credentials_set = MergeOnAuthRequiredResponses( | 1901 credentials_set = MergeOnAuthRequiredResponses( |
| 1633 deltas, &auth3, &conflicting_extensions, &net_log); | 1902 deltas, &auth3, &conflicting_extensions, &net_log); |
| 1634 EXPECT_TRUE(credentials_set); | 1903 EXPECT_TRUE(credentials_set); |
| 1635 EXPECT_FALSE(auth3.Empty()); | 1904 EXPECT_FALSE(auth3.Empty()); |
| 1636 EXPECT_EQ(username, auth1.username()); | 1905 EXPECT_EQ(username, auth1.username()); |
| 1637 EXPECT_EQ(password, auth1.password()); | 1906 EXPECT_EQ(password, auth1.password()); |
| 1638 EXPECT_EQ(1u, conflicting_extensions.size()); | 1907 EXPECT_EQ(1u, conflicting_extensions.size()); |
| 1639 EXPECT_TRUE(ContainsKey(conflicting_extensions, "extid2")); | 1908 EXPECT_TRUE(ContainsKey(conflicting_extensions, "extid2")); |
| 1640 EXPECT_EQ(3u, capturing_net_log.GetSize()); | 1909 EXPECT_EQ(3u, capturing_net_log.GetSize()); |
| 1641 } | 1910 } |
| 1642 | |
| OLD | NEW |