OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <queue> | 5 #include <queue> |
6 #include <map> | 6 #include <map> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/json/json_reader.h" | |
11 #include "base/json/json_string_value_serializer.h" | 12 #include "base/json/json_string_value_serializer.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
14 #include "base/path_service.h" | 15 #include "base/path_service.h" |
15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "base/string_piece.h" | |
16 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
17 #include "chrome/browser/content_settings/cookie_settings.h" | 19 #include "chrome/browser/content_settings/cookie_settings.h" |
18 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 20 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
19 #include "chrome/browser/extensions/api/web_request/web_request_api_constants.h" | 21 #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" | 22 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" |
21 #include "chrome/browser/extensions/event_router_forwarder.h" | 23 #include "chrome/browser/extensions/event_router_forwarder.h" |
22 #include "chrome/browser/net/chrome_network_delegate.h" | 24 #include "chrome/browser/net/chrome_network_delegate.h" |
23 #include "chrome/browser/prefs/pref_member.h" | 25 #include "chrome/browser/prefs/pref_member.h" |
24 #include "chrome/common/extensions/extension_messages.h" | 26 #include "chrome/common/extensions/extension_messages.h" |
25 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
26 #include "chrome/test/base/testing_browser_process.h" | 28 #include "chrome/test/base/testing_browser_process.h" |
27 #include "chrome/test/base/testing_pref_service.h" | 29 #include "chrome/test/base/testing_pref_service.h" |
28 #include "chrome/test/base/testing_profile.h" | 30 #include "chrome/test/base/testing_profile.h" |
29 #include "content/public/test/test_browser_thread.h" | 31 #include "content/public/test/test_browser_thread.h" |
30 #include "net/base/auth.h" | 32 #include "net/base/auth.h" |
31 #include "net/base/capturing_net_log.h" | 33 #include "net/base/capturing_net_log.h" |
32 #include "net/base/mock_host_resolver.h" | 34 #include "net/base/mock_host_resolver.h" |
33 #include "net/base/net_util.h" | 35 #include "net/base/net_util.h" |
34 #include "net/url_request/url_request_test_util.h" | 36 #include "net/url_request/url_request_test_util.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
36 | 38 |
37 namespace helpers = extension_web_request_api_helpers; | 39 namespace helpers = extension_web_request_api_helpers; |
38 namespace keys = extension_web_request_api_constants; | 40 namespace keys = extension_web_request_api_constants; |
39 | 41 |
42 using chrome::VersionInfo; | |
40 using helpers::CalculateOnAuthRequiredDelta; | 43 using helpers::CalculateOnAuthRequiredDelta; |
41 using helpers::CalculateOnBeforeRequestDelta; | 44 using helpers::CalculateOnBeforeRequestDelta; |
42 using helpers::CalculateOnBeforeSendHeadersDelta; | 45 using helpers::CalculateOnBeforeSendHeadersDelta; |
43 using helpers::CalculateOnHeadersReceivedDelta; | 46 using helpers::CalculateOnHeadersReceivedDelta; |
44 using helpers::CharListToString; | 47 using helpers::CharListToString; |
45 using helpers::EventResponseDelta; | 48 using helpers::EventResponseDelta; |
46 using helpers::EventResponseDeltas; | 49 using helpers::EventResponseDeltas; |
47 using helpers::EventResponseDeltas; | 50 using helpers::EventResponseDeltas; |
48 using helpers::InDecreasingExtensionInstallationTimeOrder; | 51 using helpers::InDecreasingExtensionInstallationTimeOrder; |
49 using helpers::MergeCancelOfResponses; | 52 using helpers::MergeCancelOfResponses; |
(...skipping 16 matching lines...) Expand all Loading... | |
66 } | 69 } |
67 | 70 |
68 // Searches |key| in |collection| by iterating over its elements and returns | 71 // Searches |key| in |collection| by iterating over its elements and returns |
69 // true if found. | 72 // true if found. |
70 template <typename Collection, typename Key> | 73 template <typename Collection, typename Key> |
71 bool Contains(const Collection& collection, const Key& key) { | 74 bool Contains(const Collection& collection, const Key& key) { |
72 return std::find(collection.begin(), collection.end(), key) != | 75 return std::find(collection.begin(), collection.end(), key) != |
73 collection.end(); | 76 collection.end(); |
74 } | 77 } |
75 | 78 |
79 // Parses |json_string| as a Value. Returns NULL on failure. The caller owns | |
80 // the returned object. | |
81 const Value* GetValueFromJson(const base::StringPiece& json_string) { | |
82 const Value* parsed = base::JSONReader::Read(json_string); | |
83 return parsed; | |
84 } | |
85 | |
86 // Parses |json_string| as a DictionaryValue. Returns NULL on failure. | |
87 scoped_ptr<const DictionaryValue> GetDictionaryFromJson( | |
88 const base::StringPiece& json_string) { | |
89 const Value* value = GetValueFromJson(json_string); | |
90 if (value == NULL) | |
91 return scoped_ptr<const DictionaryValue>(); | |
92 // Now we own the object pointed to by |value|. | |
93 const DictionaryValue* dictionary_raw = NULL; | |
94 const bool success = value->GetAsDictionary(&dictionary_raw); | |
95 scoped_ptr<const DictionaryValue> dictionary(dictionary_raw); | |
96 if (success) | |
97 return dictionary.Pass(); | |
98 else | |
99 return scoped_ptr<const DictionaryValue>(); | |
100 } | |
101 | |
102 // Parses the JSON data attached to the |message| and tries to return it. | |
103 // Returns NULL on failure. | |
104 scoped_ptr<const DictionaryValue> GetPartOfMessageArguments( | |
105 IPC::Message* message) { | |
106 bool success = true; | |
107 EXPECT_TRUE(success = (message->type() == ExtensionMsg_MessageInvoke::ID)); | |
108 if (!success) | |
109 return scoped_ptr<const DictionaryValue>(); | |
Matt Perry
2012/08/02 10:11:03
Sadly this makes the code a bit hard to read. What
vabr (Chromium)
2012/08/05 18:54:46
Good idea. I actually changed the signature of Get
| |
110 ExtensionMsg_MessageInvoke::Param param; | |
111 Value* temp_value = NULL; | |
112 EXPECT_TRUE(success = (ExtensionMsg_MessageInvoke::Read(message, ¶m))); | |
113 if (!success) | |
114 return scoped_ptr<const DictionaryValue>(); | |
115 EXPECT_TRUE(success = (param.c.GetSize() >= 2)); | |
116 if (!success) | |
117 return scoped_ptr<const DictionaryValue>(); | |
118 EXPECT_TRUE(success = (param.c.Get(1, &temp_value))); | |
119 if (!success) | |
120 return scoped_ptr<const DictionaryValue>(); | |
121 std::string args; | |
122 EXPECT_TRUE(success = (temp_value->GetAsString(&args))); | |
123 if (!success) | |
124 return scoped_ptr<const DictionaryValue>(); | |
125 const Value* value = GetValueFromJson(args); | |
126 EXPECT_TRUE(success = (value != NULL)); | |
127 if (!success) | |
128 return scoped_ptr<const DictionaryValue>(); | |
129 const ListValue* list = NULL; | |
130 EXPECT_TRUE(success = (value->GetAsList(&list))); | |
131 if (!success) | |
132 return scoped_ptr<const DictionaryValue>(); | |
133 scoped_ptr<const ListValue> list_scoped(list); | |
134 EXPECT_TRUE(success = (list->GetSize() == 1)); | |
135 if (!success) | |
136 return scoped_ptr<const DictionaryValue>(); | |
137 // TODO(vabr): Add const once ListValue getters get corrected. | |
138 DictionaryValue* dictionary = NULL; | |
139 EXPECT_TRUE(success = (list->GetDictionary(0, &dictionary))); | |
140 if (!success) | |
141 return scoped_ptr<const DictionaryValue>(); | |
142 return scoped_ptr<const DictionaryValue>(dictionary->DeepCopy()); | |
143 } | |
144 | |
76 } // namespace | 145 } // namespace |
77 | 146 |
78 // A mock event router that responds to events with a pre-arranged queue of | 147 // A mock event router that responds to events with a pre-arranged queue of |
79 // Tasks. | 148 // Tasks. |
80 class TestIPCSender : public IPC::Sender { | 149 class TestIPCSender : public IPC::Sender { |
81 public: | 150 public: |
82 typedef std::list<linked_ptr<IPC::Message> > SentMessages; | 151 typedef std::list<linked_ptr<IPC::Message> > SentMessages; |
83 | 152 |
84 // Adds a Task to the queue. We will fire these in order as events are | 153 // Adds a Task to the queue. We will fire these in order as events are |
85 // dispatched. | 154 // dispatched. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 prefs::kEnableReferrers, profile_.GetTestingPrefService(), NULL); | 196 prefs::kEnableReferrers, profile_.GetTestingPrefService(), NULL); |
128 network_delegate_.reset(new ChromeNetworkDelegate( | 197 network_delegate_.reset(new ChromeNetworkDelegate( |
129 event_router_.get(), NULL, NULL, &profile_, | 198 event_router_.get(), NULL, NULL, &profile_, |
130 CookieSettings::Factory::GetForProfile(&profile_), &enable_referrers_, | 199 CookieSettings::Factory::GetForProfile(&profile_), &enable_referrers_, |
131 NULL)); | 200 NULL)); |
132 context_.reset(new TestURLRequestContext(true)); | 201 context_.reset(new TestURLRequestContext(true)); |
133 context_->set_network_delegate(network_delegate_.get()); | 202 context_->set_network_delegate(network_delegate_.get()); |
134 context_->Init(); | 203 context_->Init(); |
135 } | 204 } |
136 | 205 |
206 // Fires a URLRequest with the specified |content_type|. Method will be "POST" | |
207 // and the data will be |bytes|. | |
208 void FireURLRequestWithPostData(const char* content_type, | |
209 const char* bytes, size_t bytes_length); | |
210 | |
137 MessageLoopForIO message_loop_; | 211 MessageLoopForIO message_loop_; |
138 content::TestBrowserThread ui_thread_; | 212 content::TestBrowserThread ui_thread_; |
139 content::TestBrowserThread io_thread_; | 213 content::TestBrowserThread io_thread_; |
140 TestingProfile profile_; | 214 TestingProfile profile_; |
141 TestDelegate delegate_; | 215 TestDelegate delegate_; |
142 BooleanPrefMember enable_referrers_; | 216 BooleanPrefMember enable_referrers_; |
143 TestIPCSender ipc_sender_; | 217 TestIPCSender ipc_sender_; |
144 scoped_refptr<extensions::EventRouterForwarder> event_router_; | 218 scoped_refptr<extensions::EventRouterForwarder> event_router_; |
145 scoped_refptr<ExtensionInfoMap> extension_info_map_; | 219 scoped_refptr<ExtensionInfoMap> extension_info_map_; |
146 scoped_ptr<ChromeNetworkDelegate> network_delegate_; | 220 scoped_ptr<ChromeNetworkDelegate> network_delegate_; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 EXPECT_TRUE(!request.is_pending()); | 466 EXPECT_TRUE(!request.is_pending()); |
393 EXPECT_EQ(net::URLRequestStatus::CANCELED, request.status().status()); | 467 EXPECT_EQ(net::URLRequestStatus::CANCELED, request.status().status()); |
394 EXPECT_EQ(net::ERR_ABORTED, request.status().error()); | 468 EXPECT_EQ(net::ERR_ABORTED, request.status().error()); |
395 EXPECT_EQ(request_url, request.url()); | 469 EXPECT_EQ(request_url, request.url()); |
396 EXPECT_EQ(1U, request.url_chain().size()); | 470 EXPECT_EQ(1U, request.url_chain().size()); |
397 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); | 471 EXPECT_EQ(0U, ipc_sender_.GetNumTasks()); |
398 | 472 |
399 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 473 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
400 &profile_, extension_id, kEventName + "/1"); | 474 &profile_, extension_id, kEventName + "/1"); |
401 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 475 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
402 &profile_, extension_id, kEventName2 + "/1"); | 476 &profile_, extension_id, kEventName2 + "/1"); |
477 } | |
478 | |
479 namespace { | |
480 | |
481 // Based on the string with extraInfoSpec |values|, create the numerical | |
482 // representation. Returns true on success, otherwise false. | |
483 bool GenerateInfoSpec(const std::string& values, int* result) { | |
484 // Create a ListValue of strings. | |
485 std::vector<std::string> split_values; | |
486 scoped_ptr<base::ListValue> list_value(new base::ListValue()); | |
487 size_t num_values = Tokenize(values, ",", &split_values); | |
488 for (size_t i = 0; i < num_values ; ++i) | |
489 list_value->Append(new base::StringValue(split_values[i])); | |
490 return ExtensionWebRequestEventRouter::ExtraInfoSpec::InitFromValue( | |
491 *list_value, result); | |
492 } | |
493 | |
494 } // namespace | |
495 | |
496 void ExtensionWebRequestTest::FireURLRequestWithPostData( | |
497 const char* content_type, | |
498 const char* bytes, size_t bytes_length) { | |
499 // The request URL can be arbitrary but must have an HTTP or HTTPS scheme. | |
500 GURL request_url("http://www.example.com"); | |
501 net::URLRequest request(request_url, &delegate_, context_.get()); | |
502 request.set_method("POST"); | |
503 request.SetExtraRequestHeaderByName( | |
504 net::HttpRequestHeaders::kContentType, content_type, true); | |
505 request.AppendBytesToUpload(bytes, bytes_length); | |
506 ipc_sender_.PushTask(base::Bind(&base::DoNothing)); | |
507 request.Start(); | |
508 } | |
509 | |
510 TEST_F(ExtensionWebRequestTest, AccessPostData) { | |
511 // We verify that POST data are accessible to OnBeforeRequest listeners. | |
512 // Three testing steps are repeated twice: | |
513 // 1. Register an extension requesting ExtraInfoSpec::POST_DATA and file a | |
514 // URLRequest with a multipart-encoded form. See it getting parsed. | |
515 // 2. Do the same, but without requesting ExtraInfoSpec::POST_DATA. Nothing | |
516 // should be parsed. | |
517 // 3. With ExtraInfoSpec::POST_DATA, fire a URLRequest with a chunked | |
518 // upload. Get the error message. | |
519 // Each of these steps is done once as if the channel was DEV or CANARY, | |
520 // and once as if it was BETA or STABLE. It is checked that POST data access | |
521 // is not available on BETA/STABLE, but that it works on DEV/CANARY. | |
522 #define kBoundary "THIS_IS_A_BOUNDARY" | |
523 #define kBlock "--" kBoundary "\r\n" \ | |
524 "Content-Disposition: form-data; name=\"text\"\r\n" \ | |
525 "\r\n" \ | |
526 "test text\r\n" \ | |
527 "--" kBoundary "--" | |
528 // POST data input. | |
529 const char kMultipartBytes[] = kBlock; | |
530 // Expected POST data output. | |
531 const std::string kPostDataPath(keys::kPostDataKey); | |
532 const std::string kFormDataPath(kPostDataPath + "." + keys::kPostDataFormKey); | |
533 const std::string kErrorPath(kPostDataPath + "." + keys::kPostDataErrorKey); | |
534 const std::string* kPath[] = {&kFormDataPath, &kPostDataPath, &kErrorPath}; | |
535 // form | |
536 const char kFormDataString[] = "{\"text\":[\"test text\"]}"; | |
537 scoped_ptr<const DictionaryValue> form_data( | |
538 GetDictionaryFromJson(kFormDataString)); | |
539 ASSERT_TRUE(form_data.get() != NULL); | |
540 // error | |
541 const StringValue error("chunked_encoding"); | |
542 // Summary. | |
543 const Value* kExpected[] = {form_data.get(), NULL, &error, NULL, NULL, NULL}; | |
544 // Header. | |
545 const char kMultipart[] = "multipart/form-data; boundary=" kBoundary; | |
546 #undef kBlock | |
547 #undef kBoundary | |
548 | |
549 // Set up a dummy extension name. | |
550 ExtensionWebRequestEventRouter::RequestFilter filter; | |
551 std::string extension_id("1"); | |
552 const std::string string_spec_post("blocking,postData"); | |
553 const std::string string_spec_no_post("blocking"); | |
554 int extra_info_spec_no_post = 0; | |
555 int extra_info_spec_post = 0; | |
556 | |
557 for (int pass = 0; pass < 2; ++pass) { | |
558 SetChannelForTestingWebRequest( | |
559 pass > 0 ? VersionInfo::CHANNEL_BETA : VersionInfo::CHANNEL_CANARY); | |
560 | |
561 // Part 1. | |
562 // Subscribe to OnBeforeRequest with POST data requirement. | |
563 ASSERT_TRUE(GenerateInfoSpec(string_spec_post, &extra_info_spec_post)); | |
564 const std::string kEventName(keys::kOnBeforeRequest); | |
565 base::WeakPtrFactory<TestIPCSender> ipc_sender_factory(&ipc_sender_); | |
566 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | |
567 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", | |
568 filter, extra_info_spec_post, ipc_sender_factory.GetWeakPtr()); | |
569 | |
570 FireURLRequestWithPostData( | |
571 kMultipart, kMultipartBytes, strlen(kMultipartBytes)); | |
572 | |
573 MessageLoop::current()->RunAllPending(); | |
574 | |
575 SetChannelForTestingWebRequest( | |
576 pass > 0 ? VersionInfo::CHANNEL_STABLE : VersionInfo::CHANNEL_DEV); | |
577 | |
578 // Part 2. | |
579 // Now remove the requirement of POST data. | |
580 ASSERT_TRUE( | |
581 GenerateInfoSpec(string_spec_no_post, &extra_info_spec_no_post)); | |
582 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | |
583 &profile_, extension_id, kEventName + "/1"); | |
584 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | |
585 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", | |
586 filter, extra_info_spec_no_post, ipc_sender_factory.GetWeakPtr()); | |
587 | |
588 FireURLRequestWithPostData( | |
589 kMultipart, kMultipartBytes, strlen(kMultipartBytes)); | |
590 | |
591 // Part 3. | |
592 // Get back the requirement of POST data. | |
593 ASSERT_TRUE(GenerateInfoSpec(string_spec_post, &extra_info_spec_post)); | |
594 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | |
595 &profile_, extension_id, kEventName + "/1"); | |
596 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | |
597 &profile_, extension_id, extension_id, kEventName, kEventName + "/1", | |
598 filter, extra_info_spec_post, ipc_sender_factory.GetWeakPtr()); | |
599 { | |
600 GURL request_url("http://www.example.com"); | |
601 net::URLRequest request(request_url, &delegate_, context_.get()); | |
602 request.set_method("POST"); | |
603 request.EnableChunkedUpload(); | |
604 const char kDummyBytes[] = "dummy"; | |
605 request.AppendChunkToUpload(kDummyBytes, strlen(kDummyBytes), true); | |
606 net::HttpRequestHeaders headers(request.extra_request_headers()); | |
607 headers.SetHeader(net::HttpRequestHeaders::kTransferEncoding, "chunked"); | |
608 request.SetExtraRequestHeaders(headers); | |
609 ipc_sender_.PushTask(base::Bind(&base::DoNothing)); | |
610 request.Start(); | |
611 } | |
612 | |
613 MessageLoop::current()->RunAllPending(); | |
614 | |
615 // Clean-up. | |
616 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | |
617 &profile_, extension_id, kEventName + "/1"); | |
618 } | |
619 | |
620 ResetChannelForTestingWebRequest(); | |
621 | |
622 IPC::Message* message = NULL; | |
623 TestIPCSender::SentMessages::const_iterator i = ipc_sender_.sent_begin(); | |
624 for (size_t test = 0; test < arraysize(kExpected); ++test) { | |
625 EXPECT_NE(i, ipc_sender_.sent_end()); | |
626 message = (i++)->get(); | |
627 scoped_ptr<const DictionaryValue> | |
628 details(GetPartOfMessageArguments(message).Pass()); | |
629 ASSERT_TRUE(details.get() != NULL); | |
630 const Value* result = NULL; | |
631 EXPECT_EQ( | |
632 kExpected[test] != NULL, details->Get(*(kPath[test % 3]), &result)); | |
633 if (kExpected[test] != NULL) { | |
634 EXPECT_TRUE(kExpected[test]->Equals(result)); | |
635 } | |
636 } | |
637 | |
638 EXPECT_EQ(i, ipc_sender_.sent_end()); | |
403 } | 639 } |
404 | 640 |
405 struct HeaderModificationTest_Header { | 641 struct HeaderModificationTest_Header { |
406 const char* name; | 642 const char* name; |
407 const char* value; | 643 const char* value; |
408 }; | 644 }; |
409 | 645 |
410 struct HeaderModificationTest_Modification { | 646 struct HeaderModificationTest_Modification { |
411 enum Type { | 647 enum Type { |
412 SET, | 648 SET, |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
622 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 858 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
623 &profile_, extension2_id, kEventName + "/2"); | 859 &profile_, extension2_id, kEventName + "/2"); |
624 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 860 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
625 &profile_, extension3_id, std::string(keys::kOnSendHeaders) + "/3"); | 861 &profile_, extension3_id, std::string(keys::kOnSendHeaders) + "/3"); |
626 }; | 862 }; |
627 | 863 |
628 namespace { | 864 namespace { |
629 | 865 |
630 void TestInitFromValue(const std::string& values, bool expected_return_code, | 866 void TestInitFromValue(const std::string& values, bool expected_return_code, |
631 int expected_extra_info_spec) { | 867 int expected_extra_info_spec) { |
632 // Create a ListValue of strings. | |
633 std::vector<std::string> split_values; | |
634 scoped_ptr<base::ListValue> list_value(new base::ListValue()); | |
635 size_t num_values = Tokenize(values, ",", &split_values); | |
636 for (size_t i = 0; i < num_values ; ++i) | |
637 list_value->Append(new base::StringValue(split_values[i])); | |
638 int actual_info_spec; | 868 int actual_info_spec; |
639 bool actual_return_code = | 869 bool actual_return_code = GenerateInfoSpec(values, &actual_info_spec); |
640 ExtensionWebRequestEventRouter::ExtraInfoSpec::InitFromValue( | |
641 *list_value, &actual_info_spec); | |
642 EXPECT_EQ(expected_return_code, actual_return_code); | 870 EXPECT_EQ(expected_return_code, actual_return_code); |
643 if (expected_return_code) | 871 if (expected_return_code) |
644 EXPECT_EQ(expected_extra_info_spec, actual_info_spec); | 872 EXPECT_EQ(expected_extra_info_spec, actual_info_spec); |
645 } | 873 } |
646 | 874 |
647 } | 875 } |
648 TEST_F(ExtensionWebRequestTest, InitFromValue) { | 876 TEST_F(ExtensionWebRequestTest, InitFromValue) { |
649 TestInitFromValue("", true, 0); | 877 TestInitFromValue("", true, 0); |
650 | 878 |
651 // Single valid values. | 879 // Single valid values. |
652 TestInitFromValue( | 880 TestInitFromValue( |
653 "requestHeaders", | 881 "requestHeaders", |
654 true, | 882 true, |
655 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS); | 883 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS); |
656 TestInitFromValue( | 884 TestInitFromValue( |
657 "responseHeaders", | 885 "responseHeaders", |
658 true, | 886 true, |
659 ExtensionWebRequestEventRouter::ExtraInfoSpec::RESPONSE_HEADERS); | 887 ExtensionWebRequestEventRouter::ExtraInfoSpec::RESPONSE_HEADERS); |
660 TestInitFromValue( | 888 TestInitFromValue( |
661 "blocking", | 889 "blocking", |
662 true, | 890 true, |
663 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); | 891 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); |
664 TestInitFromValue( | 892 TestInitFromValue( |
665 "asyncBlocking", | 893 "asyncBlocking", |
666 true, | 894 true, |
667 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING); | 895 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING); |
896 SetChannelForTestingWebRequest(VersionInfo::CHANNEL_BETA); | |
897 TestInitFromValue( | |
898 "postData", | |
899 true, | |
900 0); | |
901 SetChannelForTestingWebRequest(VersionInfo::CHANNEL_DEV); | |
902 TestInitFromValue( | |
903 "postData", | |
904 true, | |
905 ExtensionWebRequestEventRouter::ExtraInfoSpec::POST_DATA); | |
906 ResetChannelForTestingWebRequest(); | |
668 | 907 |
669 // Multiple valid values are bitwise-or'ed. | 908 // Multiple valid values are bitwise-or'ed. |
670 TestInitFromValue( | 909 TestInitFromValue( |
671 "requestHeaders,blocking", | 910 "requestHeaders,blocking", |
672 true, | 911 true, |
673 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS | | 912 ExtensionWebRequestEventRouter::ExtraInfoSpec::REQUEST_HEADERS | |
674 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); | 913 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING); |
675 | 914 |
676 // Any invalid values lead to a bad parse. | 915 // Any invalid values lead to a bad parse. |
677 TestInitFromValue("invalidValue", false, 0); | 916 TestInitFromValue("invalidValue", false, 0); |
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1481 credentials_set = MergeOnAuthRequiredResponses( | 1720 credentials_set = MergeOnAuthRequiredResponses( |
1482 deltas, &auth3, &conflicting_extensions, &net_log); | 1721 deltas, &auth3, &conflicting_extensions, &net_log); |
1483 EXPECT_TRUE(credentials_set); | 1722 EXPECT_TRUE(credentials_set); |
1484 EXPECT_FALSE(auth3.Empty()); | 1723 EXPECT_FALSE(auth3.Empty()); |
1485 EXPECT_EQ(username, auth1.username()); | 1724 EXPECT_EQ(username, auth1.username()); |
1486 EXPECT_EQ(password, auth1.password()); | 1725 EXPECT_EQ(password, auth1.password()); |
1487 EXPECT_EQ(1u, conflicting_extensions.size()); | 1726 EXPECT_EQ(1u, conflicting_extensions.size()); |
1488 EXPECT_TRUE(ContainsKey(conflicting_extensions, "extid2")); | 1727 EXPECT_TRUE(ContainsKey(conflicting_extensions, "extid2")); |
1489 EXPECT_EQ(3u, capturing_net_log.GetSize()); | 1728 EXPECT_EQ(3u, capturing_net_log.GetSize()); |
1490 } | 1729 } |
1491 | |
OLD | NEW |