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

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

Issue 10581012: Move test_url_fetcher_factory.* from content/ to net/url_request (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove export annotations Created 8 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 "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 "chrome/browser/sync/glue/http_bridge.h" 8 #include "chrome/browser/sync/glue/http_bridge.h"
9 #include "content/public/test/test_browser_thread.h" 9 #include "content/public/test/test_browser_thread.h"
10 #include "content/public/test/test_url_fetcher_factory.h"
11 #include "net/test/test_server.h" 10 #include "net/test/test_server.h"
11 #include "net/url_request/test_url_fetcher_factory.h"
12 #include "net/url_request/url_fetcher_delegate.h" 12 #include "net/url_request/url_fetcher_delegate.h"
13 #include "net/url_request/url_request_test_util.h" 13 #include "net/url_request/url_request_test_util.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using browser_sync::HttpBridge; 16 using browser_sync::HttpBridge;
17 using content::BrowserThread; 17 using content::BrowserThread;
18 18
19 namespace { 19 namespace {
20 // TODO(timsteele): Should use PathService here. See Chromium Issue 3113. 20 // TODO(timsteele): Should use PathService here. See Chromium Issue 3113.
21 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); 21 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data");
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 } 134 }
135 private: 135 private:
136 ~ShuntedHttpBridge() {} 136 ~ShuntedHttpBridge() {}
137 137
138 void CallOnURLFetchComplete() { 138 void CallOnURLFetchComplete() {
139 ASSERT_TRUE(MessageLoop::current() == test_->GetIOThreadLoop()); 139 ASSERT_TRUE(MessageLoop::current() == test_->GetIOThreadLoop());
140 // We return no cookies and a dummy content response. 140 // We return no cookies and a dummy content response.
141 net::ResponseCookies cookies; 141 net::ResponseCookies cookies;
142 142
143 std::string response_content = "success!"; 143 std::string response_content = "success!";
144 TestURLFetcher fetcher(0, GURL(), NULL); 144 net::TestURLFetcher fetcher(0, GURL(), NULL);
145 fetcher.set_url(GURL("www.google.com")); 145 fetcher.set_url(GURL("www.google.com"));
146 fetcher.set_response_code(200); 146 fetcher.set_response_code(200);
147 fetcher.set_cookies(cookies); 147 fetcher.set_cookies(cookies);
148 fetcher.SetResponseString(response_content); 148 fetcher.SetResponseString(response_content);
149 OnURLFetchComplete(&fetcher); 149 OnURLFetchComplete(&fetcher);
150 } 150 }
151 SyncHttpBridgeTest* test_; 151 SyncHttpBridgeTest* test_;
152 bool never_finishes_; 152 bool never_finishes_;
153 }; 153 };
154 154
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 375
376 signal_when_created.Wait(); // Wait till we have a bridge to abort. 376 signal_when_created.Wait(); // Wait till we have a bridge to abort.
377 ASSERT_TRUE(bridge_for_race_test()); 377 ASSERT_TRUE(bridge_for_race_test());
378 378
379 // Schedule the fetch completion callback (but don't run it yet). Don't take 379 // Schedule the fetch completion callback (but don't run it yet). Don't take
380 // a reference to the bridge to mimic URLFetcher's handling of the delegate. 380 // a reference to the bridge to mimic URLFetcher's handling of the delegate.
381 net::URLFetcherDelegate* delegate = 381 net::URLFetcherDelegate* delegate =
382 static_cast<net::URLFetcherDelegate*>(bridge_for_race_test()); 382 static_cast<net::URLFetcherDelegate*>(bridge_for_race_test());
383 net::ResponseCookies cookies; 383 net::ResponseCookies cookies;
384 std::string response_content = "success!"; 384 std::string response_content = "success!";
385 TestURLFetcher fetcher(0, GURL(), NULL); 385 net::TestURLFetcher fetcher(0, GURL(), NULL);
386 fetcher.set_url(GURL("www.google.com")); 386 fetcher.set_url(GURL("www.google.com"));
387 fetcher.set_response_code(200); 387 fetcher.set_response_code(200);
388 fetcher.set_cookies(cookies); 388 fetcher.set_cookies(cookies);
389 fetcher.SetResponseString(response_content); 389 fetcher.SetResponseString(response_content);
390 ASSERT_TRUE(BrowserThread::PostTask( 390 ASSERT_TRUE(BrowserThread::PostTask(
391 BrowserThread::IO, FROM_HERE, 391 BrowserThread::IO, FROM_HERE,
392 base::Bind(&net::URLFetcherDelegate::OnURLFetchComplete, 392 base::Bind(&net::URLFetcherDelegate::OnURLFetchComplete,
393 base::Unretained(delegate), &fetcher))); 393 base::Unretained(delegate), &fetcher)));
394 394
395 // Abort the fetch. This should be smart enough to handle the case where 395 // Abort the fetch. This should be smart enough to handle the case where
396 // the bridge is destroyed before the callback scheduled above completes. 396 // the bridge is destroyed before the callback scheduled above completes.
397 bridge_for_race_test()->Abort(); 397 bridge_for_race_test()->Abort();
398 398
399 // Wait until the sync thread releases its ref on the bridge. 399 // Wait until the sync thread releases its ref on the bridge.
400 signal_when_released.Wait(); 400 signal_when_released.Wait();
401 ASSERT_FALSE(bridge_for_race_test()); 401 ASSERT_FALSE(bridge_for_race_test());
402 402
403 // Unleash the hounds. The fetch completion callback should fire first, and 403 // Unleash the hounds. The fetch completion callback should fire first, and
404 // succeed even though we Release()d the bridge above because the call to 404 // succeed even though we Release()d the bridge above because the call to
405 // Abort should have held a reference. 405 // Abort should have held a reference.
406 io_waiter.Signal(); 406 io_waiter.Signal();
407 407
408 // Done. 408 // Done.
409 sync_thread.Stop(); 409 sync_thread.Stop();
410 io_thread()->Stop(); 410 io_thread()->Stop();
411 } 411 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698