Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: chrome/browser/extensions/api/web_request/web_request_api_unittest.cc

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile fixes. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 int modification_size; 757 int modification_size;
761 HeaderModificationTest_Modification modification[10]; 758 HeaderModificationTest_Modification modification[10];
762 int after_size; 759 int after_size;
763 HeaderModificationTest_Header after[10]; 760 HeaderModificationTest_Header after[10];
764 }; 761 };
765 762
766 class ExtensionWebRequestHeaderModificationTest 763 class ExtensionWebRequestHeaderModificationTest
767 : public testing::TestWithParam<HeaderModificationTest> { 764 : public testing::TestWithParam<HeaderModificationTest> {
768 public: 765 public:
769 ExtensionWebRequestHeaderModificationTest() 766 ExtensionWebRequestHeaderModificationTest()
770 : ui_thread_(content::BrowserThread::UI, &message_loop_), 767 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
771 io_thread_(content::BrowserThread::IO, &message_loop_),
772 profile_manager_(TestingBrowserProcess::GetGlobal()), 768 profile_manager_(TestingBrowserProcess::GetGlobal()),
773 event_router_(new EventRouterForwarder) {} 769 event_router_(new EventRouterForwarder) {}
774 770
775 protected: 771 protected:
776 virtual void SetUp() { 772 virtual void SetUp() {
777 ASSERT_TRUE(profile_manager_.SetUp()); 773 ASSERT_TRUE(profile_manager_.SetUp());
778 ChromeNetworkDelegate::InitializePrefsOnUIThread( 774 ChromeNetworkDelegate::InitializePrefsOnUIThread(
779 &enable_referrers_, NULL, NULL, profile_.GetTestingPrefService()); 775 &enable_referrers_, NULL, NULL, profile_.GetTestingPrefService());
780 network_delegate_.reset( 776 network_delegate_.reset(
781 new ChromeNetworkDelegate(event_router_.get(), &enable_referrers_)); 777 new ChromeNetworkDelegate(event_router_.get(), &enable_referrers_));
782 network_delegate_->set_profile(&profile_); 778 network_delegate_->set_profile(&profile_);
783 network_delegate_->set_cookie_settings( 779 network_delegate_->set_cookie_settings(
784 CookieSettings::Factory::GetForProfile(&profile_)); 780 CookieSettings::Factory::GetForProfile(&profile_));
785 context_.reset(new net::TestURLRequestContext(true)); 781 context_.reset(new net::TestURLRequestContext(true));
786 host_resolver_.reset(new net::MockHostResolver()); 782 host_resolver_.reset(new net::MockHostResolver());
787 host_resolver_->rules()->AddSimulatedFailure("doesnotexist"); 783 host_resolver_->rules()->AddSimulatedFailure("doesnotexist");
788 context_->set_host_resolver(host_resolver_.get()); 784 context_->set_host_resolver(host_resolver_.get());
789 context_->set_network_delegate(network_delegate_.get()); 785 context_->set_network_delegate(network_delegate_.get());
790 context_->Init(); 786 context_->Init();
791 } 787 }
792 788
793 base::MessageLoopForIO message_loop_; 789 content::TestBrowserThreadBundle thread_bundle_;
794 content::TestBrowserThread ui_thread_;
795 content::TestBrowserThread io_thread_;
796 TestingProfile profile_; 790 TestingProfile profile_;
797 TestingProfileManager profile_manager_; 791 TestingProfileManager profile_manager_;
798 net::TestDelegate delegate_; 792 net::TestDelegate delegate_;
799 BooleanPrefMember enable_referrers_; 793 BooleanPrefMember enable_referrers_;
800 TestIPCSender ipc_sender_; 794 TestIPCSender ipc_sender_;
801 scoped_refptr<EventRouterForwarder> event_router_; 795 scoped_refptr<EventRouterForwarder> event_router_;
802 scoped_refptr<ExtensionInfoMap> extension_info_map_; 796 scoped_refptr<ExtensionInfoMap> extension_info_map_;
803 scoped_ptr<ChromeNetworkDelegate> network_delegate_; 797 scoped_ptr<ChromeNetworkDelegate> network_delegate_;
804 scoped_ptr<net::MockHostResolver> host_resolver_; 798 scoped_ptr<net::MockHostResolver> host_resolver_;
805 scoped_ptr<net::TestURLRequestContext> context_; 799 scoped_ptr<net::TestURLRequestContext> context_;
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after
2133 EXPECT_TRUE(credentials_set); 2127 EXPECT_TRUE(credentials_set);
2134 EXPECT_FALSE(auth3.Empty()); 2128 EXPECT_FALSE(auth3.Empty());
2135 EXPECT_EQ(username, auth1.username()); 2129 EXPECT_EQ(username, auth1.username());
2136 EXPECT_EQ(password, auth1.password()); 2130 EXPECT_EQ(password, auth1.password());
2137 EXPECT_EQ(1u, warning_set.size()); 2131 EXPECT_EQ(1u, warning_set.size());
2138 EXPECT_TRUE(HasWarning(warning_set, "extid2")); 2132 EXPECT_TRUE(HasWarning(warning_set, "extid2"));
2139 EXPECT_EQ(3u, capturing_net_log.GetSize()); 2133 EXPECT_EQ(3u, capturing_net_log.GetSize());
2140 } 2134 }
2141 2135
2142 } // namespace extensions 2136 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698