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 "chrome/browser/sync/internal_api/syncapi_server_connection_manager.h" | 5 #include "chrome/browser/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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 server.TerminateAllIO(); | 82 server.TerminateAllIO(); |
83 bool result = server.PostBufferToPath( | 83 bool result = server.PostBufferToPath( |
84 ¶ms, "/testpath", "testauth", &watcher); | 84 ¶ms, "/testpath", "testauth", &watcher); |
85 | 85 |
86 EXPECT_FALSE(result); | 86 EXPECT_FALSE(result); |
87 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, | 87 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, |
88 params.response.server_status); | 88 params.response.server_status); |
89 } | 89 } |
90 | 90 |
91 TEST(SyncAPIServerConnectionManagerTest, EarlyAbortCheckTime) { | |
92 SyncAPIServerConnectionManager server( | |
93 "server", 0, true, "1", new BlockingHttpPostFactory()); | |
94 int32 time = 0; | |
95 server.TerminateAllIO(); | |
96 bool result = server.CheckTime(&time); | |
97 EXPECT_FALSE(result); | |
98 } | |
99 | |
100 TEST(SyncAPIServerConnectionManagerTest, AbortPost) { | 91 TEST(SyncAPIServerConnectionManagerTest, AbortPost) { |
101 SyncAPIServerConnectionManager server( | 92 SyncAPIServerConnectionManager server( |
102 "server", 0, true, "1", new BlockingHttpPostFactory()); | 93 "server", 0, true, "1", new BlockingHttpPostFactory()); |
103 | 94 |
104 ServerConnectionManager::PostBufferParams params; | 95 ServerConnectionManager::PostBufferParams params; |
105 ScopedServerStatusWatcher watcher(&server, ¶ms.response); | 96 ScopedServerStatusWatcher watcher(&server, ¶ms.response); |
106 | 97 |
107 base::Thread abort_thread("Test_AbortThread"); | 98 base::Thread abort_thread("Test_AbortThread"); |
108 ASSERT_TRUE(abort_thread.Start()); | 99 ASSERT_TRUE(abort_thread.Start()); |
109 abort_thread.message_loop()->PostDelayedTask( | 100 abort_thread.message_loop()->PostDelayedTask( |
110 FROM_HERE, | 101 FROM_HERE, |
111 base::Bind(&ServerConnectionManager::TerminateAllIO, | 102 base::Bind(&ServerConnectionManager::TerminateAllIO, |
112 base::Unretained(&server)), | 103 base::Unretained(&server)), |
113 TestTimeouts::tiny_timeout()); | 104 TestTimeouts::tiny_timeout()); |
114 | 105 |
115 bool result = server.PostBufferToPath( | 106 bool result = server.PostBufferToPath( |
116 ¶ms, "/testpath", "testauth", &watcher); | 107 ¶ms, "/testpath", "testauth", &watcher); |
117 | 108 |
118 EXPECT_FALSE(result); | 109 EXPECT_FALSE(result); |
119 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, | 110 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, |
120 params.response.server_status); | 111 params.response.server_status); |
121 abort_thread.Stop(); | 112 abort_thread.Stop(); |
122 } | 113 } |
123 | 114 |
124 TEST(SyncAPIServerConnectionManagerTest, AbortCheckTime) { | |
125 SyncAPIServerConnectionManager server( | |
126 "server", 0, true, "1", new BlockingHttpPostFactory()); | |
127 | |
128 base::Thread abort_thread("Test_AbortThread"); | |
129 ASSERT_TRUE(abort_thread.Start()); | |
130 abort_thread.message_loop()->PostDelayedTask( | |
131 FROM_HERE, | |
132 base::Bind(&ServerConnectionManager::TerminateAllIO, | |
133 base::Unretained(&server)), | |
134 TestTimeouts::tiny_timeout()); | |
135 | |
136 int32 time = 0; | |
137 bool result = server.CheckTime(&time); | |
138 EXPECT_FALSE(result); | |
139 abort_thread.Stop(); | |
140 } | |
141 | |
142 } // namespace sync_api | 115 } // namespace sync_api |
OLD | NEW |