| 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/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 // as if it completed. | 153 // as if it completed. |
| 154 test_->GetIOThreadLoop()->PostTask(FROM_HERE, | 154 test_->GetIOThreadLoop()->PostTask(FROM_HERE, |
| 155 base::Bind(&ShuntedHttpBridge::CallOnURLFetchComplete, this)); | 155 base::Bind(&ShuntedHttpBridge::CallOnURLFetchComplete, this)); |
| 156 } | 156 } |
| 157 | 157 |
| 158 private: | 158 private: |
| 159 ~ShuntedHttpBridge() override {} | 159 ~ShuntedHttpBridge() override {} |
| 160 | 160 |
| 161 void CallOnURLFetchComplete() { | 161 void CallOnURLFetchComplete() { |
| 162 ASSERT_TRUE(base::MessageLoop::current() == test_->GetIOThreadLoop()); | 162 ASSERT_TRUE(base::MessageLoop::current() == test_->GetIOThreadLoop()); |
| 163 // We return no cookies and a dummy content response. | 163 // We return a dummy content response. |
| 164 net::ResponseCookies cookies; | |
| 165 | |
| 166 std::string response_content = "success!"; | 164 std::string response_content = "success!"; |
| 167 net::TestURLFetcher fetcher(0, GURL("http://www.google.com"), NULL); | 165 net::TestURLFetcher fetcher(0, GURL("http://www.google.com"), NULL); |
| 168 scoped_refptr<net::HttpResponseHeaders> response_headers( | 166 scoped_refptr<net::HttpResponseHeaders> response_headers( |
| 169 new net::HttpResponseHeaders("")); | 167 new net::HttpResponseHeaders("")); |
| 170 fetcher.set_response_code(200); | 168 fetcher.set_response_code(200); |
| 171 fetcher.set_cookies(cookies); | |
| 172 fetcher.SetResponseString(response_content); | 169 fetcher.SetResponseString(response_content); |
| 173 fetcher.set_response_headers(response_headers); | 170 fetcher.set_response_headers(response_headers); |
| 174 OnURLFetchComplete(&fetcher); | 171 OnURLFetchComplete(&fetcher); |
| 175 } | 172 } |
| 176 MAYBE_SyncHttpBridgeTest* test_; | 173 MAYBE_SyncHttpBridgeTest* test_; |
| 177 bool never_finishes_; | 174 bool never_finishes_; |
| 178 }; | 175 }; |
| 179 | 176 |
| 180 void MAYBE_SyncHttpBridgeTest::RunSyncThreadBridgeUseTest( | 177 void MAYBE_SyncHttpBridgeTest::RunSyncThreadBridgeUseTest( |
| 181 base::WaitableEvent* signal_when_created, | 178 base::WaitableEvent* signal_when_created, |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 FROM_HERE, | 435 FROM_HERE, |
| 439 base::Bind(&base::WaitableEvent::Wait, base::Unretained(&io_waiter)))); | 436 base::Bind(&base::WaitableEvent::Wait, base::Unretained(&io_waiter)))); |
| 440 | 437 |
| 441 signal_when_created.Wait(); // Wait till we have a bridge to abort. | 438 signal_when_created.Wait(); // Wait till we have a bridge to abort. |
| 442 ASSERT_TRUE(bridge_for_race_test()); | 439 ASSERT_TRUE(bridge_for_race_test()); |
| 443 | 440 |
| 444 // Schedule the fetch completion callback (but don't run it yet). Don't take | 441 // Schedule the fetch completion callback (but don't run it yet). Don't take |
| 445 // a reference to the bridge to mimic URLFetcher's handling of the delegate. | 442 // a reference to the bridge to mimic URLFetcher's handling of the delegate. |
| 446 net::URLFetcherDelegate* delegate = | 443 net::URLFetcherDelegate* delegate = |
| 447 static_cast<net::URLFetcherDelegate*>(bridge_for_race_test()); | 444 static_cast<net::URLFetcherDelegate*>(bridge_for_race_test()); |
| 448 net::ResponseCookies cookies; | |
| 449 std::string response_content = "success!"; | 445 std::string response_content = "success!"; |
| 450 net::TestURLFetcher fetcher(0, GURL("http://www.google.com"), NULL); | 446 net::TestURLFetcher fetcher(0, GURL("http://www.google.com"), NULL); |
| 451 fetcher.set_response_code(200); | 447 fetcher.set_response_code(200); |
| 452 fetcher.set_cookies(cookies); | |
| 453 fetcher.SetResponseString(response_content); | 448 fetcher.SetResponseString(response_content); |
| 454 ASSERT_TRUE(io_thread()->task_runner()->PostTask( | 449 ASSERT_TRUE(io_thread()->task_runner()->PostTask( |
| 455 FROM_HERE, | 450 FROM_HERE, |
| 456 base::Bind(&net::URLFetcherDelegate::OnURLFetchComplete, | 451 base::Bind(&net::URLFetcherDelegate::OnURLFetchComplete, |
| 457 base::Unretained(delegate), &fetcher))); | 452 base::Unretained(delegate), &fetcher))); |
| 458 | 453 |
| 459 // Abort the fetch. This should be smart enough to handle the case where | 454 // Abort the fetch. This should be smart enough to handle the case where |
| 460 // the bridge is destroyed before the callback scheduled above completes. | 455 // the bridge is destroyed before the callback scheduled above completes. |
| 461 bridge_for_race_test()->Abort(); | 456 bridge_for_race_test()->Abort(); |
| 462 | 457 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 | 581 |
| 587 // Sync thread: Finally run the posted task, only to find that our | 582 // Sync thread: Finally run the posted task, only to find that our |
| 588 // HttpBridgeFactory has been neutered. Should not crash. | 583 // HttpBridgeFactory has been neutered. Should not crash. |
| 589 factory->Init("TestUserAgent", BindToTrackerCallback()); | 584 factory->Init("TestUserAgent", BindToTrackerCallback()); |
| 590 | 585 |
| 591 // At this point, attempting to use the factory would trigger a crash. Both | 586 // At this point, attempting to use the factory would trigger a crash. Both |
| 592 // this test and the real world code should make sure this never happens. | 587 // this test and the real world code should make sure this never happens. |
| 593 } | 588 } |
| 594 | 589 |
| 595 } // namespace syncer | 590 } // namespace syncer |
| OLD | NEW |