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" |
11 #include "base/file_path.h" | |
10 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/json/json_reader.h" | |
11 #include "base/json/json_string_value_serializer.h" | 14 #include "base/json/json_string_value_serializer.h" |
12 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
13 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
14 #include "base/path_service.h" | 17 #include "base/path_service.h" |
15 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
19 #include "base/string_piece.h" | |
16 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
17 #include "chrome/browser/content_settings/cookie_settings.h" | 21 #include "chrome/browser/content_settings/cookie_settings.h" |
18 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 22 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
19 #include "chrome/browser/extensions/api/web_request/web_request_api_constants.h" | 23 #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" | 24 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" |
21 #include "chrome/browser/extensions/event_router_forwarder.h" | 25 #include "chrome/browser/extensions/event_router_forwarder.h" |
22 #include "chrome/browser/net/chrome_network_delegate.h" | 26 #include "chrome/browser/net/chrome_network_delegate.h" |
23 #include "chrome/browser/prefs/pref_member.h" | 27 #include "chrome/browser/prefs/pref_member.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, &profile_, | 160 event_router_.get(), 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 scoped_ptr<base::ListValue> list_value(new base::ListValue()); | |
battre
2012/08/16 19:18:03
nit: you can use a base::ListValue instead of scop
vabr (Chromium)
2012/08/17 18:29:57
Done.
| |
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 raw.Append( | |
550 BinaryValue::CreateWithCopiedBuffer(kPlainBlock1, kPlainBlock1Length)); | |
551 raw.Append(new StringValue("")); | |
552 raw.Append( | |
553 BinaryValue::CreateWithCopiedBuffer(kPlainBlock2, kPlainBlock2Length)); | |
554 // Summary. | |
555 const Value* const kExpected[] = { | |
556 form_data.get(), | |
557 NULL, | |
558 &error, | |
559 &raw, | |
560 &raw, | |
561 NULL, NULL, NULL, NULL, NULL // These are for the disabled cases. | |
562 }; | |
563 // Header. | |
564 const char kMultipart[] = "multipart/form-data; boundary=" kBoundary; | |
565 #undef kBoundary | |
566 | |
567 // Set up a dummy extension name. | |
568 const std::string kEventName(keys::kOnBeforeRequest); | |
569 ExtensionWebRequestEventRouter::RequestFilter filter; | |
570 std::string extension_id("1"); | |
571 const std::string string_spec_post("blocking,requestBody"); | |
572 const std::string string_spec_no_post("blocking"); | |
573 int extra_info_spec_empty = 0; | |
574 int extra_info_spec_body = 0; | |
575 base::WeakPtrFactory<TestIPCSender> ipc_sender_factory(&ipc_sender_); | |
576 | |
577 for (int pass = 0; pass < 2; ++pass) { | |
battre
2012/08/16 19:18:03
Can you add a comment, why you have these passes?
vabr (Chromium)
2012/08/17 18:29:57
Done.
| |
578 { | |
579 Feature::ScopedCurrentChannel sc( | |
580 pass > 0 ? VersionInfo::CHANNEL_BETA : VersionInfo::CHANNEL_CANARY); | |
581 | |
582 // Part 1. | |
583 // Subscribe to OnBeforeRequest with requestBody requirement. | |
584 ASSERT_TRUE(GenerateInfoSpec(string_spec_post, &extra_info_spec_body)); | |
585 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | |
586 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", | |
587 filter, extra_info_spec_body, ipc_sender_factory.GetWeakPtr()); | |
588 | |
589 FireURLRequestWithData(kMethodPost, kMultipart, form_1, form_2); | |
590 | |
591 MessageLoop::current()->RunAllPending(); | |
592 } | |
593 | |
594 { | |
595 Feature::ScopedCurrentChannel sc( | |
596 pass > 0 ? VersionInfo::CHANNEL_STABLE : VersionInfo::CHANNEL_DEV); | |
597 | |
598 // Part 2. | |
599 // Now remove the requirement of requestBody. | |
600 ASSERT_TRUE( | |
601 GenerateInfoSpec(string_spec_no_post, &extra_info_spec_empty)); | |
602 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | |
603 &profile_, extension_id, kEventName + "/1"); | |
604 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | |
605 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", | |
606 filter, extra_info_spec_empty, ipc_sender_factory.GetWeakPtr()); | |
607 | |
608 FireURLRequestWithData(kMethodPost, kMultipart, form_1, form_2); | |
609 | |
610 // Part 3. | |
611 // Get back the requirement of requestBody. | |
612 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | |
613 &profile_, extension_id, kEventName + "/1"); | |
614 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | |
vabr (Chromium)
2012/08/17 18:29:57
Here I am adding a listener which stays through pa
| |
615 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", | |
616 filter, extra_info_spec_body, ipc_sender_factory.GetWeakPtr()); | |
617 { // Fire the request with chunked upload. | |
618 GURL request_url("http://www.example.com"); | |
619 net::URLRequest request(request_url, &delegate_, context_.get()); | |
620 request.set_method("POST"); | |
621 request.EnableChunkedUpload(); | |
622 const char kDummyBytes[] = "dummy"; | |
623 request.AppendChunkToUpload(kDummyBytes, strlen(kDummyBytes), true); | |
624 net::HttpRequestHeaders headers(request.extra_request_headers()); | |
625 headers.SetHeader( | |
626 net::HttpRequestHeaders::kTransferEncoding, "chunked"); | |
627 request.SetExtraRequestHeaders(headers); | |
628 ipc_sender_.PushTask(base::Bind(&base::DoNothing)); | |
629 request.Start(); | |
630 } | |
631 | |
632 // Part 4. | |
633 // Now send a POST request with body which is not parseable as a form. | |
battre
2012/08/16 19:18:03
Why do you do this while no listener is subscribed
vabr (Chromium)
2012/08/17 18:29:57
I believe there is a listener subscribed (marked b
| |
634 FireURLRequestWithData(kMethodPost, NULL /*no header*/, plain_1, plain_2); | |
battre
2012/08/16 19:18:03
Validate the generated event data?
vabr (Chromium)
2012/08/17 18:29:57
I don't understand your question. If you ask where
| |
635 | |
636 // Part 5. | |
637 // Now send a PUT request with the same body as above. | |
638 FireURLRequestWithData(kMethodPut, NULL /*no header*/, plain_1, plain_2); | |
639 | |
640 MessageLoop::current()->RunAllPending(); | |
641 | |
642 // Clean-up. | |
643 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | |
644 &profile_, extension_id, kEventName + "/1"); | |
645 } | |
646 } | |
647 | |
648 IPC::Message* message = NULL; | |
649 TestIPCSender::SentMessages::const_iterator i = ipc_sender_.sent_begin(); | |
650 for (size_t test = 0; test < arraysize(kExpected); ++test) { | |
651 EXPECT_NE(i, ipc_sender_.sent_end()); | |
652 message = (i++)->get(); | |
653 const DictionaryValue* details; | |
654 ExtensionMsg_MessageInvoke::Param param; | |
655 GetPartOfMessageArguments(message, &details, ¶m); | |
656 ASSERT_TRUE(details != NULL); | |
657 const Value* result = NULL; | |
658 EXPECT_EQ( | |
659 kExpected[test] != NULL, | |
660 details->Get(*(kPath[test % arraysize(kPath)]), &result)); | |
661 if (kExpected[test] != NULL) { | |
662 EXPECT_TRUE(kExpected[test]->Equals(result)); | |
663 } | |
664 } | |
665 | |
666 EXPECT_EQ(i, ipc_sender_.sent_end()); | |
405 } | 667 } |
406 | 668 |
407 struct HeaderModificationTest_Header { | 669 struct HeaderModificationTest_Header { |
408 const char* name; | 670 const char* name; |
409 const char* value; | 671 const char* value; |
410 }; | 672 }; |
411 | 673 |
412 struct HeaderModificationTest_Modification { | 674 struct HeaderModificationTest_Modification { |
413 enum Type { | 675 enum Type { |
414 SET, | 676 SET, |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
617 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 879 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
618 &profile_, extension2_id, kEventName + "/2"); | 880 &profile_, extension2_id, kEventName + "/2"); |
619 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 881 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
620 &profile_, extension3_id, std::string(keys::kOnSendHeaders) + "/3"); | 882 &profile_, extension3_id, std::string(keys::kOnSendHeaders) + "/3"); |
621 }; | 883 }; |
622 | 884 |
623 namespace { | 885 namespace { |
624 | 886 |
625 void TestInitFromValue(const std::string& values, bool expected_return_code, | 887 void TestInitFromValue(const std::string& values, bool expected_return_code, |
626 int expected_extra_info_spec) { | 888 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; | 889 int actual_info_spec; |
634 bool actual_return_code = | 890 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); | 891 EXPECT_EQ(expected_return_code, actual_return_code); |
638 if (expected_return_code) | 892 if (expected_return_code) |
639 EXPECT_EQ(expected_extra_info_spec, actual_info_spec); | 893 EXPECT_EQ(expected_extra_info_spec, actual_info_spec); |
640 } | 894 } |
641 | 895 |
642 } | 896 } |
643 TEST_F(ExtensionWebRequestTest, InitFromValue) { | 897 TEST_F(ExtensionWebRequestTest, InitFromValue) { |
644 TestInitFromValue("", true, 0); | 898 TestInitFromValue("", true, 0); |
645 | 899 |
646 // Single valid values. | 900 // Single valid values. |
647 TestInitFromValue( | 901 TestInitFromValue( |
648 "requestHeaders", | 902 "requestHeaders", |
649 true, | 903 true, |
650 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS); | 904 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS); |
651 TestInitFromValue( | 905 TestInitFromValue( |
652 "responseHeaders", | 906 "responseHeaders", |
653 true, | 907 true, |
654 ExtensionWebRequestEventRouter::ExtraInfoSpec::RESPONSE_HEADERS); | 908 ExtensionWebRequestEventRouter::ExtraInfoSpec::RESPONSE_HEADERS); |
655 TestInitFromValue( | 909 TestInitFromValue( |
656 "blocking", | 910 "blocking", |
657 true, | 911 true, |
658 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); | 912 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); |
659 TestInitFromValue( | 913 TestInitFromValue( |
660 "asyncBlocking", | 914 "asyncBlocking", |
661 true, | 915 true, |
662 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING); | 916 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING); |
917 { | |
918 Feature::ScopedCurrentChannel sc(VersionInfo::CHANNEL_BETA); | |
919 TestInitFromValue( | |
920 "requestBody", | |
921 true, | |
922 0); | |
923 } | |
924 { | |
925 Feature::ScopedCurrentChannel sc(VersionInfo::CHANNEL_DEV); | |
926 TestInitFromValue( | |
927 "requestBody", | |
928 true, | |
929 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_BODY); | |
930 } | |
663 | 931 |
664 // Multiple valid values are bitwise-or'ed. | 932 // Multiple valid values are bitwise-or'ed. |
665 TestInitFromValue( | 933 TestInitFromValue( |
666 "requestHeaders,blocking", | 934 "requestHeaders,blocking", |
667 true, | 935 true, |
668 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS | | 936 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS | |
669 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); | 937 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); |
670 | 938 |
671 // Any invalid values lead to a bad parse. | 939 // Any invalid values lead to a bad parse. |
672 TestInitFromValue("invalidValue", false, 0); | 940 TestInitFromValue("invalidValue", false, 0); |
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1632 credentials_set = MergeOnAuthRequiredResponses( | 1900 credentials_set = MergeOnAuthRequiredResponses( |
1633 deltas, &auth3, &conflicting_extensions, &net_log); | 1901 deltas, &auth3, &conflicting_extensions, &net_log); |
1634 EXPECT_TRUE(credentials_set); | 1902 EXPECT_TRUE(credentials_set); |
1635 EXPECT_FALSE(auth3.Empty()); | 1903 EXPECT_FALSE(auth3.Empty()); |
1636 EXPECT_EQ(username, auth1.username()); | 1904 EXPECT_EQ(username, auth1.username()); |
1637 EXPECT_EQ(password, auth1.password()); | 1905 EXPECT_EQ(password, auth1.password()); |
1638 EXPECT_EQ(1u, conflicting_extensions.size()); | 1906 EXPECT_EQ(1u, conflicting_extensions.size()); |
1639 EXPECT_TRUE(ContainsKey(conflicting_extensions, "extid2")); | 1907 EXPECT_TRUE(ContainsKey(conflicting_extensions, "extid2")); |
1640 EXPECT_EQ(3u, capturing_net_log.GetSize()); | 1908 EXPECT_EQ(3u, capturing_net_log.GetSize()); |
1641 } | 1909 } |
1642 | |
OLD | NEW |