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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } // namespace | 65 } // namespace |
66 | 66 |
67 // Ask the ServerConnectionManager to stop before it is created. | 67 // Ask the ServerConnectionManager to stop before it is created. |
68 TEST(SyncAPIServerConnectionManagerTest, VeryEarlyAbortPost) { | 68 TEST(SyncAPIServerConnectionManagerTest, VeryEarlyAbortPost) { |
69 CancelationSignal signal; | 69 CancelationSignal signal; |
70 signal.Signal(); | 70 signal.Signal(); |
71 SyncAPIServerConnectionManager server( | 71 SyncAPIServerConnectionManager server( |
72 "server", 0, true, new BlockingHttpPostFactory(), &signal); | 72 "server", 0, true, new BlockingHttpPostFactory(), &signal); |
73 | 73 |
74 ServerConnectionManager::PostBufferParams params; | 74 ServerConnectionManager::PostBufferParams params; |
75 ScopedServerStatusWatcher watcher(&server, ¶ms.response); | |
76 | 75 |
77 bool result = server.PostBufferToPath( | 76 bool result = server.PostBufferToPath(¶ms, "/testpath", "testauth"); |
78 ¶ms, "/testpath", "testauth", &watcher); | |
79 | 77 |
80 EXPECT_FALSE(result); | 78 EXPECT_FALSE(result); |
81 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, | 79 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, |
82 params.response.server_status); | 80 params.response.server_status); |
83 } | 81 } |
84 | 82 |
85 // Ask the ServerConnectionManager to stop before its first request is made. | 83 // Ask the ServerConnectionManager to stop before its first request is made. |
86 TEST(SyncAPIServerConnectionManagerTest, EarlyAbortPost) { | 84 TEST(SyncAPIServerConnectionManagerTest, EarlyAbortPost) { |
87 CancelationSignal signal; | 85 CancelationSignal signal; |
88 SyncAPIServerConnectionManager server( | 86 SyncAPIServerConnectionManager server( |
89 "server", 0, true, new BlockingHttpPostFactory(), &signal); | 87 "server", 0, true, new BlockingHttpPostFactory(), &signal); |
90 | 88 |
91 ServerConnectionManager::PostBufferParams params; | 89 ServerConnectionManager::PostBufferParams params; |
92 ScopedServerStatusWatcher watcher(&server, ¶ms.response); | |
93 | 90 |
94 signal.Signal(); | 91 signal.Signal(); |
95 bool result = server.PostBufferToPath( | 92 bool result = server.PostBufferToPath(¶ms, "/testpath", "testauth"); |
96 ¶ms, "/testpath", "testauth", &watcher); | |
97 | 93 |
98 EXPECT_FALSE(result); | 94 EXPECT_FALSE(result); |
99 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, | 95 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, |
100 params.response.server_status); | 96 params.response.server_status); |
101 } | 97 } |
102 | 98 |
103 // Ask the ServerConnectionManager to stop during a request. | 99 // Ask the ServerConnectionManager to stop during a request. |
104 TEST(SyncAPIServerConnectionManagerTest, AbortPost) { | 100 TEST(SyncAPIServerConnectionManagerTest, AbortPost) { |
105 CancelationSignal signal; | 101 CancelationSignal signal; |
106 SyncAPIServerConnectionManager server( | 102 SyncAPIServerConnectionManager server( |
107 "server", 0, true, new BlockingHttpPostFactory(), &signal); | 103 "server", 0, true, new BlockingHttpPostFactory(), &signal); |
108 | 104 |
109 ServerConnectionManager::PostBufferParams params; | 105 ServerConnectionManager::PostBufferParams params; |
110 ScopedServerStatusWatcher watcher(&server, ¶ms.response); | |
111 | 106 |
112 base::Thread abort_thread("Test_AbortThread"); | 107 base::Thread abort_thread("Test_AbortThread"); |
113 ASSERT_TRUE(abort_thread.Start()); | 108 ASSERT_TRUE(abort_thread.Start()); |
114 abort_thread.message_loop()->PostDelayedTask( | 109 abort_thread.message_loop()->PostDelayedTask( |
115 FROM_HERE, | 110 FROM_HERE, |
116 base::Bind(&CancelationSignal::Signal, | 111 base::Bind(&CancelationSignal::Signal, |
117 base::Unretained(&signal)), | 112 base::Unretained(&signal)), |
118 TestTimeouts::tiny_timeout()); | 113 TestTimeouts::tiny_timeout()); |
119 | 114 |
120 bool result = server.PostBufferToPath( | 115 bool result = server.PostBufferToPath(¶ms, "/testpath", "testauth"); |
121 ¶ms, "/testpath", "testauth", &watcher); | |
122 | 116 |
123 EXPECT_FALSE(result); | 117 EXPECT_FALSE(result); |
124 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, | 118 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, |
125 params.response.server_status); | 119 params.response.server_status); |
126 abort_thread.Stop(); | 120 abort_thread.Stop(); |
127 } | 121 } |
128 | 122 |
129 } // namespace syncer | 123 } // namespace syncer |
OLD | NEW |