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

Side by Side Diff: chrome/browser/sync/glue/http_bridge_unittest.cc

Issue 9562037: Move TestURLRequestContextGetter to url_request_test_util.{h,cc} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change comment Created 8 years, 9 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 "base/message_loop_proxy.h" 5 #include "base/message_loop_proxy.h"
6 #include "base/threading/thread.h" 6 #include "base/threading/thread.h"
7 #include "chrome/browser/sync/glue/http_bridge.h" 7 #include "chrome/browser/sync/glue/http_bridge.h"
8 #include "chrome/test/base/test_url_request_context_getter.h"
9 #include "content/test/test_browser_thread.h" 8 #include "content/test/test_browser_thread.h"
10 #include "content/test/test_url_fetcher_factory.h" 9 #include "content/test/test_url_fetcher_factory.h"
11 #include "net/test/test_server.h" 10 #include "net/test/test_server.h"
12 #include "net/url_request/url_request_test_util.h" 11 #include "net/url_request/url_request_test_util.h"
13 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
14 13
15 using browser_sync::HttpBridge; 14 using browser_sync::HttpBridge;
16 using content::BrowserThread; 15 using content::BrowserThread;
17 16
18 namespace { 17 namespace {
(...skipping 19 matching lines...) Expand all
38 if (fake_default_request_context_getter_) { 37 if (fake_default_request_context_getter_) {
39 GetIOThreadLoop()->ReleaseSoon(FROM_HERE, 38 GetIOThreadLoop()->ReleaseSoon(FROM_HERE,
40 fake_default_request_context_getter_); 39 fake_default_request_context_getter_);
41 fake_default_request_context_getter_ = NULL; 40 fake_default_request_context_getter_ = NULL;
42 } 41 }
43 io_thread_.Stop(); 42 io_thread_.Stop();
44 } 43 }
45 44
46 HttpBridge* BuildBridge() { 45 HttpBridge* BuildBridge() {
47 if (!fake_default_request_context_getter_) { 46 if (!fake_default_request_context_getter_) {
48 fake_default_request_context_getter_ = new TestURLRequestContextGetter(); 47 fake_default_request_context_getter_ =
48 new TestURLRequestContextGetter(
49 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
49 fake_default_request_context_getter_->AddRef(); 50 fake_default_request_context_getter_->AddRef();
50 } 51 }
51 HttpBridge* bridge = new HttpBridge( 52 HttpBridge* bridge = new HttpBridge(
52 new HttpBridge::RequestContextGetter( 53 new HttpBridge::RequestContextGetter(
53 fake_default_request_context_getter_)); 54 fake_default_request_context_getter_));
54 return bridge; 55 return bridge;
55 } 56 }
56 57
57 static void Abort(HttpBridge* bridge) { 58 static void Abort(HttpBridge* bridge) {
58 bridge->Abort(); 59 bridge->Abort();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 BrowserThread::PostTask( 142 BrowserThread::PostTask(
142 BrowserThread::IO, FROM_HERE, 143 BrowserThread::IO, FROM_HERE,
143 base::Bind(&SyncHttpBridgeTest::TestSameHttpNetworkSession, 144 base::Bind(&SyncHttpBridgeTest::TestSameHttpNetworkSession,
144 MessageLoop::current(), this)); 145 MessageLoop::current(), this));
145 MessageLoop::current()->Run(); 146 MessageLoop::current()->Run();
146 } 147 }
147 148
148 // Test the HttpBridge without actually making any network requests. 149 // Test the HttpBridge without actually making any network requests.
149 TEST_F(SyncHttpBridgeTest, TestMakeSynchronousPostShunted) { 150 TEST_F(SyncHttpBridgeTest, TestMakeSynchronousPostShunted) {
150 scoped_refptr<net::URLRequestContextGetter> ctx_getter( 151 scoped_refptr<net::URLRequestContextGetter> ctx_getter(
151 new TestURLRequestContextGetter()); 152 new TestURLRequestContextGetter(
153 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
152 scoped_refptr<HttpBridge> http_bridge(new ShuntedHttpBridge( 154 scoped_refptr<HttpBridge> http_bridge(new ShuntedHttpBridge(
153 ctx_getter, this, false)); 155 ctx_getter, this, false));
154 http_bridge->SetUserAgent("bob"); 156 http_bridge->SetUserAgent("bob");
155 http_bridge->SetURL("http://www.google.com", 9999); 157 http_bridge->SetURL("http://www.google.com", 9999);
156 http_bridge->SetPostPayload("text/plain", 2, " "); 158 http_bridge->SetPostPayload("text/plain", 2, " ");
157 159
158 int os_error = 0; 160 int os_error = 0;
159 int response_code = 0; 161 int response_code = 0;
160 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); 162 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code);
161 EXPECT_TRUE(success); 163 EXPECT_TRUE(success);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 EXPECT_TRUE(success); 267 EXPECT_TRUE(success);
266 EXPECT_EQ(200, response_code); 268 EXPECT_EQ(200, response_code);
267 EXPECT_EQ(0, os_error); 269 EXPECT_EQ(0, os_error);
268 270
269 EXPECT_EQ(http_bridge->GetResponseHeaderValue("Content-type"), "text/html"); 271 EXPECT_EQ(http_bridge->GetResponseHeaderValue("Content-type"), "text/html");
270 EXPECT_TRUE(http_bridge->GetResponseHeaderValue("invalid-header").empty()); 272 EXPECT_TRUE(http_bridge->GetResponseHeaderValue("invalid-header").empty());
271 } 273 }
272 274
273 TEST_F(SyncHttpBridgeTest, Abort) { 275 TEST_F(SyncHttpBridgeTest, Abort) {
274 scoped_refptr<net::URLRequestContextGetter> ctx_getter( 276 scoped_refptr<net::URLRequestContextGetter> ctx_getter(
275 new TestURLRequestContextGetter()); 277 new TestURLRequestContextGetter(
278 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
276 scoped_refptr<ShuntedHttpBridge> http_bridge(new ShuntedHttpBridge( 279 scoped_refptr<ShuntedHttpBridge> http_bridge(new ShuntedHttpBridge(
277 ctx_getter, this, true)); 280 ctx_getter, this, true));
278 http_bridge->SetUserAgent("bob"); 281 http_bridge->SetUserAgent("bob");
279 http_bridge->SetURL("http://www.google.com", 9999); 282 http_bridge->SetURL("http://www.google.com", 9999);
280 http_bridge->SetPostPayload("text/plain", 2, " "); 283 http_bridge->SetPostPayload("text/plain", 2, " ");
281 284
282 int os_error = 0; 285 int os_error = 0;
283 int response_code = 0; 286 int response_code = 0;
284 287
285 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 288 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
286 base::Bind(&SyncHttpBridgeTest::Abort, http_bridge)); 289 base::Bind(&SyncHttpBridgeTest::Abort, http_bridge));
287 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); 290 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code);
288 EXPECT_FALSE(success); 291 EXPECT_FALSE(success);
289 EXPECT_EQ(net::ERR_ABORTED, os_error); 292 EXPECT_EQ(net::ERR_ABORTED, os_error);
290 } 293 }
291 294
292 TEST_F(SyncHttpBridgeTest, AbortLate) { 295 TEST_F(SyncHttpBridgeTest, AbortLate) {
293 scoped_refptr<net::URLRequestContextGetter> ctx_getter( 296 scoped_refptr<net::URLRequestContextGetter> ctx_getter(
294 new TestURLRequestContextGetter()); 297 new TestURLRequestContextGetter(
298 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
295 scoped_refptr<ShuntedHttpBridge> http_bridge(new ShuntedHttpBridge( 299 scoped_refptr<ShuntedHttpBridge> http_bridge(new ShuntedHttpBridge(
296 ctx_getter, this, false)); 300 ctx_getter, this, false));
297 http_bridge->SetUserAgent("bob"); 301 http_bridge->SetUserAgent("bob");
298 http_bridge->SetURL("http://www.google.com", 9999); 302 http_bridge->SetURL("http://www.google.com", 9999);
299 http_bridge->SetPostPayload("text/plain", 2, " "); 303 http_bridge->SetPostPayload("text/plain", 2, " ");
300 304
301 int os_error = 0; 305 int os_error = 0;
302 int response_code = 0; 306 int response_code = 0;
303 307
304 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); 308 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code);
305 ASSERT_TRUE(success); 309 ASSERT_TRUE(success);
306 http_bridge->Abort(); 310 http_bridge->Abort();
307 // Ensures no double-free of URLFetcher, etc. 311 // Ensures no double-free of URLFetcher, etc.
308 } 312 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/malware_details_unittest.cc ('k') | chrome/browser/sync/glue/sync_backend_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698