| 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/single_thread_task_runner.h" |
| 9 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 10 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 13 #include "net/http/http_response_headers.h" | 14 #include "net/http/http_response_headers.h" |
| 14 #include "net/test/embedded_test_server/embedded_test_server.h" | 15 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 15 #include "net/url_request/test_url_fetcher_factory.h" | 16 #include "net/url_request/test_url_fetcher_factory.h" |
| 16 #include "net/url_request/url_fetcher_delegate.h" | 17 #include "net/url_request/url_fetcher_delegate.h" |
| 17 #include "net/url_request/url_request_test_util.h" | 18 #include "net/url_request/url_request_test_util.h" |
| 18 #include "sync/internal_api/public/base/cancelation_signal.h" | 19 #include "sync/internal_api/public/base/cancelation_signal.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 bool never_finishes) | 136 bool never_finishes) |
| 136 : HttpBridge(kUserAgent, | 137 : HttpBridge(kUserAgent, |
| 137 baseline_context_getter, | 138 baseline_context_getter, |
| 138 NetworkTimeUpdateCallback(), | 139 NetworkTimeUpdateCallback(), |
| 139 BindToTrackerCallback()), | 140 BindToTrackerCallback()), |
| 140 test_(test), | 141 test_(test), |
| 141 never_finishes_(never_finishes) {} | 142 never_finishes_(never_finishes) {} |
| 142 | 143 |
| 143 protected: | 144 protected: |
| 144 void MakeAsynchronousPost() override { | 145 void MakeAsynchronousPost() override { |
| 145 ASSERT_TRUE(base::MessageLoop::current() == test_->GetIOThreadLoop()); | 146 ASSERT_TRUE( |
| 147 test_->GetIOThreadLoop()->task_runner()->BelongsToCurrentThread()); |
| 146 if (never_finishes_) | 148 if (never_finishes_) |
| 147 return; | 149 return; |
| 148 | 150 |
| 149 // We don't actually want to make a request for this test, so just callback | 151 // We don't actually want to make a request for this test, so just callback |
| 150 // as if it completed. | 152 // as if it completed. |
| 151 test_->GetIOThreadLoop()->PostTask(FROM_HERE, | 153 test_->GetIOThreadLoop()->PostTask(FROM_HERE, |
| 152 base::Bind(&ShuntedHttpBridge::CallOnURLFetchComplete, this)); | 154 base::Bind(&ShuntedHttpBridge::CallOnURLFetchComplete, this)); |
| 153 } | 155 } |
| 154 | 156 |
| 155 private: | 157 private: |
| 156 ~ShuntedHttpBridge() override {} | 158 ~ShuntedHttpBridge() override {} |
| 157 | 159 |
| 158 void CallOnURLFetchComplete() { | 160 void CallOnURLFetchComplete() { |
| 159 ASSERT_TRUE(base::MessageLoop::current() == test_->GetIOThreadLoop()); | 161 ASSERT_TRUE( |
| 162 test_->GetIOThreadLoop()->task_runner()->BelongsToCurrentThread()); |
| 160 // We return a dummy content response. | 163 // We return a dummy content response. |
| 161 std::string response_content = "success!"; | 164 std::string response_content = "success!"; |
| 162 net::TestURLFetcher fetcher(0, GURL("http://www.google.com"), NULL); | 165 net::TestURLFetcher fetcher(0, GURL("http://www.google.com"), NULL); |
| 163 scoped_refptr<net::HttpResponseHeaders> response_headers( | 166 scoped_refptr<net::HttpResponseHeaders> response_headers( |
| 164 new net::HttpResponseHeaders("")); | 167 new net::HttpResponseHeaders("")); |
| 165 fetcher.set_response_code(200); | 168 fetcher.set_response_code(200); |
| 166 fetcher.SetResponseString(response_content); | 169 fetcher.SetResponseString(response_content); |
| 167 fetcher.set_response_headers(response_headers); | 170 fetcher.set_response_headers(response_headers); |
| 168 OnURLFetchComplete(&fetcher); | 171 OnURLFetchComplete(&fetcher); |
| 169 } | 172 } |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 | 574 |
| 572 // Sync thread: Finally run the posted task, only to find that our | 575 // Sync thread: Finally run the posted task, only to find that our |
| 573 // HttpBridgeFactory has been neutered. Should not crash. | 576 // HttpBridgeFactory has been neutered. Should not crash. |
| 574 factory->Init("TestUserAgent", BindToTrackerCallback()); | 577 factory->Init("TestUserAgent", BindToTrackerCallback()); |
| 575 | 578 |
| 576 // At this point, attempting to use the factory would trigger a crash. Both | 579 // At this point, attempting to use the factory would trigger a crash. Both |
| 577 // this test and the real world code should make sure this never happens. | 580 // this test and the real world code should make sure this never happens. |
| 578 } | 581 } |
| 579 | 582 |
| 580 } // namespace syncer | 583 } // namespace syncer |
| OLD | NEW |