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" |
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 "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
15 #include "sync/internal_api/public/base/cancelation_signal.h" | 15 #include "sync/internal_api/public/base/cancelation_signal.h" |
16 #include "sync/internal_api/public/http_post_provider_factory.h" | 16 #include "sync/internal_api/public/http_post_provider_factory.h" |
17 #include "sync/internal_api/public/http_post_provider_interface.h" | 17 #include "sync/internal_api/public/http_post_provider_interface.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: |
27 BlockingHttpPost() : wait_for_abort_(false, false) {} | 27 BlockingHttpPost() : wait_for_abort_(false, false) {} |
28 virtual ~BlockingHttpPost() {} | 28 ~BlockingHttpPost() override {} |
29 | 29 |
30 virtual void SetExtraRequestHeaders(const char* headers) override {} | 30 void SetExtraRequestHeaders(const char* headers) override {} |
31 virtual void SetURL(const char* url, int port) override {} | 31 void SetURL(const char* url, int port) override {} |
32 virtual void SetPostPayload(const char* content_type, | 32 void SetPostPayload(const char* content_type, |
33 int content_length, | 33 int content_length, |
34 const char* content) override {} | 34 const char* content) override {} |
35 virtual bool MakeSynchronousPost(int* error_code, int* response_code) | 35 bool MakeSynchronousPost(int* error_code, int* response_code) override { |
36 override { | |
37 wait_for_abort_.TimedWait(TestTimeouts::action_max_timeout()); | 36 wait_for_abort_.TimedWait(TestTimeouts::action_max_timeout()); |
38 *error_code = net::ERR_ABORTED; | 37 *error_code = net::ERR_ABORTED; |
39 return false; | 38 return false; |
40 } | 39 } |
41 virtual int GetResponseContentLength() const override { | 40 int GetResponseContentLength() const override { return 0; } |
42 return 0; | 41 const char* GetResponseContent() const override { return ""; } |
43 } | 42 const std::string GetResponseHeaderValue( |
44 virtual const char* GetResponseContent() const override { | |
45 return ""; | |
46 } | |
47 virtual const std::string GetResponseHeaderValue( | |
48 const std::string& name) const override { | 43 const std::string& name) const override { |
49 return std::string(); | 44 return std::string(); |
50 } | 45 } |
51 virtual void Abort() override { | 46 void Abort() override { wait_for_abort_.Signal(); } |
52 wait_for_abort_.Signal(); | |
53 } | |
54 private: | 47 private: |
55 base::WaitableEvent wait_for_abort_; | 48 base::WaitableEvent wait_for_abort_; |
56 }; | 49 }; |
57 | 50 |
58 class BlockingHttpPostFactory : public HttpPostProviderFactory { | 51 class BlockingHttpPostFactory : public HttpPostProviderFactory { |
59 public: | 52 public: |
60 virtual ~BlockingHttpPostFactory() {} | 53 ~BlockingHttpPostFactory() override {} |
61 virtual void Init(const std::string& user_agent) override {} | 54 void Init(const std::string& user_agent) override {} |
62 virtual HttpPostProviderInterface* Create() override { | 55 HttpPostProviderInterface* Create() override { |
63 return new BlockingHttpPost(); | 56 return new BlockingHttpPost(); |
64 } | 57 } |
65 virtual void Destroy(HttpPostProviderInterface* http) override { | 58 void Destroy(HttpPostProviderInterface* http) override { |
66 delete static_cast<BlockingHttpPost*>(http); | 59 delete static_cast<BlockingHttpPost*>(http); |
67 } | 60 } |
68 }; | 61 }; |
69 | 62 |
70 } // namespace | 63 } // namespace |
71 | 64 |
72 // Ask the ServerConnectionManager to stop before it is created. | 65 // Ask the ServerConnectionManager to stop before it is created. |
73 TEST(SyncAPIServerConnectionManagerTest, VeryEarlyAbortPost) { | 66 TEST(SyncAPIServerConnectionManagerTest, VeryEarlyAbortPost) { |
74 CancelationSignal signal; | 67 CancelationSignal signal; |
75 signal.Signal(); | 68 signal.Signal(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 bool result = server.PostBufferToPath( | 118 bool result = server.PostBufferToPath( |
126 ¶ms, "/testpath", "testauth", &watcher); | 119 ¶ms, "/testpath", "testauth", &watcher); |
127 | 120 |
128 EXPECT_FALSE(result); | 121 EXPECT_FALSE(result); |
129 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, | 122 EXPECT_EQ(HttpResponse::CONNECTION_UNAVAILABLE, |
130 params.response.server_status); | 123 params.response.server_status); |
131 abort_thread.Stop(); | 124 abort_thread.Stop(); |
132 } | 125 } |
133 | 126 |
134 } // namespace syncer | 127 } // namespace syncer |
OLD | NEW |