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", fire a POST URLRequest which is not a parseable |
| 490 // HTML form. Raw data should be returned. |
| 491 // 4. Do the same, but with a PUT method. Result should be the same. |
| 492 // Each of these steps is done once as if the channel was DEV or CANARY, |
| 493 // and once as if it was BETA or STABLE. It is checked that parsed data is |
| 494 // available on DEV/CANARY but not on BETA/STABLE. |
| 495 const std::string kMethodPost("POST"); |
| 496 const std::string kMethodPut("PUT"); |
| 497 |
| 498 // Input. |
| 499 const char kPlainBlock1[] = "abcd\n"; |
| 500 const size_t kPlainBlock1Length = sizeof(kPlainBlock1) - 1; |
| 501 std::vector<char> plain_1(kPlainBlock1, kPlainBlock1 + kPlainBlock1Length); |
| 502 const char kPlainBlock2[] = "1234\n"; |
| 503 const size_t kPlainBlock2Length = sizeof(kPlainBlock2) - 1; |
| 504 std::vector<char> plain_2(kPlainBlock2, kPlainBlock2 + kPlainBlock2Length); |
| 505 #define kBoundary "THIS_IS_A_BOUNDARY" |
| 506 const char kFormBlock1[] = "--" kBoundary "\r\n" |
| 507 "Content-Disposition: form-data; name=\"A\"\r\n" |
| 508 "\r\n" |
| 509 "test text\r\n" |
| 510 "--" kBoundary "\r\n" |
| 511 "Content-Disposition: form-data; name=\"B\"; filename=\"\"\r\n" |
| 512 "Content-Type: application/octet-stream\r\n" |
| 513 "\r\n"; |
| 514 std::vector<char> form_1(kFormBlock1, kFormBlock1 + sizeof(kFormBlock1) - 1); |
| 515 const char kFormBlock2[] = "\r\n" |
| 516 "--" kBoundary "\r\n" |
| 517 "Content-Disposition: form-data; name=\"C\"\r\n" |
| 518 "\r\n" |
| 519 "test password\r\n" |
| 520 "--" kBoundary "--"; |
| 521 std::vector<char> form_2(kFormBlock2, kFormBlock2 + sizeof(kFormBlock2) - 1); |
| 522 |
| 523 // Expected output. |
| 524 // Paths to look for in returned dictionaries. |
| 525 const std::string kBodyPath(keys::kRequestBodyKey); |
| 526 const std::string kFormDataPath( |
| 527 kBodyPath + "." + keys::kRequestBodyFormDataKey); |
| 528 const std::string kRawPath(kBodyPath + "." + keys::kRequestBodyRawKey); |
| 529 const std::string kErrorPath(kBodyPath + "." + keys::kRequestBodyErrorKey); |
| 530 const std::string* const kPath[] = { |
| 531 &kFormDataPath, |
| 532 &kBodyPath, |
| 533 &kRawPath, |
| 534 &kRawPath |
| 535 }; |
| 536 // Contents of formData. |
| 537 const char kFormData[] = |
| 538 "{\"A\":[\"test text\"],\"B\":[\"\"],\"C\":[\"test password\"]}"; |
| 539 scoped_ptr<const Value> form_data(base::JSONReader::Read(kFormData)); |
| 540 ASSERT_TRUE(form_data.get() != NULL); |
| 541 ASSERT_TRUE(form_data->GetType() == Value::TYPE_DICTIONARY); |
| 542 // Contents of raw. |
| 543 ListValue raw; |
| 544 extensions::RawDataPresenter::AppendResultWithKey( |
| 545 &raw, |
| 546 keys::kRequestBodyRawBytesKey, |
| 547 BinaryValue::CreateWithCopiedBuffer(kPlainBlock1, kPlainBlock1Length)); |
| 548 extensions::RawDataPresenter::AppendResultWithKey( |
| 549 &raw, |
| 550 keys::kRequestBodyRawFileKey, |
| 551 Value::CreateStringValue("")); |
| 552 extensions::RawDataPresenter::AppendResultWithKey( |
| 553 &raw, |
| 554 keys::kRequestBodyRawBytesKey, |
| 555 BinaryValue::CreateWithCopiedBuffer(kPlainBlock2, kPlainBlock2Length)); |
| 556 // Summary. |
| 557 const Value* const kExpected[] = { |
| 558 form_data.get(), |
| 559 NULL, |
| 560 &raw, |
| 561 &raw, |
| 562 NULL, NULL, NULL, NULL // These are for the disabled cases. |
| 563 }; |
| 564 // Header. |
| 565 const char kMultipart[] = "multipart/form-data; boundary=" kBoundary; |
| 566 #undef kBoundary |
| 567 |
| 568 // Set up a dummy extension name. |
| 569 const std::string kEventName(keys::kOnBeforeRequest); |
| 570 ExtensionWebRequestEventRouter::RequestFilter filter; |
| 571 std::string extension_id("1"); |
| 572 const std::string string_spec_post("blocking,requestBody"); |
| 573 const std::string string_spec_no_post("blocking"); |
| 574 int extra_info_spec_empty = 0; |
| 575 int extra_info_spec_body = 0; |
| 576 base::WeakPtrFactory<TestIPCSender> ipc_sender_factory(&ipc_sender_); |
| 577 |
| 578 // All the tests are done twice, once with the release channel pretending to |
| 579 // be one of DEV/CANARY, once BETA/STABLE. Hence two passes. |
| 580 for (int pass = 0; pass < 2; ++pass) { |
| 581 { |
| 582 Feature::ScopedCurrentChannel sc( |
| 583 pass > 0 ? VersionInfo::CHANNEL_BETA : VersionInfo::CHANNEL_CANARY); |
| 584 |
| 585 // Part 1. |
| 586 // Subscribe to OnBeforeRequest with requestBody requirement. |
| 587 ASSERT_TRUE(GenerateInfoSpec(string_spec_post, &extra_info_spec_body)); |
| 588 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
| 589 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", |
| 590 filter, extra_info_spec_body, ipc_sender_factory.GetWeakPtr()); |
| 591 |
| 592 FireURLRequestWithData(kMethodPost, kMultipart, form_1, form_2); |
| 593 |
| 594 MessageLoop::current()->RunAllPending(); |
| 595 // We inspect the result in the message list of |ipc_sender_| later. |
| 596 |
| 597 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
| 598 &profile_, extension_id, kEventName + "/1"); |
| 599 } |
| 600 |
| 601 { |
| 602 Feature::ScopedCurrentChannel sc( |
| 603 pass > 0 ? VersionInfo::CHANNEL_STABLE : VersionInfo::CHANNEL_DEV); |
| 604 |
| 605 // Part 2. |
| 606 // Now subscribe to OnBeforeRequest *without* the requestBody requirement. |
| 607 ASSERT_TRUE( |
| 608 GenerateInfoSpec(string_spec_no_post, &extra_info_spec_empty)); |
| 609 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
| 610 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", |
| 611 filter, extra_info_spec_empty, ipc_sender_factory.GetWeakPtr()); |
| 612 |
| 613 FireURLRequestWithData(kMethodPost, kMultipart, form_1, form_2); |
| 614 |
| 615 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
| 616 &profile_, extension_id, kEventName + "/1"); |
| 617 } |
| 618 |
| 619 { |
| 620 Feature::ScopedCurrentChannel sc( |
| 621 pass > 0 ? VersionInfo::CHANNEL_STABLE : VersionInfo::CHANNEL_DEV); |
| 622 |
| 623 // Subscribe to OnBeforeRequest with requestBody requirement. |
| 624 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
| 625 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", |
| 626 filter, extra_info_spec_body, ipc_sender_factory.GetWeakPtr()); |
| 627 |
| 628 // Part 3. |
| 629 // Now send a POST request with body which is not parseable as a form. |
| 630 FireURLRequestWithData(kMethodPost, NULL /*no header*/, plain_1, plain_2); |
| 631 |
| 632 // Part 4. |
| 633 // Now send a PUT request with the same body as above. |
| 634 FireURLRequestWithData(kMethodPut, NULL /*no header*/, plain_1, plain_2); |
| 635 |
| 636 MessageLoop::current()->RunAllPending(); |
| 637 |
| 638 // Clean-up. |
| 639 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
| 640 &profile_, extension_id, kEventName + "/1"); |
| 641 } |
| 642 } |
| 643 |
| 644 IPC::Message* message = NULL; |
| 645 TestIPCSender::SentMessages::const_iterator i = ipc_sender_.sent_begin(); |
| 646 for (size_t test = 0; test < arraysize(kExpected); ++test) { |
| 647 EXPECT_NE(i, ipc_sender_.sent_end()); |
| 648 message = (i++)->get(); |
| 649 const DictionaryValue* details; |
| 650 ExtensionMsg_MessageInvoke::Param param; |
| 651 GetPartOfMessageArguments(message, &details, ¶m); |
| 652 ASSERT_TRUE(details != NULL); |
| 653 const Value* result = NULL; |
| 654 EXPECT_EQ( |
| 655 kExpected[test] != NULL, |
| 656 details->Get(*(kPath[test % arraysize(kPath)]), &result)); |
| 657 if (kExpected[test] != NULL) { |
| 658 EXPECT_TRUE(kExpected[test]->Equals(result)); |
| 659 } |
| 660 } |
| 661 |
| 662 EXPECT_EQ(i, ipc_sender_.sent_end()); |
405 } | 663 } |
406 | 664 |
407 struct HeaderModificationTest_Header { | 665 struct HeaderModificationTest_Header { |
408 const char* name; | 666 const char* name; |
409 const char* value; | 667 const char* value; |
410 }; | 668 }; |
411 | 669 |
412 struct HeaderModificationTest_Modification { | 670 struct HeaderModificationTest_Modification { |
413 enum Type { | 671 enum Type { |
414 SET, | 672 SET, |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 875 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
618 &profile_, extension2_id, kEventName + "/2"); | 876 &profile_, extension2_id, kEventName + "/2"); |
619 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 877 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
620 &profile_, extension3_id, std::string(keys::kOnSendHeaders) + "/3"); | 878 &profile_, extension3_id, std::string(keys::kOnSendHeaders) + "/3"); |
621 }; | 879 }; |
622 | 880 |
623 namespace { | 881 namespace { |
624 | 882 |
625 void TestInitFromValue(const std::string& values, bool expected_return_code, | 883 void TestInitFromValue(const std::string& values, bool expected_return_code, |
626 int expected_extra_info_spec) { | 884 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; | 885 int actual_info_spec; |
634 bool actual_return_code = | 886 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); | 887 EXPECT_EQ(expected_return_code, actual_return_code); |
638 if (expected_return_code) | 888 if (expected_return_code) |
639 EXPECT_EQ(expected_extra_info_spec, actual_info_spec); | 889 EXPECT_EQ(expected_extra_info_spec, actual_info_spec); |
640 } | 890 } |
641 | 891 |
642 } | 892 } |
643 TEST_F(ExtensionWebRequestTest, InitFromValue) { | 893 TEST_F(ExtensionWebRequestTest, InitFromValue) { |
644 TestInitFromValue("", true, 0); | 894 TestInitFromValue("", true, 0); |
645 | 895 |
646 // Single valid values. | 896 // Single valid values. |
647 TestInitFromValue( | 897 TestInitFromValue( |
648 "requestHeaders", | 898 "requestHeaders", |
649 true, | 899 true, |
650 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS); | 900 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS); |
651 TestInitFromValue( | 901 TestInitFromValue( |
652 "responseHeaders", | 902 "responseHeaders", |
653 true, | 903 true, |
654 ExtensionWebRequestEventRouter::ExtraInfoSpec::RESPONSE_HEADERS); | 904 ExtensionWebRequestEventRouter::ExtraInfoSpec::RESPONSE_HEADERS); |
655 TestInitFromValue( | 905 TestInitFromValue( |
656 "blocking", | 906 "blocking", |
657 true, | 907 true, |
658 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); | 908 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); |
659 TestInitFromValue( | 909 TestInitFromValue( |
660 "asyncBlocking", | 910 "asyncBlocking", |
661 true, | 911 true, |
662 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING); | 912 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING); |
| 913 { |
| 914 Feature::ScopedCurrentChannel sc(VersionInfo::CHANNEL_BETA); |
| 915 TestInitFromValue( |
| 916 "requestBody", |
| 917 true, |
| 918 0); |
| 919 } |
| 920 { |
| 921 Feature::ScopedCurrentChannel sc(VersionInfo::CHANNEL_DEV); |
| 922 TestInitFromValue( |
| 923 "requestBody", |
| 924 true, |
| 925 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_BODY); |
| 926 } |
663 | 927 |
664 // Multiple valid values are bitwise-or'ed. | 928 // Multiple valid values are bitwise-or'ed. |
665 TestInitFromValue( | 929 TestInitFromValue( |
666 "requestHeaders,blocking", | 930 "requestHeaders,blocking", |
667 true, | 931 true, |
668 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS | | 932 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS | |
669 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); | 933 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); |
670 | 934 |
671 // Any invalid values lead to a bad parse. | 935 // Any invalid values lead to a bad parse. |
672 TestInitFromValue("invalidValue", false, 0); | 936 TestInitFromValue("invalidValue", false, 0); |
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1632 credentials_set = MergeOnAuthRequiredResponses( | 1896 credentials_set = MergeOnAuthRequiredResponses( |
1633 deltas, &auth3, &conflicting_extensions, &net_log); | 1897 deltas, &auth3, &conflicting_extensions, &net_log); |
1634 EXPECT_TRUE(credentials_set); | 1898 EXPECT_TRUE(credentials_set); |
1635 EXPECT_FALSE(auth3.Empty()); | 1899 EXPECT_FALSE(auth3.Empty()); |
1636 EXPECT_EQ(username, auth1.username()); | 1900 EXPECT_EQ(username, auth1.username()); |
1637 EXPECT_EQ(password, auth1.password()); | 1901 EXPECT_EQ(password, auth1.password()); |
1638 EXPECT_EQ(1u, conflicting_extensions.size()); | 1902 EXPECT_EQ(1u, conflicting_extensions.size()); |
1639 EXPECT_TRUE(ContainsKey(conflicting_extensions, "extid2")); | 1903 EXPECT_TRUE(ContainsKey(conflicting_extensions, "extid2")); |
1640 EXPECT_EQ(3u, capturing_net_log.GetSize()); | 1904 EXPECT_EQ(3u, capturing_net_log.GetSize()); |
1641 } | 1905 } |
1642 | |
OLD | NEW |