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/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "chrome/browser/net/about_protocol_handler.h" | 30 #include "chrome/browser/net/about_protocol_handler.h" |
31 #include "chrome/browser/net/chrome_network_delegate.h" | 31 #include "chrome/browser/net/chrome_network_delegate.h" |
32 #include "chrome/common/extensions/extension_messages.h" | 32 #include "chrome/common/extensions/extension_messages.h" |
33 #include "chrome/common/extensions/features/feature.h" | 33 #include "chrome/common/extensions/features/feature.h" |
34 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
35 #include "chrome/test/base/testing_browser_process.h" | 35 #include "chrome/test/base/testing_browser_process.h" |
36 #include "chrome/test/base/testing_pref_service_syncable.h" | 36 #include "chrome/test/base/testing_pref_service_syncable.h" |
37 #include "chrome/test/base/testing_profile.h" | 37 #include "chrome/test/base/testing_profile.h" |
38 #include "chrome/test/base/testing_profile_manager.h" | 38 #include "chrome/test/base/testing_profile_manager.h" |
39 #include "content/public/common/url_constants.h" | 39 #include "content/public/common/url_constants.h" |
40 #include "content/public/test/test_browser_thread.h" | 40 #include "content/public/test/test_browser_thread_bundle.h" |
41 #include "net/base/auth.h" | 41 #include "net/base/auth.h" |
42 #include "net/base/capturing_net_log.h" | 42 #include "net/base/capturing_net_log.h" |
43 #include "net/base/net_util.h" | 43 #include "net/base/net_util.h" |
44 #include "net/base/upload_bytes_element_reader.h" | 44 #include "net/base/upload_bytes_element_reader.h" |
45 #include "net/base/upload_data_stream.h" | 45 #include "net/base/upload_data_stream.h" |
46 #include "net/base/upload_file_element_reader.h" | 46 #include "net/base/upload_file_element_reader.h" |
47 #include "net/dns/mock_host_resolver.h" | 47 #include "net/dns/mock_host_resolver.h" |
48 #include "net/url_request/url_request_job_factory_impl.h" | 48 #include "net/url_request/url_request_job_factory_impl.h" |
49 #include "net/url_request/url_request_test_util.h" | 49 #include "net/url_request/url_request_test_util.h" |
50 #include "testing/gtest/include/gtest/gtest-message.h" | 50 #include "testing/gtest/include/gtest/gtest-message.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 return true; | 166 return true; |
167 } | 167 } |
168 | 168 |
169 std::queue<base::Closure> task_queue_; | 169 std::queue<base::Closure> task_queue_; |
170 SentMessages sent_messages_; | 170 SentMessages sent_messages_; |
171 }; | 171 }; |
172 | 172 |
173 class ExtensionWebRequestTest : public testing::Test { | 173 class ExtensionWebRequestTest : public testing::Test { |
174 public: | 174 public: |
175 ExtensionWebRequestTest() | 175 ExtensionWebRequestTest() |
176 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 176 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
177 io_thread_(content::BrowserThread::IO, &message_loop_), | |
178 profile_manager_(TestingBrowserProcess::GetGlobal()), | 177 profile_manager_(TestingBrowserProcess::GetGlobal()), |
179 event_router_(new EventRouterForwarder) {} | 178 event_router_(new EventRouterForwarder) {} |
180 | 179 |
181 protected: | 180 protected: |
182 virtual void SetUp() OVERRIDE { | 181 virtual void SetUp() OVERRIDE { |
183 ASSERT_TRUE(profile_manager_.SetUp()); | 182 ASSERT_TRUE(profile_manager_.SetUp()); |
184 ChromeNetworkDelegate::InitializePrefsOnUIThread( | 183 ChromeNetworkDelegate::InitializePrefsOnUIThread( |
185 &enable_referrers_, NULL, NULL, profile_.GetTestingPrefService()); | 184 &enable_referrers_, NULL, NULL, profile_.GetTestingPrefService()); |
186 network_delegate_.reset( | 185 network_delegate_.reset( |
187 new ChromeNetworkDelegate(event_router_.get(), &enable_referrers_)); | 186 new ChromeNetworkDelegate(event_router_.get(), &enable_referrers_)); |
188 network_delegate_->set_profile(&profile_); | 187 network_delegate_->set_profile(&profile_); |
189 network_delegate_->set_cookie_settings( | 188 network_delegate_->set_cookie_settings( |
190 CookieSettings::Factory::GetForProfile(&profile_)); | 189 CookieSettings::Factory::GetForProfile(&profile_)); |
191 context_.reset(new net::TestURLRequestContext(true)); | 190 context_.reset(new net::TestURLRequestContext(true)); |
192 context_->set_network_delegate(network_delegate_.get()); | 191 context_->set_network_delegate(network_delegate_.get()); |
193 context_->Init(); | 192 context_->Init(); |
194 } | 193 } |
195 | 194 |
196 // Fires a URLRequest with the specified |method|, |content_type| and three | 195 // Fires a URLRequest with the specified |method|, |content_type| and three |
197 // elements of upload data: bytes_1, a dummy empty file, bytes_2. | 196 // elements of upload data: bytes_1, a dummy empty file, bytes_2. |
198 void FireURLRequestWithData(const std::string& method, | 197 void FireURLRequestWithData(const std::string& method, |
199 const char* content_type, | 198 const char* content_type, |
200 const std::vector<char>& bytes_1, | 199 const std::vector<char>& bytes_1, |
201 const std::vector<char>& bytes_2); | 200 const std::vector<char>& bytes_2); |
202 | 201 |
203 base::MessageLoopForIO message_loop_; | 202 content::TestBrowserThreadBundle thread_bundle_; |
204 content::TestBrowserThread ui_thread_; | |
205 content::TestBrowserThread io_thread_; | |
206 TestingProfile profile_; | 203 TestingProfile profile_; |
207 TestingProfileManager profile_manager_; | 204 TestingProfileManager profile_manager_; |
208 net::TestDelegate delegate_; | 205 net::TestDelegate delegate_; |
209 BooleanPrefMember enable_referrers_; | 206 BooleanPrefMember enable_referrers_; |
210 TestIPCSender ipc_sender_; | 207 TestIPCSender ipc_sender_; |
211 scoped_refptr<EventRouterForwarder> event_router_; | 208 scoped_refptr<EventRouterForwarder> event_router_; |
212 scoped_refptr<ExtensionInfoMap> extension_info_map_; | 209 scoped_refptr<ExtensionInfoMap> extension_info_map_; |
213 scoped_ptr<ChromeNetworkDelegate> network_delegate_; | 210 scoped_ptr<ChromeNetworkDelegate> network_delegate_; |
214 scoped_ptr<net::TestURLRequestContext> context_; | 211 scoped_ptr<net::TestURLRequestContext> context_; |
215 }; | 212 }; |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 int modification_size; | 758 int modification_size; |
762 HeaderModificationTest_Modification modification[10]; | 759 HeaderModificationTest_Modification modification[10]; |
763 int after_size; | 760 int after_size; |
764 HeaderModificationTest_Header after[10]; | 761 HeaderModificationTest_Header after[10]; |
765 }; | 762 }; |
766 | 763 |
767 class ExtensionWebRequestHeaderModificationTest | 764 class ExtensionWebRequestHeaderModificationTest |
768 : public testing::TestWithParam<HeaderModificationTest> { | 765 : public testing::TestWithParam<HeaderModificationTest> { |
769 public: | 766 public: |
770 ExtensionWebRequestHeaderModificationTest() | 767 ExtensionWebRequestHeaderModificationTest() |
771 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 768 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
772 io_thread_(content::BrowserThread::IO, &message_loop_), | |
773 profile_manager_(TestingBrowserProcess::GetGlobal()), | 769 profile_manager_(TestingBrowserProcess::GetGlobal()), |
774 event_router_(new EventRouterForwarder) {} | 770 event_router_(new EventRouterForwarder) {} |
775 | 771 |
776 protected: | 772 protected: |
777 virtual void SetUp() { | 773 virtual void SetUp() { |
778 ASSERT_TRUE(profile_manager_.SetUp()); | 774 ASSERT_TRUE(profile_manager_.SetUp()); |
779 ChromeNetworkDelegate::InitializePrefsOnUIThread( | 775 ChromeNetworkDelegate::InitializePrefsOnUIThread( |
780 &enable_referrers_, NULL, NULL, profile_.GetTestingPrefService()); | 776 &enable_referrers_, NULL, NULL, profile_.GetTestingPrefService()); |
781 network_delegate_.reset( | 777 network_delegate_.reset( |
782 new ChromeNetworkDelegate(event_router_.get(), &enable_referrers_)); | 778 new ChromeNetworkDelegate(event_router_.get(), &enable_referrers_)); |
783 network_delegate_->set_profile(&profile_); | 779 network_delegate_->set_profile(&profile_); |
784 network_delegate_->set_cookie_settings( | 780 network_delegate_->set_cookie_settings( |
785 CookieSettings::Factory::GetForProfile(&profile_)); | 781 CookieSettings::Factory::GetForProfile(&profile_)); |
786 context_.reset(new net::TestURLRequestContext(true)); | 782 context_.reset(new net::TestURLRequestContext(true)); |
787 host_resolver_.reset(new net::MockHostResolver()); | 783 host_resolver_.reset(new net::MockHostResolver()); |
788 host_resolver_->rules()->AddSimulatedFailure("doesnotexist"); | 784 host_resolver_->rules()->AddSimulatedFailure("doesnotexist"); |
789 context_->set_host_resolver(host_resolver_.get()); | 785 context_->set_host_resolver(host_resolver_.get()); |
790 context_->set_network_delegate(network_delegate_.get()); | 786 context_->set_network_delegate(network_delegate_.get()); |
791 context_->Init(); | 787 context_->Init(); |
792 } | 788 } |
793 | 789 |
794 base::MessageLoopForIO message_loop_; | 790 content::TestBrowserThreadBundle thread_bundle_; |
795 content::TestBrowserThread ui_thread_; | |
796 content::TestBrowserThread io_thread_; | |
797 TestingProfile profile_; | 791 TestingProfile profile_; |
798 TestingProfileManager profile_manager_; | 792 TestingProfileManager profile_manager_; |
799 net::TestDelegate delegate_; | 793 net::TestDelegate delegate_; |
800 BooleanPrefMember enable_referrers_; | 794 BooleanPrefMember enable_referrers_; |
801 TestIPCSender ipc_sender_; | 795 TestIPCSender ipc_sender_; |
802 scoped_refptr<EventRouterForwarder> event_router_; | 796 scoped_refptr<EventRouterForwarder> event_router_; |
803 scoped_refptr<ExtensionInfoMap> extension_info_map_; | 797 scoped_refptr<ExtensionInfoMap> extension_info_map_; |
804 scoped_ptr<ChromeNetworkDelegate> network_delegate_; | 798 scoped_ptr<ChromeNetworkDelegate> network_delegate_; |
805 scoped_ptr<net::MockHostResolver> host_resolver_; | 799 scoped_ptr<net::MockHostResolver> host_resolver_; |
806 scoped_ptr<net::TestURLRequestContext> context_; | 800 scoped_ptr<net::TestURLRequestContext> context_; |
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2134 EXPECT_TRUE(credentials_set); | 2128 EXPECT_TRUE(credentials_set); |
2135 EXPECT_FALSE(auth3.Empty()); | 2129 EXPECT_FALSE(auth3.Empty()); |
2136 EXPECT_EQ(username, auth1.username()); | 2130 EXPECT_EQ(username, auth1.username()); |
2137 EXPECT_EQ(password, auth1.password()); | 2131 EXPECT_EQ(password, auth1.password()); |
2138 EXPECT_EQ(1u, warning_set.size()); | 2132 EXPECT_EQ(1u, warning_set.size()); |
2139 EXPECT_TRUE(HasWarning(warning_set, "extid2")); | 2133 EXPECT_TRUE(HasWarning(warning_set, "extid2")); |
2140 EXPECT_EQ(3u, capturing_net_log.GetSize()); | 2134 EXPECT_EQ(3u, capturing_net_log.GetSize()); |
2141 } | 2135 } |
2142 | 2136 |
2143 } // namespace extensions | 2137 } // namespace extensions |
OLD | NEW |