| 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 "components/sync/core_impl/syncapi_server_connection_manager.h" | 5 #include "components/sync/engine_impl/net/sync_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/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "components/sync/base/cancelation_signal.h" | 14 #include "components/sync/base/cancelation_signal.h" |
| 15 #include "components/sync/core/http_post_provider_factory.h" | 15 #include "components/sync/engine/net/http_post_provider_factory.h" |
| 16 #include "components/sync/core/http_post_provider_interface.h" | 16 #include "components/sync/engine/net/http_post_provider_interface.h" |
| 17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 namespace syncer { | 20 namespace syncer { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 using base::TimeDelta; | 23 using base::TimeDelta; |
| 24 | 24 |
| 25 class BlockingHttpPost : public HttpPostProviderInterface { | 25 class BlockingHttpPost : public HttpPostProviderInterface { |
| 26 public: | 26 public: |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 return new BlockingHttpPost(); | 61 return new BlockingHttpPost(); |
| 62 } | 62 } |
| 63 void Destroy(HttpPostProviderInterface* http) override { | 63 void Destroy(HttpPostProviderInterface* http) override { |
| 64 delete static_cast<BlockingHttpPost*>(http); | 64 delete static_cast<BlockingHttpPost*>(http); |
| 65 } | 65 } |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 // Ask the ServerConnectionManager to stop before it is created. | 70 // Ask the ServerConnectionManager to stop before it is created. |
| 71 TEST(SyncAPIServerConnectionManagerTest, VeryEarlyAbortPost) { | 71 TEST(SyncServerConnectionManagerTest, VeryEarlyAbortPost) { |
| 72 CancelationSignal signal; | 72 CancelationSignal signal; |
| 73 signal.Signal(); | 73 signal.Signal(); |
| 74 SyncAPIServerConnectionManager server("server", 0, true, | 74 SyncServerConnectionManager server("server", 0, true, |
| 75 new BlockingHttpPostFactory(), &signal); | 75 new BlockingHttpPostFactory(), &signal); |
| 76 | 76 |
| 77 ServerConnectionManager::PostBufferParams params; | 77 ServerConnectionManager::PostBufferParams params; |
| 78 | 78 |
| 79 bool result = server.PostBufferToPath(¶ms, "/testpath", "testauth"); | 79 bool result = server.PostBufferToPath(¶ms, "/testpath", "testauth"); |
| 80 | 80 |
| 81 EXPECT_FALSE(result); | 81 EXPECT_FALSE(result); |
| 82 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, | 82 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, |
| 83 params.response.server_status); | 83 params.response.server_status); |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Ask the ServerConnectionManager to stop before its first request is made. | 86 // Ask the ServerConnectionManager to stop before its first request is made. |
| 87 TEST(SyncAPIServerConnectionManagerTest, EarlyAbortPost) { | 87 TEST(SyncServerConnectionManagerTest, EarlyAbortPost) { |
| 88 CancelationSignal signal; | 88 CancelationSignal signal; |
| 89 SyncAPIServerConnectionManager server("server", 0, true, | 89 SyncServerConnectionManager server("server", 0, true, |
| 90 new BlockingHttpPostFactory(), &signal); | 90 new BlockingHttpPostFactory(), &signal); |
| 91 | 91 |
| 92 ServerConnectionManager::PostBufferParams params; | 92 ServerConnectionManager::PostBufferParams params; |
| 93 | 93 |
| 94 signal.Signal(); | 94 signal.Signal(); |
| 95 bool result = server.PostBufferToPath(¶ms, "/testpath", "testauth"); | 95 bool result = server.PostBufferToPath(¶ms, "/testpath", "testauth"); |
| 96 | 96 |
| 97 EXPECT_FALSE(result); | 97 EXPECT_FALSE(result); |
| 98 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, | 98 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, |
| 99 params.response.server_status); | 99 params.response.server_status); |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Ask the ServerConnectionManager to stop during a request. | 102 // Ask the ServerConnectionManager to stop during a request. |
| 103 TEST(SyncAPIServerConnectionManagerTest, AbortPost) { | 103 TEST(SyncServerConnectionManagerTest, AbortPost) { |
| 104 CancelationSignal signal; | 104 CancelationSignal signal; |
| 105 SyncAPIServerConnectionManager server("server", 0, true, | 105 SyncServerConnectionManager server("server", 0, true, |
| 106 new BlockingHttpPostFactory(), &signal); | 106 new BlockingHttpPostFactory(), &signal); |
| 107 | 107 |
| 108 ServerConnectionManager::PostBufferParams params; | 108 ServerConnectionManager::PostBufferParams params; |
| 109 | 109 |
| 110 base::Thread abort_thread("Test_AbortThread"); | 110 base::Thread abort_thread("Test_AbortThread"); |
| 111 ASSERT_TRUE(abort_thread.Start()); | 111 ASSERT_TRUE(abort_thread.Start()); |
| 112 abort_thread.task_runner()->PostDelayedTask( | 112 abort_thread.task_runner()->PostDelayedTask( |
| 113 FROM_HERE, | 113 FROM_HERE, |
| 114 base::Bind(&CancelationSignal::Signal, base::Unretained(&signal)), | 114 base::Bind(&CancelationSignal::Signal, base::Unretained(&signal)), |
| 115 TestTimeouts::tiny_timeout()); | 115 TestTimeouts::tiny_timeout()); |
| 116 | 116 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 166 |
| 167 private: | 167 private: |
| 168 int error_code_; | 168 int error_code_; |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 } // namespace | 171 } // namespace |
| 172 | 172 |
| 173 // Fail request with TIMED_OUT error. Make sure server status is | 173 // Fail request with TIMED_OUT error. Make sure server status is |
| 174 // CONNECTION_UNAVAILABLE and therefore request will be retried after network | 174 // CONNECTION_UNAVAILABLE and therefore request will be retried after network |
| 175 // change. | 175 // change. |
| 176 TEST(SyncAPIServerConnectionManagerTest, FailPostWithTimedOut) { | 176 TEST(SyncServerConnectionManagerTest, FailPostWithTimedOut) { |
| 177 CancelationSignal signal; | 177 CancelationSignal signal; |
| 178 SyncAPIServerConnectionManager server( | 178 SyncServerConnectionManager server( |
| 179 "server", 0, true, new FailingHttpPostFactory(net::ERR_TIMED_OUT), | 179 "server", 0, true, new FailingHttpPostFactory(net::ERR_TIMED_OUT), |
| 180 &signal); | 180 &signal); |
| 181 | 181 |
| 182 ServerConnectionManager::PostBufferParams params; | 182 ServerConnectionManager::PostBufferParams params; |
| 183 | 183 |
| 184 bool result = server.PostBufferToPath(¶ms, "/testpath", "testauth"); | 184 bool result = server.PostBufferToPath(¶ms, "/testpath", "testauth"); |
| 185 | 185 |
| 186 EXPECT_FALSE(result); | 186 EXPECT_FALSE(result); |
| 187 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, | 187 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, |
| 188 params.response.server_status); | 188 params.response.server_status); |
| 189 } | 189 } |
| 190 | 190 |
| 191 } // namespace syncer | 191 } // namespace syncer |
| OLD | NEW |