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/base64.h" |
8 #include "base/bind.h" | 9 #include "base/bind.h" |
9 #include "base/callback.h" | 10 #include "base/callback.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" |
25 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
26 #include "chrome/test/base/testing_browser_process.h" | 29 #include "chrome/test/base/testing_browser_process.h" |
27 #include "chrome/test/base/testing_pref_service.h" | 30 #include "chrome/test/base/testing_pref_service.h" |
28 #include "chrome/test/base/testing_profile.h" | 31 #include "chrome/test/base/testing_profile.h" |
29 #include "content/public/test/test_browser_thread.h" | 32 #include "content/public/test/test_browser_thread.h" |
30 #include "net/base/auth.h" | 33 #include "net/base/auth.h" |
31 #include "net/base/capturing_net_log.h" | 34 #include "net/base/capturing_net_log.h" |
32 #include "net/base/mock_host_resolver.h" | 35 #include "net/base/mock_host_resolver.h" |
33 #include "net/base/net_util.h" | 36 #include "net/base/net_util.h" |
34 #include "net/url_request/url_request_test_util.h" | 37 #include "net/url_request/url_request_test_util.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
36 | 39 |
37 namespace helpers = extension_web_request_api_helpers; | 40 namespace helpers = extension_web_request_api_helpers; |
38 namespace keys = extension_web_request_api_constants; | 41 namespace keys = extension_web_request_api_constants; |
39 | 42 |
| 43 using chrome::VersionInfo; |
40 using helpers::CalculateOnAuthRequiredDelta; | 44 using helpers::CalculateOnAuthRequiredDelta; |
41 using helpers::CalculateOnBeforeRequestDelta; | 45 using helpers::CalculateOnBeforeRequestDelta; |
42 using helpers::CalculateOnBeforeSendHeadersDelta; | 46 using helpers::CalculateOnBeforeSendHeadersDelta; |
43 using helpers::CalculateOnHeadersReceivedDelta; | 47 using helpers::CalculateOnHeadersReceivedDelta; |
44 using helpers::CharListToString; | 48 using helpers::CharListToString; |
45 using helpers::EventResponseDelta; | 49 using helpers::EventResponseDelta; |
46 using helpers::EventResponseDeltas; | 50 using helpers::EventResponseDeltas; |
47 using helpers::EventResponseDeltas; | 51 using helpers::EventResponseDeltas; |
48 using helpers::InDecreasingExtensionInstallationTimeOrder; | 52 using helpers::InDecreasingExtensionInstallationTimeOrder; |
49 using helpers::MergeCancelOfResponses; | 53 using helpers::MergeCancelOfResponses; |
(...skipping 18 matching lines...) Expand all Loading... |
68 } | 72 } |
69 | 73 |
70 // Searches |key| in |collection| by iterating over its elements and returns | 74 // Searches |key| in |collection| by iterating over its elements and returns |
71 // true if found. | 75 // true if found. |
72 template <typename Collection, typename Key> | 76 template <typename Collection, typename Key> |
73 bool Contains(const Collection& collection, const Key& key) { | 77 bool Contains(const Collection& collection, const Key& key) { |
74 return std::find(collection.begin(), collection.end(), key) != | 78 return std::find(collection.begin(), collection.end(), key) != |
75 collection.end(); | 79 collection.end(); |
76 } | 80 } |
77 | 81 |
| 82 // Parses |json_string| as a Value. Returns NULL on failure. |
| 83 scoped_ptr<const Value> GetValueFromJson(const base::StringPiece& json_string) { |
| 84 return scoped_ptr<const Value>(base::JSONReader::Read(json_string)); |
| 85 } |
| 86 |
| 87 // Parses the JSON data attached to the |message| and tries to return it. |
| 88 // Returns NULL on failure. |
| 89 void GetPartOfMessageArguments(IPC::Message* message, |
| 90 scoped_ptr<const DictionaryValue>* out) { |
| 91 ASSERT_EQ(ExtensionMsg_MessageInvoke::ID, message->type()); |
| 92 ExtensionMsg_MessageInvoke::Param param; |
| 93 Value* temp_value = NULL; |
| 94 ASSERT_TRUE(ExtensionMsg_MessageInvoke::Read(message, ¶m)); |
| 95 ASSERT_GE(param.c.GetSize(), 2u); |
| 96 ASSERT_TRUE(param.c.Get(1, &temp_value)); |
| 97 std::string args; |
| 98 ASSERT_TRUE(temp_value->GetAsString(&args)); |
| 99 scoped_ptr<const Value> value = GetValueFromJson(args); |
| 100 ASSERT_TRUE(value.get() != NULL); |
| 101 const ListValue* list = NULL; |
| 102 ASSERT_TRUE(value->GetAsList(&list)); |
| 103 ASSERT_EQ(1u, list->GetSize()); |
| 104 const DictionaryValue* dictionary_raw; |
| 105 ASSERT_TRUE(list->GetDictionary(0, &dictionary_raw)); |
| 106 scoped_ptr<const DictionaryValue> dictionary(dictionary_raw->DeepCopy()); |
| 107 out->swap(dictionary); |
| 108 ASSERT_TRUE(dictionary.get() == NULL); |
| 109 } |
| 110 |
78 } // namespace | 111 } // namespace |
79 | 112 |
80 // A mock event router that responds to events with a pre-arranged queue of | 113 // A mock event router that responds to events with a pre-arranged queue of |
81 // Tasks. | 114 // Tasks. |
82 class TestIPCSender : public IPC::Sender { | 115 class TestIPCSender : public IPC::Sender { |
83 public: | 116 public: |
84 typedef std::list<linked_ptr<IPC::Message> > SentMessages; | 117 typedef std::list<linked_ptr<IPC::Message> > SentMessages; |
85 | 118 |
86 // Adds a Task to the queue. We will fire these in order as events are | 119 // Adds a Task to the queue. We will fire these in order as events are |
87 // dispatched. | 120 // dispatched. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 prefs::kEnableReferrers, profile_.GetTestingPrefService(), NULL); | 162 prefs::kEnableReferrers, profile_.GetTestingPrefService(), NULL); |
130 network_delegate_.reset(new ChromeNetworkDelegate( | 163 network_delegate_.reset(new ChromeNetworkDelegate( |
131 event_router_.get(), NULL, NULL, &profile_, | 164 event_router_.get(), NULL, NULL, &profile_, |
132 CookieSettings::Factory::GetForProfile(&profile_), &enable_referrers_, | 165 CookieSettings::Factory::GetForProfile(&profile_), &enable_referrers_, |
133 NULL)); | 166 NULL)); |
134 context_.reset(new TestURLRequestContext(true)); | 167 context_.reset(new TestURLRequestContext(true)); |
135 context_->set_network_delegate(network_delegate_.get()); | 168 context_->set_network_delegate(network_delegate_.get()); |
136 context_->Init(); | 169 context_->Init(); |
137 } | 170 } |
138 | 171 |
| 172 // Fires a URLRequest with the specified |method|, |content_type| and the |
| 173 // data from |bytes|. |
| 174 void FireURLRequestWithData(const std::string& method, |
| 175 const char* content_type, |
| 176 const char* bytes, size_t bytes_length); |
| 177 |
139 MessageLoopForIO message_loop_; | 178 MessageLoopForIO message_loop_; |
140 content::TestBrowserThread ui_thread_; | 179 content::TestBrowserThread ui_thread_; |
141 content::TestBrowserThread io_thread_; | 180 content::TestBrowserThread io_thread_; |
142 TestingProfile profile_; | 181 TestingProfile profile_; |
143 TestDelegate delegate_; | 182 TestDelegate delegate_; |
144 BooleanPrefMember enable_referrers_; | 183 BooleanPrefMember enable_referrers_; |
145 TestIPCSender ipc_sender_; | 184 TestIPCSender ipc_sender_; |
146 scoped_refptr<extensions::EventRouterForwarder> event_router_; | 185 scoped_refptr<extensions::EventRouterForwarder> event_router_; |
147 scoped_refptr<ExtensionInfoMap> extension_info_map_; | 186 scoped_refptr<ExtensionInfoMap> extension_info_map_; |
148 scoped_ptr<ChromeNetworkDelegate> network_delegate_; | 187 scoped_ptr<ChromeNetworkDelegate> network_delegate_; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 EXPECT_TRUE(!request.is_pending()); | 433 EXPECT_TRUE(!request.is_pending()); |
395 EXPECT_EQ(net::URLRequestStatus::CANCELED, request.status().status()); | 434 EXPECT_EQ(net::URLRequestStatus::CANCELED, request.status().status()); |
396 EXPECT_EQ(net::ERR_ABORTED, request.status().error()); | 435 EXPECT_EQ(net::ERR_ABORTED, request.status().error()); |
397 EXPECT_EQ(request_url, request.url()); | 436 EXPECT_EQ(request_url, request.url()); |
398 EXPECT_EQ(1U, request.url_chain().size()); | 437 EXPECT_EQ(1U, request.url_chain().size()); |
399 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); | 438 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); |
400 | 439 |
401 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 440 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
402 &profile_, extension_id, kEventName + "/1"); | 441 &profile_, extension_id, kEventName + "/1"); |
403 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 442 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
404 &profile_, extension_id, kEventName2 + "/1"); | 443 &profile_, extension_id, kEventName2 + "/1"); |
| 444 } |
| 445 |
| 446 namespace { |
| 447 |
| 448 // Create the numerical representation of |values|, strings passed as |
| 449 // extraInfoSpec by the event handler. Returns true on success, otherwise false. |
| 450 bool GenerateInfoSpec(const std::string& values, int* result) { |
| 451 // Create a ListValue of strings. |
| 452 std::vector<std::string> split_values; |
| 453 scoped_ptr<base::ListValue> list_value(new base::ListValue()); |
| 454 size_t num_values = Tokenize(values, ",", &split_values); |
| 455 for (size_t i = 0; i < num_values ; ++i) |
| 456 list_value->Append(new base::StringValue(split_values[i])); |
| 457 return ExtensionWebRequestEventRouter::ExtraInfoSpec::InitFromValue( |
| 458 *list_value, result); |
| 459 } |
| 460 |
| 461 } // namespace |
| 462 |
| 463 void ExtensionWebRequestTest::FireURLRequestWithData( |
| 464 const std::string& method, |
| 465 const char* content_type, |
| 466 const char* bytes, size_t bytes_length) { |
| 467 // The request URL can be arbitrary but must have an HTTP or HTTPS scheme. |
| 468 GURL request_url("http://www.example.com"); |
| 469 net::URLRequest request(request_url, &delegate_, context_.get()); |
| 470 request.set_method(method); |
| 471 if (content_type != NULL) |
| 472 request.SetExtraRequestHeaderByName(net::HttpRequestHeaders::kContentType, |
| 473 content_type, |
| 474 true /* overwrite */); |
| 475 request.AppendBytesToUpload(bytes, bytes_length); |
| 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 "body" in ExtraInfoSpec and file a |
| 484 // POST URLRequest with a multipart-encoded form. See it getting parsed. |
| 485 // 2. Do the same, but without requesting "body". Nothing should be parsed. |
| 486 // 3. With "body" again, fire a POST URLRequest with a chunked upload. Get |
| 487 // the error message. |
| 488 // 4. With "body", fire a POST URLRequest which is not a parseable HTML form. |
| 489 // Raw data in Base64 encoding should be returned. |
| 490 // 5. Do the same, but with a PUT method. Result should be the same. |
| 491 // Each of these steps is done once as if the channel was DEV or CANARY, |
| 492 // and once as if it was BETA or STABLE. It is checked that parsed data is |
| 493 // available on DEV/CANARY but not on BETA/STABLE. |
| 494 const std::string kMethodPost("POST"); |
| 495 const std::string kMethodPut("PUT"); |
| 496 |
| 497 const char kPlainData[] = "abcd1234\n"; |
| 498 #define kBoundary "THIS_IS_A_BOUNDARY" |
| 499 #define kBlock "--" kBoundary "\r\n" \ |
| 500 "Content-Disposition: form-data; name=\"text\"\r\n" \ |
| 501 "\r\n" \ |
| 502 "test text\r\n" \ |
| 503 "--" kBoundary "--" |
| 504 // Input. |
| 505 const char kMultipartBytes[] = kBlock; |
| 506 // Expected output. |
| 507 std::string expectedPlainData; |
| 508 ASSERT_TRUE(base::Base64Encode(kPlainData, &expectedPlainData)); |
| 509 const std::string kBodyPath(keys::kBodyKey); |
| 510 const std::string kParsedFormPath(kBodyPath + "." + keys::kBodyParsedFormKey); |
| 511 const std::string kRawPath(kBodyPath + "." + keys::kBodyRawKey); |
| 512 const std::string kErrorPath(kBodyPath + "." + keys::kBodyErrorKey); |
| 513 const std::string* const kPath[] = { |
| 514 &kParsedFormPath, |
| 515 &kBodyPath, |
| 516 &kErrorPath, |
| 517 &kRawPath, |
| 518 &kRawPath |
| 519 }; |
| 520 // parsedForm |
| 521 const char kFormDataString[] = "{\"text\":[\"test text\"]}"; |
| 522 scoped_ptr<const Value> form_data(GetValueFromJson(kFormDataString)); |
| 523 ASSERT_TRUE(form_data.get() != NULL); |
| 524 ASSERT_TRUE(form_data->GetType() == Value::TYPE_DICTIONARY); |
| 525 // error |
| 526 const StringValue error("Not supported: data is uploaded chunked."); |
| 527 // raw |
| 528 const StringValue raw(expectedPlainData); |
| 529 // Summary. |
| 530 const Value* const kExpected[] = { |
| 531 form_data.get(), |
| 532 NULL, |
| 533 &error, |
| 534 &raw, |
| 535 &raw, |
| 536 NULL, NULL, NULL, NULL, NULL // These are for the disabled cases. |
| 537 }; |
| 538 // Header. |
| 539 const char kMultipart[] = "multipart/form-data; boundary=" kBoundary; |
| 540 #undef kBlock |
| 541 #undef kBoundary |
| 542 |
| 543 // Set up a dummy extension name. |
| 544 ExtensionWebRequestEventRouter::RequestFilter filter; |
| 545 std::string extension_id("1"); |
| 546 const std::string string_spec_post("blocking,body"); |
| 547 const std::string string_spec_no_post("blocking"); |
| 548 int extra_info_spec_empty = 0; |
| 549 int extra_info_spec_body = 0; |
| 550 |
| 551 for (int pass = 0; pass < 2; ++pass) { |
| 552 WebRequestSetChannelForTesting( |
| 553 pass > 0 ? VersionInfo::CHANNEL_BETA : VersionInfo::CHANNEL_CANARY); |
| 554 |
| 555 // Part 1. |
| 556 // Subscribe to OnBeforeRequest with request body requirement. |
| 557 ASSERT_TRUE(GenerateInfoSpec(string_spec_post, &extra_info_spec_body)); |
| 558 const std::string kEventName(keys::kOnBeforeRequest); |
| 559 base::WeakPtrFactory<TestIPCSender> ipc_sender_factory(&ipc_sender_); |
| 560 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
| 561 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", |
| 562 filter, extra_info_spec_body, ipc_sender_factory.GetWeakPtr()); |
| 563 |
| 564 FireURLRequestWithData( |
| 565 kMethodPost, kMultipart, kMultipartBytes, strlen(kMultipartBytes)); |
| 566 |
| 567 MessageLoop::current()->RunAllPending(); |
| 568 |
| 569 WebRequestSetChannelForTesting( |
| 570 pass > 0 ? VersionInfo::CHANNEL_STABLE : VersionInfo::CHANNEL_DEV); |
| 571 |
| 572 // Part 2. |
| 573 // Now remove the requirement of request body. |
| 574 ASSERT_TRUE( |
| 575 GenerateInfoSpec(string_spec_no_post, &extra_info_spec_empty)); |
| 576 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
| 577 &profile_, extension_id, kEventName + "/1"); |
| 578 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
| 579 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", |
| 580 filter, extra_info_spec_empty, ipc_sender_factory.GetWeakPtr()); |
| 581 |
| 582 FireURLRequestWithData( |
| 583 kMethodPost, kMultipart, kMultipartBytes, strlen(kMultipartBytes)); |
| 584 |
| 585 // Part 3. |
| 586 // Get back the requirement of request body. |
| 587 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
| 588 &profile_, extension_id, kEventName + "/1"); |
| 589 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
| 590 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", |
| 591 filter, extra_info_spec_body, ipc_sender_factory.GetWeakPtr()); |
| 592 { // Fire the request with chunked upload. |
| 593 GURL request_url("http://www.example.com"); |
| 594 net::URLRequest request(request_url, &delegate_, context_.get()); |
| 595 request.set_method("POST"); |
| 596 request.EnableChunkedUpload(); |
| 597 const char kDummyBytes[] = "dummy"; |
| 598 request.AppendChunkToUpload(kDummyBytes, strlen(kDummyBytes), true); |
| 599 net::HttpRequestHeaders headers(request.extra_request_headers()); |
| 600 headers.SetHeader(net::HttpRequestHeaders::kTransferEncoding, "chunked"); |
| 601 request.SetExtraRequestHeaders(headers); |
| 602 ipc_sender_.PushTask(base::Bind(&base::DoNothing)); |
| 603 request.Start(); |
| 604 } |
| 605 |
| 606 // Part 4. |
| 607 // Now send a POST request with body which is not parseable as a form. |
| 608 FireURLRequestWithData( |
| 609 kMethodPost, NULL /*no header*/, kPlainData, strlen(kPlainData)); |
| 610 |
| 611 // Part 5. |
| 612 // Now send a PUT request with the same body as above. |
| 613 FireURLRequestWithData( |
| 614 kMethodPut, NULL /*no header*/, kPlainData, strlen(kPlainData)); |
| 615 |
| 616 MessageLoop::current()->RunAllPending(); |
| 617 |
| 618 // Clean-up. |
| 619 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
| 620 &profile_, extension_id, kEventName + "/1"); |
| 621 } |
| 622 |
| 623 WebRequestResetChannelForTesting(); |
| 624 |
| 625 IPC::Message* message = NULL; |
| 626 TestIPCSender::SentMessages::const_iterator i = ipc_sender_.sent_begin(); |
| 627 for (size_t test = 0; test < arraysize(kExpected); ++test) { |
| 628 EXPECT_NE(i, ipc_sender_.sent_end()); |
| 629 message = (i++)->get(); |
| 630 scoped_ptr<const DictionaryValue> details; |
| 631 GetPartOfMessageArguments(message, &details); |
| 632 ASSERT_TRUE(details != NULL); |
| 633 const Value* result = NULL; |
| 634 EXPECT_EQ( |
| 635 kExpected[test] != NULL, |
| 636 details->Get(*(kPath[test % arraysize(kPath)]), &result)); |
| 637 if (kExpected[test] != NULL) { |
| 638 EXPECT_TRUE(kExpected[test]->Equals(result)); |
| 639 } |
| 640 } |
| 641 |
| 642 EXPECT_EQ(i, ipc_sender_.sent_end()); |
405 } | 643 } |
406 | 644 |
407 struct HeaderModificationTest_Header { | 645 struct HeaderModificationTest_Header { |
408 const char* name; | 646 const char* name; |
409 const char* value; | 647 const char* value; |
410 }; | 648 }; |
411 | 649 |
412 struct HeaderModificationTest_Modification { | 650 struct HeaderModificationTest_Modification { |
413 enum Type { | 651 enum Type { |
414 SET, | 652 SET, |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 862 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
625 &profile_, extension2_id, kEventName + "/2"); | 863 &profile_, extension2_id, kEventName + "/2"); |
626 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 864 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
627 &profile_, extension3_id, std::string(keys::kOnSendHeaders) + "/3"); | 865 &profile_, extension3_id, std::string(keys::kOnSendHeaders) + "/3"); |
628 }; | 866 }; |
629 | 867 |
630 namespace { | 868 namespace { |
631 | 869 |
632 void TestInitFromValue(const std::string& values, bool expected_return_code, | 870 void TestInitFromValue(const std::string& values, bool expected_return_code, |
633 int expected_extra_info_spec) { | 871 int expected_extra_info_spec) { |
634 // Create a ListValue of strings. | |
635 std::vector<std::string> split_values; | |
636 scoped_ptr<base::ListValue> list_value(new base::ListValue()); | |
637 size_t num_values = Tokenize(values, ",", &split_values); | |
638 for (size_t i = 0; i < num_values ; ++i) | |
639 list_value->Append(new base::StringValue(split_values[i])); | |
640 int actual_info_spec; | 872 int actual_info_spec; |
641 bool actual_return_code = | 873 bool actual_return_code = GenerateInfoSpec(values, &actual_info_spec); |
642 ExtensionWebRequestEventRouter::ExtraInfoSpec::InitFromValue( | |
643 *list_value, &actual_info_spec); | |
644 EXPECT_EQ(expected_return_code, actual_return_code); | 874 EXPECT_EQ(expected_return_code, actual_return_code); |
645 if (expected_return_code) | 875 if (expected_return_code) |
646 EXPECT_EQ(expected_extra_info_spec, actual_info_spec); | 876 EXPECT_EQ(expected_extra_info_spec, actual_info_spec); |
647 } | 877 } |
648 | 878 |
649 } | 879 } |
650 TEST_F(ExtensionWebRequestTest, InitFromValue) { | 880 TEST_F(ExtensionWebRequestTest, InitFromValue) { |
651 TestInitFromValue("", true, 0); | 881 TestInitFromValue("", true, 0); |
652 | 882 |
653 // Single valid values. | 883 // Single valid values. |
654 TestInitFromValue( | 884 TestInitFromValue( |
655 "requestHeaders", | 885 "requestHeaders", |
656 true, | 886 true, |
657 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS); | 887 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS); |
658 TestInitFromValue( | 888 TestInitFromValue( |
659 "responseHeaders", | 889 "responseHeaders", |
660 true, | 890 true, |
661 ExtensionWebRequestEventRouter::ExtraInfoSpec::RESPONSE_HEADERS); | 891 ExtensionWebRequestEventRouter::ExtraInfoSpec::RESPONSE_HEADERS); |
662 TestInitFromValue( | 892 TestInitFromValue( |
663 "blocking", | 893 "blocking", |
664 true, | 894 true, |
665 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); | 895 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); |
666 TestInitFromValue( | 896 TestInitFromValue( |
667 "asyncBlocking", | 897 "asyncBlocking", |
668 true, | 898 true, |
669 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING); | 899 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING); |
| 900 WebRequestSetChannelForTesting(VersionInfo::CHANNEL_BETA); |
| 901 TestInitFromValue( |
| 902 "body", |
| 903 true, |
| 904 0); |
| 905 WebRequestSetChannelForTesting(VersionInfo::CHANNEL_DEV); |
| 906 TestInitFromValue( |
| 907 "body", |
| 908 true, |
| 909 ExtensionWebRequestEventRouter::ExtraInfoSpec::BODY); |
| 910 WebRequestResetChannelForTesting(); |
670 | 911 |
671 // Multiple valid values are bitwise-or'ed. | 912 // Multiple valid values are bitwise-or'ed. |
672 TestInitFromValue( | 913 TestInitFromValue( |
673 "requestHeaders,blocking", | 914 "requestHeaders,blocking", |
674 true, | 915 true, |
675 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS | | 916 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS | |
676 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); | 917 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); |
677 | 918 |
678 // Any invalid values lead to a bad parse. | 919 // Any invalid values lead to a bad parse. |
679 TestInitFromValue("invalidValue", false, 0); | 920 TestInitFromValue("invalidValue", false, 0); |
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1639 credentials_set = MergeOnAuthRequiredResponses( | 1880 credentials_set = MergeOnAuthRequiredResponses( |
1640 deltas, &auth3, &conflicting_extensions, &net_log); | 1881 deltas, &auth3, &conflicting_extensions, &net_log); |
1641 EXPECT_TRUE(credentials_set); | 1882 EXPECT_TRUE(credentials_set); |
1642 EXPECT_FALSE(auth3.Empty()); | 1883 EXPECT_FALSE(auth3.Empty()); |
1643 EXPECT_EQ(username, auth1.username()); | 1884 EXPECT_EQ(username, auth1.username()); |
1644 EXPECT_EQ(password, auth1.password()); | 1885 EXPECT_EQ(password, auth1.password()); |
1645 EXPECT_EQ(1u, conflicting_extensions.size()); | 1886 EXPECT_EQ(1u, conflicting_extensions.size()); |
1646 EXPECT_TRUE(ContainsKey(conflicting_extensions, "extid2")); | 1887 EXPECT_TRUE(ContainsKey(conflicting_extensions, "extid2")); |
1647 EXPECT_EQ(3u, capturing_net_log.GetSize()); | 1888 EXPECT_EQ(3u, capturing_net_log.GetSize()); |
1648 } | 1889 } |
1649 | |
OLD | NEW |