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 "sync/internal_api/syncapi_server_connection_manager.h" | 5 #include "sync/internal_api/syncapi_server_connection_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 TestTimeouts::tiny_timeout()); | 113 TestTimeouts::tiny_timeout()); |
114 | 114 |
115 bool result = server.PostBufferToPath(¶ms, "/testpath", "testauth"); | 115 bool result = server.PostBufferToPath(¶ms, "/testpath", "testauth"); |
116 | 116 |
117 EXPECT_FALSE(result); | 117 EXPECT_FALSE(result); |
118 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, | 118 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, |
119 params.response.server_status); | 119 params.response.server_status); |
120 abort_thread.Stop(); | 120 abort_thread.Stop(); |
121 } | 121 } |
122 | 122 |
| 123 namespace { |
| 124 |
| 125 class FailingHttpPost : public HttpPostProviderInterface { |
| 126 public: |
| 127 explicit FailingHttpPost(int error_code) : error_code_(error_code) {} |
| 128 ~FailingHttpPost() override {} |
| 129 |
| 130 void SetExtraRequestHeaders(const char* headers) override {} |
| 131 void SetURL(const char* url, int port) override {} |
| 132 void SetPostPayload(const char* content_type, |
| 133 int content_length, |
| 134 const char* content) override {} |
| 135 bool MakeSynchronousPost(int* error_code, int* response_code) override { |
| 136 *error_code = error_code_; |
| 137 return false; |
| 138 } |
| 139 int GetResponseContentLength() const override { return 0; } |
| 140 const char* GetResponseContent() const override { return ""; } |
| 141 const std::string GetResponseHeaderValue( |
| 142 const std::string& name) const override { |
| 143 return std::string(); |
| 144 } |
| 145 void Abort() override {} |
| 146 |
| 147 private: |
| 148 int error_code_; |
| 149 }; |
| 150 |
| 151 class FailingHttpPostFactory : public HttpPostProviderFactory { |
| 152 public: |
| 153 explicit FailingHttpPostFactory(int error_code) : error_code_(error_code) {} |
| 154 ~FailingHttpPostFactory() override {} |
| 155 void Init(const std::string& user_agent, |
| 156 const BindToTrackerCallback& bind_to_tracker_callback) override {} |
| 157 |
| 158 HttpPostProviderInterface* Create() override { |
| 159 return new FailingHttpPost(error_code_); |
| 160 } |
| 161 void Destroy(HttpPostProviderInterface* http) override { |
| 162 delete static_cast<FailingHttpPost*>(http); |
| 163 } |
| 164 |
| 165 private: |
| 166 int error_code_; |
| 167 }; |
| 168 |
| 169 } // namespace |
| 170 |
| 171 // Fail request with TIMED_OUT error. Make sure server status is |
| 172 // CONNECTION_UNAVAILABLE and therefore request will be retried after network |
| 173 // change. |
| 174 TEST(SyncAPIServerConnectionManagerTest, FailPostWithTimedOut) { |
| 175 CancelationSignal signal; |
| 176 SyncAPIServerConnectionManager server( |
| 177 "server", 0, true, new FailingHttpPostFactory(net::ERR_TIMED_OUT), |
| 178 &signal); |
| 179 |
| 180 ServerConnectionManager::PostBufferParams params; |
| 181 |
| 182 bool result = server.PostBufferToPath(¶ms, "/testpath", "testauth"); |
| 183 |
| 184 EXPECT_FALSE(result); |
| 185 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, |
| 186 params.response.server_status); |
| 187 } |
| 188 |
123 } // namespace syncer | 189 } // namespace syncer |
OLD | NEW |