Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1090)

Side by Side Diff: sync/internal_api/syncapi_server_connection_manager_unittest.cc

Issue 10645004: [Sync] Move HttpBridge to sync/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to head Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 11 matching lines...) Expand all
22 using csync::ScopedServerStatusWatcher; 22 using csync::ScopedServerStatusWatcher;
23 23
24 namespace csync { 24 namespace csync {
25 namespace { 25 namespace {
26 26
27 class BlockingHttpPost : public HttpPostProviderInterface { 27 class BlockingHttpPost : public HttpPostProviderInterface {
28 public: 28 public:
29 BlockingHttpPost() : wait_for_abort_(false, false) {} 29 BlockingHttpPost() : wait_for_abort_(false, false) {}
30 virtual ~BlockingHttpPost() {} 30 virtual ~BlockingHttpPost() {}
31 31
32 virtual void SetUserAgent(const char* user_agent) OVERRIDE {}
33 virtual void SetExtraRequestHeaders(const char* headers) OVERRIDE {} 32 virtual void SetExtraRequestHeaders(const char* headers) OVERRIDE {}
34 virtual void SetURL(const char* url, int port) OVERRIDE {} 33 virtual void SetURL(const char* url, int port) OVERRIDE {}
35 virtual void SetPostPayload(const char* content_type, 34 virtual void SetPostPayload(const char* content_type,
36 int content_length, 35 int content_length,
37 const char* content) OVERRIDE {} 36 const char* content) OVERRIDE {}
38 virtual bool MakeSynchronousPost(int* error_code, int* response_code) 37 virtual bool MakeSynchronousPost(int* error_code, int* response_code)
39 OVERRIDE { 38 OVERRIDE {
40 wait_for_abort_.TimedWait(TimeDelta::FromMilliseconds( 39 wait_for_abort_.TimedWait(TimeDelta::FromMilliseconds(
41 TestTimeouts::action_max_timeout_ms())); 40 TestTimeouts::action_max_timeout_ms()));
42 *error_code = net::ERR_ABORTED; 41 *error_code = net::ERR_ABORTED;
(...skipping 24 matching lines...) Expand all
67 } 66 }
68 virtual void Destroy(HttpPostProviderInterface* http) OVERRIDE { 67 virtual void Destroy(HttpPostProviderInterface* http) OVERRIDE {
69 delete static_cast<BlockingHttpPost*>(http); 68 delete static_cast<BlockingHttpPost*>(http);
70 } 69 }
71 }; 70 };
72 71
73 } // namespace 72 } // namespace
74 73
75 TEST(SyncAPIServerConnectionManagerTest, EarlyAbortPost) { 74 TEST(SyncAPIServerConnectionManagerTest, EarlyAbortPost) {
76 SyncAPIServerConnectionManager server( 75 SyncAPIServerConnectionManager server(
77 "server", 0, true, "1", new BlockingHttpPostFactory()); 76 "server", 0, true, new BlockingHttpPostFactory());
78 77
79 ServerConnectionManager::PostBufferParams params; 78 ServerConnectionManager::PostBufferParams params;
80 ScopedServerStatusWatcher watcher(&server, &params.response); 79 ScopedServerStatusWatcher watcher(&server, &params.response);
81 80
82 server.TerminateAllIO(); 81 server.TerminateAllIO();
83 bool result = server.PostBufferToPath( 82 bool result = server.PostBufferToPath(
84 &params, "/testpath", "testauth", &watcher); 83 &params, "/testpath", "testauth", &watcher);
85 84
86 EXPECT_FALSE(result); 85 EXPECT_FALSE(result);
87 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, 86 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE,
88 params.response.server_status); 87 params.response.server_status);
89 } 88 }
90 89
91 TEST(SyncAPIServerConnectionManagerTest, AbortPost) { 90 TEST(SyncAPIServerConnectionManagerTest, AbortPost) {
92 SyncAPIServerConnectionManager server( 91 SyncAPIServerConnectionManager server(
93 "server", 0, true, "1", new BlockingHttpPostFactory()); 92 "server", 0, true, new BlockingHttpPostFactory());
94 93
95 ServerConnectionManager::PostBufferParams params; 94 ServerConnectionManager::PostBufferParams params;
96 ScopedServerStatusWatcher watcher(&server, &params.response); 95 ScopedServerStatusWatcher watcher(&server, &params.response);
97 96
98 base::Thread abort_thread("Test_AbortThread"); 97 base::Thread abort_thread("Test_AbortThread");
99 ASSERT_TRUE(abort_thread.Start()); 98 ASSERT_TRUE(abort_thread.Start());
100 abort_thread.message_loop()->PostDelayedTask( 99 abort_thread.message_loop()->PostDelayedTask(
101 FROM_HERE, 100 FROM_HERE,
102 base::Bind(&ServerConnectionManager::TerminateAllIO, 101 base::Bind(&ServerConnectionManager::TerminateAllIO,
103 base::Unretained(&server)), 102 base::Unretained(&server)),
104 TestTimeouts::tiny_timeout()); 103 TestTimeouts::tiny_timeout());
105 104
106 bool result = server.PostBufferToPath( 105 bool result = server.PostBufferToPath(
107 &params, "/testpath", "testauth", &watcher); 106 &params, "/testpath", "testauth", &watcher);
108 107
109 EXPECT_FALSE(result); 108 EXPECT_FALSE(result);
110 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, 109 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE,
111 params.response.server_status); 110 params.response.server_status);
112 abort_thread.Stop(); 111 abort_thread.Stop();
113 } 112 }
114 113
115 } // namespace csync 114 } // namespace csync
OLDNEW
« no previous file with comments | « sync/internal_api/syncapi_server_connection_manager.cc ('k') | sync/internal_api/syncapi_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698