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