OLD | NEW |
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/common/url_fetcher_delegate.h" | |
10 #include "content/test/test_browser_thread.h" | 9 #include "content/test/test_browser_thread.h" |
11 #include "content/test/test_url_fetcher_factory.h" | 10 #include "content/test/test_url_fetcher_factory.h" |
12 #include "net/test/test_server.h" | 11 #include "net/test/test_server.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"); |
22 } | 22 } |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 base::WaitableEvent io_waiter(false, false); | 371 base::WaitableEvent io_waiter(false, false); |
372 ASSERT_TRUE(BrowserThread::PostTask( | 372 ASSERT_TRUE(BrowserThread::PostTask( |
373 BrowserThread::IO, FROM_HERE, | 373 BrowserThread::IO, FROM_HERE, |
374 base::Bind(&base::WaitableEvent::Wait, base::Unretained(&io_waiter)))); | 374 base::Bind(&base::WaitableEvent::Wait, base::Unretained(&io_waiter)))); |
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 content::URLFetcherDelegate* delegate = | 381 net::URLFetcherDelegate* delegate = |
382 static_cast<content::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 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(&content::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 } |
OLD | NEW |