| OLD | NEW |
| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/bit_cast.h" | 8 #include "base/bit_cast.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // as if it completed. | 150 // as if it completed. |
| 151 test_->GetIOThreadLoop()->PostTask(FROM_HERE, | 151 test_->GetIOThreadLoop()->PostTask(FROM_HERE, |
| 152 base::Bind(&ShuntedHttpBridge::CallOnURLFetchComplete, this)); | 152 base::Bind(&ShuntedHttpBridge::CallOnURLFetchComplete, this)); |
| 153 } | 153 } |
| 154 | 154 |
| 155 private: | 155 private: |
| 156 ~ShuntedHttpBridge() override {} | 156 ~ShuntedHttpBridge() override {} |
| 157 | 157 |
| 158 void CallOnURLFetchComplete() { | 158 void CallOnURLFetchComplete() { |
| 159 ASSERT_TRUE(base::MessageLoop::current() == test_->GetIOThreadLoop()); | 159 ASSERT_TRUE(base::MessageLoop::current() == test_->GetIOThreadLoop()); |
| 160 // We return no cookies and a dummy content response. | 160 // We return a dummy content response. |
| 161 net::ResponseCookies cookies; | |
| 162 | |
| 163 std::string response_content = "success!"; | 161 std::string response_content = "success!"; |
| 164 net::TestURLFetcher fetcher(0, GURL("http://www.google.com"), NULL); | 162 net::TestURLFetcher fetcher(0, GURL("http://www.google.com"), NULL); |
| 165 scoped_refptr<net::HttpResponseHeaders> response_headers( | 163 scoped_refptr<net::HttpResponseHeaders> response_headers( |
| 166 new net::HttpResponseHeaders("")); | 164 new net::HttpResponseHeaders("")); |
| 167 fetcher.set_response_code(200); | 165 fetcher.set_response_code(200); |
| 168 fetcher.set_cookies(cookies); | |
| 169 fetcher.SetResponseString(response_content); | 166 fetcher.SetResponseString(response_content); |
| 170 fetcher.set_response_headers(response_headers); | 167 fetcher.set_response_headers(response_headers); |
| 171 OnURLFetchComplete(&fetcher); | 168 OnURLFetchComplete(&fetcher); |
| 172 } | 169 } |
| 173 MAYBE_SyncHttpBridgeTest* test_; | 170 MAYBE_SyncHttpBridgeTest* test_; |
| 174 bool never_finishes_; | 171 bool never_finishes_; |
| 175 }; | 172 }; |
| 176 | 173 |
| 177 void MAYBE_SyncHttpBridgeTest::RunSyncThreadBridgeUseTest( | 174 void MAYBE_SyncHttpBridgeTest::RunSyncThreadBridgeUseTest( |
| 178 base::WaitableEvent* signal_when_created, | 175 base::WaitableEvent* signal_when_created, |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 FROM_HERE, | 425 FROM_HERE, |
| 429 base::Bind(&base::WaitableEvent::Wait, base::Unretained(&io_waiter)))); | 426 base::Bind(&base::WaitableEvent::Wait, base::Unretained(&io_waiter)))); |
| 430 | 427 |
| 431 signal_when_created.Wait(); // Wait till we have a bridge to abort. | 428 signal_when_created.Wait(); // Wait till we have a bridge to abort. |
| 432 ASSERT_TRUE(bridge_for_race_test()); | 429 ASSERT_TRUE(bridge_for_race_test()); |
| 433 | 430 |
| 434 // Schedule the fetch completion callback (but don't run it yet). Don't take | 431 // Schedule the fetch completion callback (but don't run it yet). Don't take |
| 435 // a reference to the bridge to mimic URLFetcher's handling of the delegate. | 432 // a reference to the bridge to mimic URLFetcher's handling of the delegate. |
| 436 net::URLFetcherDelegate* delegate = | 433 net::URLFetcherDelegate* delegate = |
| 437 static_cast<net::URLFetcherDelegate*>(bridge_for_race_test()); | 434 static_cast<net::URLFetcherDelegate*>(bridge_for_race_test()); |
| 438 net::ResponseCookies cookies; | |
| 439 std::string response_content = "success!"; | 435 std::string response_content = "success!"; |
| 440 net::TestURLFetcher fetcher(0, GURL("http://www.google.com"), NULL); | 436 net::TestURLFetcher fetcher(0, GURL("http://www.google.com"), NULL); |
| 441 fetcher.set_response_code(200); | 437 fetcher.set_response_code(200); |
| 442 fetcher.set_cookies(cookies); | |
| 443 fetcher.SetResponseString(response_content); | 438 fetcher.SetResponseString(response_content); |
| 444 ASSERT_TRUE(io_thread()->task_runner()->PostTask( | 439 ASSERT_TRUE(io_thread()->task_runner()->PostTask( |
| 445 FROM_HERE, | 440 FROM_HERE, |
| 446 base::Bind(&net::URLFetcherDelegate::OnURLFetchComplete, | 441 base::Bind(&net::URLFetcherDelegate::OnURLFetchComplete, |
| 447 base::Unretained(delegate), &fetcher))); | 442 base::Unretained(delegate), &fetcher))); |
| 448 | 443 |
| 449 // Abort the fetch. This should be smart enough to handle the case where | 444 // Abort the fetch. This should be smart enough to handle the case where |
| 450 // the bridge is destroyed before the callback scheduled above completes. | 445 // the bridge is destroyed before the callback scheduled above completes. |
| 451 bridge_for_race_test()->Abort(); | 446 bridge_for_race_test()->Abort(); |
| 452 | 447 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 | 571 |
| 577 // Sync thread: Finally run the posted task, only to find that our | 572 // Sync thread: Finally run the posted task, only to find that our |
| 578 // HttpBridgeFactory has been neutered. Should not crash. | 573 // HttpBridgeFactory has been neutered. Should not crash. |
| 579 factory->Init("TestUserAgent", BindToTrackerCallback()); | 574 factory->Init("TestUserAgent", BindToTrackerCallback()); |
| 580 | 575 |
| 581 // At this point, attempting to use the factory would trigger a crash. Both | 576 // At this point, attempting to use the factory would trigger a crash. Both |
| 582 // this test and the real world code should make sure this never happens. | 577 // this test and the real world code should make sure this never happens. |
| 583 } | 578 } |
| 584 | 579 |
| 585 } // namespace syncer | 580 } // namespace syncer |
| OLD | NEW |