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

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

Issue 8726001: Converted remaining non-factory NewRunnable* calls to use base::Bind (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: formatting Created 9 years 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
« no previous file with comments | « no previous file | chrome/browser/sync/glue/non_frontend_data_type_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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" 8 #include "chrome/test/base/test_url_request_context_getter.h"
9 #include "content/test/test_browser_thread.h" 9 #include "content/test/test_browser_thread.h"
10 #include "content/test/test_url_fetcher_factory.h" 10 #include "content/test/test_url_fetcher_factory.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 test_(test), never_finishes_(never_finishes) { } 102 test_(test), never_finishes_(never_finishes) { }
103 protected: 103 protected:
104 virtual void MakeAsynchronousPost() { 104 virtual void MakeAsynchronousPost() {
105 ASSERT_TRUE(MessageLoop::current() == test_->GetIOThreadLoop()); 105 ASSERT_TRUE(MessageLoop::current() == test_->GetIOThreadLoop());
106 if (never_finishes_) 106 if (never_finishes_)
107 return; 107 return;
108 108
109 // We don't actually want to make a request for this test, so just callback 109 // We don't actually want to make a request for this test, so just callback
110 // as if it completed. 110 // as if it completed.
111 test_->GetIOThreadLoop()->PostTask(FROM_HERE, 111 test_->GetIOThreadLoop()->PostTask(FROM_HERE,
112 NewRunnableMethod(this, &ShuntedHttpBridge::CallOnURLFetchComplete)); 112 base::Bind(&ShuntedHttpBridge::CallOnURLFetchComplete, this));
113 } 113 }
114 private: 114 private:
115 ~ShuntedHttpBridge() {} 115 ~ShuntedHttpBridge() {}
116 116
117 void CallOnURLFetchComplete() { 117 void CallOnURLFetchComplete() {
118 ASSERT_TRUE(MessageLoop::current() == test_->GetIOThreadLoop()); 118 ASSERT_TRUE(MessageLoop::current() == test_->GetIOThreadLoop());
119 // We return no cookies and a dummy content response. 119 // We return no cookies and a dummy content response.
120 net::ResponseCookies cookies; 120 net::ResponseCookies cookies;
121 121
122 std::string response_content = "success!"; 122 std::string response_content = "success!";
123 TestURLFetcher fetcher(0, GURL(), NULL); 123 TestURLFetcher fetcher(0, GURL(), NULL);
124 fetcher.set_url(GURL("www.google.com")); 124 fetcher.set_url(GURL("www.google.com"));
125 fetcher.set_response_code(200); 125 fetcher.set_response_code(200);
126 fetcher.set_cookies(cookies); 126 fetcher.set_cookies(cookies);
127 fetcher.SetResponseString(response_content); 127 fetcher.SetResponseString(response_content);
128 OnURLFetchComplete(&fetcher); 128 OnURLFetchComplete(&fetcher);
129 } 129 }
130 HttpBridgeTest* test_; 130 HttpBridgeTest* test_;
131 bool never_finishes_; 131 bool never_finishes_;
132 }; 132 };
133 133
134 TEST_F(HttpBridgeTest, TestUsesSameHttpNetworkSession) { 134 TEST_F(HttpBridgeTest, TestUsesSameHttpNetworkSession) {
135 // Run this test on the IO thread because we can only call 135 // Run this test on the IO thread because we can only call
136 // URLRequestContextGetter::GetURLRequestContext on the IO thread. 136 // URLRequestContextGetter::GetURLRequestContext on the IO thread.
137 BrowserThread::PostTask( 137 BrowserThread::PostTask(
138 BrowserThread::IO, FROM_HERE, 138 BrowserThread::IO, FROM_HERE,
139 NewRunnableFunction(&HttpBridgeTest::TestSameHttpNetworkSession, 139 base::Bind(&HttpBridgeTest::TestSameHttpNetworkSession,
140 MessageLoop::current(), this)); 140 MessageLoop::current(), this));
141 MessageLoop::current()->Run(); 141 MessageLoop::current()->Run();
142 } 142 }
143 143
144 // Test the HttpBridge without actually making any network requests. 144 // Test the HttpBridge without actually making any network requests.
145 TEST_F(HttpBridgeTest, TestMakeSynchronousPostShunted) { 145 TEST_F(HttpBridgeTest, TestMakeSynchronousPostShunted) {
146 scoped_refptr<net::URLRequestContextGetter> ctx_getter( 146 scoped_refptr<net::URLRequestContextGetter> ctx_getter(
147 new TestURLRequestContextGetter()); 147 new TestURLRequestContextGetter());
148 scoped_refptr<HttpBridge> http_bridge(new ShuntedHttpBridge( 148 scoped_refptr<HttpBridge> http_bridge(new ShuntedHttpBridge(
149 ctx_getter, this, false)); 149 ctx_getter, this, false));
150 http_bridge->SetUserAgent("bob"); 150 http_bridge->SetUserAgent("bob");
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 new TestURLRequestContextGetter()); 271 new TestURLRequestContextGetter());
272 scoped_refptr<ShuntedHttpBridge> http_bridge(new ShuntedHttpBridge( 272 scoped_refptr<ShuntedHttpBridge> http_bridge(new ShuntedHttpBridge(
273 ctx_getter, this, true)); 273 ctx_getter, this, true));
274 http_bridge->SetUserAgent("bob"); 274 http_bridge->SetUserAgent("bob");
275 http_bridge->SetURL("http://www.google.com", 9999); 275 http_bridge->SetURL("http://www.google.com", 9999);
276 http_bridge->SetPostPayload("text/plain", 2, " "); 276 http_bridge->SetPostPayload("text/plain", 2, " ");
277 277
278 int os_error = 0; 278 int os_error = 0;
279 int response_code = 0; 279 int response_code = 0;
280 280
281 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, NewRunnableFunction( 281 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
282 &HttpBridgeTest::Abort, http_bridge)); 282 base::Bind(&HttpBridgeTest::Abort, http_bridge));
283 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); 283 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code);
284 EXPECT_FALSE(success); 284 EXPECT_FALSE(success);
285 EXPECT_EQ(net::ERR_ABORTED, os_error); 285 EXPECT_EQ(net::ERR_ABORTED, os_error);
286 } 286 }
287 287
288 TEST_F(HttpBridgeTest, AbortLate) { 288 TEST_F(HttpBridgeTest, AbortLate) {
289 scoped_refptr<net::URLRequestContextGetter> ctx_getter( 289 scoped_refptr<net::URLRequestContextGetter> ctx_getter(
290 new TestURLRequestContextGetter()); 290 new TestURLRequestContextGetter());
291 scoped_refptr<ShuntedHttpBridge> http_bridge(new ShuntedHttpBridge( 291 scoped_refptr<ShuntedHttpBridge> http_bridge(new ShuntedHttpBridge(
292 ctx_getter, this, false)); 292 ctx_getter, this, false));
293 http_bridge->SetUserAgent("bob"); 293 http_bridge->SetUserAgent("bob");
294 http_bridge->SetURL("http://www.google.com", 9999); 294 http_bridge->SetURL("http://www.google.com", 9999);
295 http_bridge->SetPostPayload("text/plain", 2, " "); 295 http_bridge->SetPostPayload("text/plain", 2, " ");
296 296
297 int os_error = 0; 297 int os_error = 0;
298 int response_code = 0; 298 int response_code = 0;
299 299
300 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); 300 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code);
301 ASSERT_TRUE(success); 301 ASSERT_TRUE(success);
302 http_bridge->Abort(); 302 http_bridge->Abort();
303 // Ensures no double-free of URLFetcher, etc. 303 // Ensures no double-free of URLFetcher, etc.
304 } 304 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync/glue/non_frontend_data_type_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698