| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } | 62 } |
| 63 virtual void Destroy(HttpPostProviderInterface* http) OVERRIDE { | 63 virtual 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 TEST(SyncAPIServerConnectionManagerTest, EarlyAbortPost) { | 70 TEST(SyncAPIServerConnectionManagerTest, EarlyAbortPost) { |
| 71 SyncAPIServerConnectionManager server( | 71 SyncAPIServerConnectionManager server( |
| 72 "server", 0, true, new BlockingHttpPostFactory()); | 72 "server", 0, true, new BlockingHttpPostFactory(), false); |
| 73 | 73 |
| 74 ServerConnectionManager::PostBufferParams params; | 74 ServerConnectionManager::PostBufferParams params; |
| 75 ScopedServerStatusWatcher watcher(&server, ¶ms.response); | 75 ScopedServerStatusWatcher watcher(&server, ¶ms.response); |
| 76 | 76 |
| 77 server.TerminateAllIO(); | 77 server.TerminateAllIO(); |
| 78 bool result = server.PostBufferToPath( | 78 bool result = server.PostBufferToPath( |
| 79 ¶ms, "/testpath", "testauth", &watcher); | 79 ¶ms, "/testpath", "testauth", &watcher); |
| 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 TEST(SyncAPIServerConnectionManagerTest, AbortPost) { | 86 TEST(SyncAPIServerConnectionManagerTest, AbortPost) { |
| 87 SyncAPIServerConnectionManager server( | 87 SyncAPIServerConnectionManager server( |
| 88 "server", 0, true, new BlockingHttpPostFactory()); | 88 "server", 0, true, new BlockingHttpPostFactory(), false); |
| 89 | 89 |
| 90 ServerConnectionManager::PostBufferParams params; | 90 ServerConnectionManager::PostBufferParams params; |
| 91 ScopedServerStatusWatcher watcher(&server, ¶ms.response); | 91 ScopedServerStatusWatcher watcher(&server, ¶ms.response); |
| 92 | 92 |
| 93 base::Thread abort_thread("Test_AbortThread"); | 93 base::Thread abort_thread("Test_AbortThread"); |
| 94 ASSERT_TRUE(abort_thread.Start()); | 94 ASSERT_TRUE(abort_thread.Start()); |
| 95 abort_thread.message_loop()->PostDelayedTask( | 95 abort_thread.message_loop()->PostDelayedTask( |
| 96 FROM_HERE, | 96 FROM_HERE, |
| 97 base::Bind(&ServerConnectionManager::TerminateAllIO, | 97 base::Bind(&ServerConnectionManager::TerminateAllIO, |
| 98 base::Unretained(&server)), | 98 base::Unretained(&server)), |
| 99 TestTimeouts::tiny_timeout()); | 99 TestTimeouts::tiny_timeout()); |
| 100 | 100 |
| 101 bool result = server.PostBufferToPath( | 101 bool result = server.PostBufferToPath( |
| 102 ¶ms, "/testpath", "testauth", &watcher); | 102 ¶ms, "/testpath", "testauth", &watcher); |
| 103 | 103 |
| 104 EXPECT_FALSE(result); | 104 EXPECT_FALSE(result); |
| 105 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, | 105 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, |
| 106 params.response.server_status); | 106 params.response.server_status); |
| 107 abort_thread.Stop(); | 107 abort_thread.Stop(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 } // namespace syncer | 110 } // namespace syncer |
| OLD | NEW |