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

Side by Side Diff: sync/internal_api/http_bridge_unittest.cc

Issue 16298002: Update sync/, sql/, and printing/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
« no previous file with comments | « sync/internal_api/http_bridge.cc ('k') | sync/notifier/non_blocking_invalidator.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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/synchronization/waitable_event.h" 6 #include "base/synchronization/waitable_event.h"
7 #include "base/threading/thread.h" 7 #include "base/threading/thread.h"
8 #include "net/test/spawned_test_server/spawned_test_server.h" 8 #include "net/test/spawned_test_server/spawned_test_server.h"
9 #include "net/url_request/test_url_fetcher_factory.h" 9 #include "net/url_request/test_url_fetcher_factory.h"
10 #include "net/url_request/url_fetcher_delegate.h" 10 #include "net/url_request/url_fetcher_delegate.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 SyncHttpBridgeTest* test_; 153 SyncHttpBridgeTest* test_;
154 bool never_finishes_; 154 bool never_finishes_;
155 }; 155 };
156 156
157 void SyncHttpBridgeTest::RunSyncThreadBridgeUseTest( 157 void SyncHttpBridgeTest::RunSyncThreadBridgeUseTest(
158 base::WaitableEvent* signal_when_created, 158 base::WaitableEvent* signal_when_created,
159 base::WaitableEvent* signal_when_released) { 159 base::WaitableEvent* signal_when_released) {
160 scoped_refptr<net::URLRequestContextGetter> ctx_getter( 160 scoped_refptr<net::URLRequestContextGetter> ctx_getter(
161 new net::TestURLRequestContextGetter(io_thread_.message_loop_proxy())); 161 new net::TestURLRequestContextGetter(io_thread_.message_loop_proxy()));
162 { 162 {
163 scoped_refptr<ShuntedHttpBridge> bridge(new ShuntedHttpBridge( 163 scoped_refptr<ShuntedHttpBridge> bridge(
164 ctx_getter, this, true)); 164 new ShuntedHttpBridge(ctx_getter.get(), this, true));
165 bridge->SetURL("http://www.google.com", 9999); 165 bridge->SetURL("http://www.google.com", 9999);
166 bridge->SetPostPayload("text/plain", 2, " "); 166 bridge->SetPostPayload("text/plain", 2, " ");
167 bridge_for_race_test_ = bridge; 167 bridge_for_race_test_ = bridge.get();
168 signal_when_created->Signal(); 168 signal_when_created->Signal();
169 169
170 int os_error = 0; 170 int os_error = 0;
171 int response_code = 0; 171 int response_code = 0;
172 bridge->MakeSynchronousPost(&os_error, &response_code); 172 bridge->MakeSynchronousPost(&os_error, &response_code);
173 bridge_for_race_test_ = NULL; 173 bridge_for_race_test_ = NULL;
174 } 174 }
175 signal_when_released->Signal(); 175 signal_when_released->Signal();
176 } 176 }
177 177
178 TEST_F(SyncHttpBridgeTest, TestUsesSameHttpNetworkSession) { 178 TEST_F(SyncHttpBridgeTest, TestUsesSameHttpNetworkSession) {
179 // Run this test on the IO thread because we can only call 179 // Run this test on the IO thread because we can only call
180 // URLRequestContextGetter::GetURLRequestContext on the IO thread. 180 // URLRequestContextGetter::GetURLRequestContext on the IO thread.
181 io_thread()->message_loop() 181 io_thread()->message_loop()
182 ->PostTask(FROM_HERE, 182 ->PostTask(FROM_HERE,
183 base::Bind(&SyncHttpBridgeTest::TestSameHttpNetworkSession, 183 base::Bind(&SyncHttpBridgeTest::TestSameHttpNetworkSession,
184 base::MessageLoop::current(), 184 base::MessageLoop::current(),
185 this)); 185 this));
186 base::MessageLoop::current()->Run(); 186 base::MessageLoop::current()->Run();
187 } 187 }
188 188
189 // Test the HttpBridge without actually making any network requests. 189 // Test the HttpBridge without actually making any network requests.
190 TEST_F(SyncHttpBridgeTest, TestMakeSynchronousPostShunted) { 190 TEST_F(SyncHttpBridgeTest, TestMakeSynchronousPostShunted) {
191 scoped_refptr<net::URLRequestContextGetter> ctx_getter( 191 scoped_refptr<net::URLRequestContextGetter> ctx_getter(
192 new net::TestURLRequestContextGetter(io_thread()->message_loop_proxy())); 192 new net::TestURLRequestContextGetter(io_thread()->message_loop_proxy()));
193 scoped_refptr<HttpBridge> http_bridge(new ShuntedHttpBridge( 193 scoped_refptr<HttpBridge> http_bridge(
194 ctx_getter, this, false)); 194 new ShuntedHttpBridge(ctx_getter.get(), this, false));
195 http_bridge->SetURL("http://www.google.com", 9999); 195 http_bridge->SetURL("http://www.google.com", 9999);
196 http_bridge->SetPostPayload("text/plain", 2, " "); 196 http_bridge->SetPostPayload("text/plain", 2, " ");
197 197
198 int os_error = 0; 198 int os_error = 0;
199 int response_code = 0; 199 int response_code = 0;
200 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); 200 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code);
201 EXPECT_TRUE(success); 201 EXPECT_TRUE(success);
202 EXPECT_EQ(200, response_code); 202 EXPECT_EQ(200, response_code);
203 EXPECT_EQ(0, os_error); 203 EXPECT_EQ(0, os_error);
204 204
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 EXPECT_EQ(200, response_code); 305 EXPECT_EQ(200, response_code);
306 EXPECT_EQ(0, os_error); 306 EXPECT_EQ(0, os_error);
307 307
308 EXPECT_EQ(http_bridge->GetResponseHeaderValue("Content-type"), "text/html"); 308 EXPECT_EQ(http_bridge->GetResponseHeaderValue("Content-type"), "text/html");
309 EXPECT_TRUE(http_bridge->GetResponseHeaderValue("invalid-header").empty()); 309 EXPECT_TRUE(http_bridge->GetResponseHeaderValue("invalid-header").empty());
310 } 310 }
311 311
312 TEST_F(SyncHttpBridgeTest, Abort) { 312 TEST_F(SyncHttpBridgeTest, Abort) {
313 scoped_refptr<net::URLRequestContextGetter> ctx_getter( 313 scoped_refptr<net::URLRequestContextGetter> ctx_getter(
314 new net::TestURLRequestContextGetter(io_thread()->message_loop_proxy())); 314 new net::TestURLRequestContextGetter(io_thread()->message_loop_proxy()));
315 scoped_refptr<ShuntedHttpBridge> http_bridge(new ShuntedHttpBridge( 315 scoped_refptr<ShuntedHttpBridge> http_bridge(
316 ctx_getter, this, true)); 316 new ShuntedHttpBridge(ctx_getter.get(), this, true));
317 http_bridge->SetURL("http://www.google.com", 9999); 317 http_bridge->SetURL("http://www.google.com", 9999);
318 http_bridge->SetPostPayload("text/plain", 2, " "); 318 http_bridge->SetPostPayload("text/plain", 2, " ");
319 319
320 int os_error = 0; 320 int os_error = 0;
321 int response_code = 0; 321 int response_code = 0;
322 322
323 io_thread()->message_loop_proxy()->PostTask( 323 io_thread()->message_loop_proxy()->PostTask(
324 FROM_HERE, 324 FROM_HERE,
325 base::Bind(&SyncHttpBridgeTest::Abort, http_bridge)); 325 base::Bind(&SyncHttpBridgeTest::Abort, http_bridge));
326 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); 326 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code);
327 EXPECT_FALSE(success); 327 EXPECT_FALSE(success);
328 EXPECT_EQ(net::ERR_ABORTED, os_error); 328 EXPECT_EQ(net::ERR_ABORTED, os_error);
329 } 329 }
330 330
331 TEST_F(SyncHttpBridgeTest, AbortLate) { 331 TEST_F(SyncHttpBridgeTest, AbortLate) {
332 scoped_refptr<net::URLRequestContextGetter> ctx_getter( 332 scoped_refptr<net::URLRequestContextGetter> ctx_getter(
333 new net::TestURLRequestContextGetter(io_thread()->message_loop_proxy())); 333 new net::TestURLRequestContextGetter(io_thread()->message_loop_proxy()));
334 scoped_refptr<ShuntedHttpBridge> http_bridge(new ShuntedHttpBridge( 334 scoped_refptr<ShuntedHttpBridge> http_bridge(
335 ctx_getter, this, false)); 335 new ShuntedHttpBridge(ctx_getter.get(), this, false));
336 http_bridge->SetURL("http://www.google.com", 9999); 336 http_bridge->SetURL("http://www.google.com", 9999);
337 http_bridge->SetPostPayload("text/plain", 2, " "); 337 http_bridge->SetPostPayload("text/plain", 2, " ");
338 338
339 int os_error = 0; 339 int os_error = 0;
340 int response_code = 0; 340 int response_code = 0;
341 341
342 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); 342 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code);
343 ASSERT_TRUE(success); 343 ASSERT_TRUE(success);
344 http_bridge->Abort(); 344 http_bridge->Abort();
345 // Ensures no double-free of URLFetcher, etc. 345 // Ensures no double-free of URLFetcher, etc.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 // succeed even though we Release()d the bridge above because the call to 399 // succeed even though we Release()d the bridge above because the call to
400 // Abort should have held a reference. 400 // Abort should have held a reference.
401 io_waiter.Signal(); 401 io_waiter.Signal();
402 402
403 // Done. 403 // Done.
404 sync_thread.Stop(); 404 sync_thread.Stop();
405 io_thread()->Stop(); 405 io_thread()->Stop();
406 } 406 }
407 407
408 } // namespace syncer 408 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/http_bridge.cc ('k') | sync/notifier/non_blocking_invalidator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698