OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/run_loop.h" | 5 #include "base/run_loop.h" |
6 #include "base/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
7 #include "components/invalidation/gcm_network_channel.h" | 7 #include "components/invalidation/gcm_network_channel.h" |
8 #include "google_apis/gaia/google_service_auth_error.h" | 8 #include "google_apis/gaia/google_service_auth_error.h" |
9 #include "net/url_request/test_url_fetcher_factory.h" | 9 #include "net/url_request/test_url_fetcher_factory.h" |
10 #include "net/url_request/url_request_test_util.h" | 10 #include "net/url_request/url_request_test_util.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace syncer { | 13 namespace syncer { |
14 | 14 |
15 class TestGCMNetworkChannelDelegate : public GCMNetworkChannelDelegate { | 15 class TestGCMNetworkChannelDelegate : public GCMNetworkChannelDelegate { |
16 public: | 16 public: |
17 TestGCMNetworkChannelDelegate() | 17 TestGCMNetworkChannelDelegate() |
18 : register_call_count_(0) {} | 18 : register_call_count_(0) {} |
19 | 19 |
20 virtual void Initialize( | 20 virtual void Initialize( |
21 GCMNetworkChannelDelegate::ConnectionStateCallback callback) OVERRIDE { | 21 GCMNetworkChannelDelegate::ConnectionStateCallback callback) override { |
22 connection_state_callback = callback; | 22 connection_state_callback = callback; |
23 } | 23 } |
24 | 24 |
25 virtual void RequestToken(RequestTokenCallback callback) OVERRIDE { | 25 virtual void RequestToken(RequestTokenCallback callback) override { |
26 request_token_callback = callback; | 26 request_token_callback = callback; |
27 } | 27 } |
28 | 28 |
29 virtual void InvalidateToken(const std::string& token) OVERRIDE { | 29 virtual void InvalidateToken(const std::string& token) override { |
30 invalidated_token = token; | 30 invalidated_token = token; |
31 } | 31 } |
32 | 32 |
33 virtual void Register(RegisterCallback callback) OVERRIDE { | 33 virtual void Register(RegisterCallback callback) override { |
34 ++register_call_count_; | 34 ++register_call_count_; |
35 register_callback = callback; | 35 register_callback = callback; |
36 } | 36 } |
37 | 37 |
38 virtual void SetMessageReceiver(MessageCallback callback) OVERRIDE { | 38 virtual void SetMessageReceiver(MessageCallback callback) override { |
39 message_callback = callback; | 39 message_callback = callback; |
40 } | 40 } |
41 | 41 |
42 RequestTokenCallback request_token_callback; | 42 RequestTokenCallback request_token_callback; |
43 std::string invalidated_token; | 43 std::string invalidated_token; |
44 RegisterCallback register_callback; | 44 RegisterCallback register_callback; |
45 int register_call_count_; | 45 int register_call_count_; |
46 MessageCallback message_callback; | 46 MessageCallback message_callback; |
47 ConnectionStateCallback connection_state_callback; | 47 ConnectionStateCallback connection_state_callback; |
48 }; | 48 }; |
(...skipping 30 matching lines...) Expand all Loading... |
79 TestGCMNetworkChannel( | 79 TestGCMNetworkChannel( |
80 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 80 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
81 scoped_ptr<GCMNetworkChannelDelegate> delegate) | 81 scoped_ptr<GCMNetworkChannelDelegate> delegate) |
82 : GCMNetworkChannel(request_context_getter, delegate.Pass()) { | 82 : GCMNetworkChannel(request_context_getter, delegate.Pass()) { |
83 ResetRegisterBackoffEntryForTest(&kTestBackoffPolicy); | 83 ResetRegisterBackoffEntryForTest(&kTestBackoffPolicy); |
84 } | 84 } |
85 | 85 |
86 protected: | 86 protected: |
87 // On Android GCMNetworkChannel::BuildUrl hits NOTREACHED(). I still want | 87 // On Android GCMNetworkChannel::BuildUrl hits NOTREACHED(). I still want |
88 // tests to run. | 88 // tests to run. |
89 virtual GURL BuildUrl(const std::string& registration_id) OVERRIDE { | 89 virtual GURL BuildUrl(const std::string& registration_id) override { |
90 return GURL("http://test.url.com"); | 90 return GURL("http://test.url.com"); |
91 } | 91 } |
92 }; | 92 }; |
93 | 93 |
94 class GCMNetworkChannelTest; | 94 class GCMNetworkChannelTest; |
95 | 95 |
96 // Test needs to capture setting echo-token header on http request. | 96 // Test needs to capture setting echo-token header on http request. |
97 // This class is going to do that. | 97 // This class is going to do that. |
98 class TestNetworkChannelURLFetcher : public net::FakeURLFetcher { | 98 class TestNetworkChannelURLFetcher : public net::FakeURLFetcher { |
99 public: | 99 public: |
100 TestNetworkChannelURLFetcher(GCMNetworkChannelTest* test, | 100 TestNetworkChannelURLFetcher(GCMNetworkChannelTest* test, |
101 const GURL& url, | 101 const GURL& url, |
102 net::URLFetcherDelegate* delegate, | 102 net::URLFetcherDelegate* delegate, |
103 const std::string& response_data, | 103 const std::string& response_data, |
104 net::HttpStatusCode response_code, | 104 net::HttpStatusCode response_code, |
105 net::URLRequestStatus::Status status) | 105 net::URLRequestStatus::Status status) |
106 : net::FakeURLFetcher(url, | 106 : net::FakeURLFetcher(url, |
107 delegate, | 107 delegate, |
108 response_data, | 108 response_data, |
109 response_code, | 109 response_code, |
110 status), | 110 status), |
111 test_(test) {} | 111 test_(test) {} |
112 | 112 |
113 virtual void AddExtraRequestHeader(const std::string& header_line) OVERRIDE; | 113 virtual void AddExtraRequestHeader(const std::string& header_line) override; |
114 | 114 |
115 private: | 115 private: |
116 GCMNetworkChannelTest* test_; | 116 GCMNetworkChannelTest* test_; |
117 }; | 117 }; |
118 | 118 |
119 class GCMNetworkChannelTest | 119 class GCMNetworkChannelTest |
120 : public ::testing::Test, | 120 : public ::testing::Test, |
121 public SyncNetworkChannel::Observer { | 121 public SyncNetworkChannel::Observer { |
122 public: | 122 public: |
123 GCMNetworkChannelTest() | 123 GCMNetworkChannelTest() |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 std::string* output) { | 160 std::string* output) { |
161 GCMNetworkChannel::Base64EncodeURLSafe(input, output); | 161 GCMNetworkChannel::Base64EncodeURLSafe(input, output); |
162 } | 162 } |
163 | 163 |
164 static bool Base64DecodeURLSafe(const std::string& input, | 164 static bool Base64DecodeURLSafe(const std::string& input, |
165 std::string* output) { | 165 std::string* output) { |
166 return GCMNetworkChannel::Base64DecodeURLSafe(input, output); | 166 return GCMNetworkChannel::Base64DecodeURLSafe(input, output); |
167 } | 167 } |
168 | 168 |
169 virtual void OnNetworkChannelStateChanged( | 169 virtual void OnNetworkChannelStateChanged( |
170 InvalidatorState invalidator_state) OVERRIDE { | 170 InvalidatorState invalidator_state) override { |
171 last_invalidator_state_ = invalidator_state; | 171 last_invalidator_state_ = invalidator_state; |
172 } | 172 } |
173 | 173 |
174 void OnIncomingMessage(std::string incoming_message) { | 174 void OnIncomingMessage(std::string incoming_message) { |
175 } | 175 } |
176 | 176 |
177 GCMNetworkChannel* network_channel() { | 177 GCMNetworkChannel* network_channel() { |
178 return gcm_network_channel_.get(); | 178 return gcm_network_channel_.get(); |
179 } | 179 } |
180 | 180 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 delegate()->request_token_callback.Run( | 505 delegate()->request_token_callback.Run( |
506 GoogleServiceAuthError::AuthErrorNone(), "access.token"); | 506 GoogleServiceAuthError::AuthErrorNone(), "access.token"); |
507 RunLoopUntilIdle(); | 507 RunLoopUntilIdle(); |
508 EXPECT_EQ(url_fetchers_created_count(), 3); | 508 EXPECT_EQ(url_fetchers_created_count(), 3); |
509 // Echo_token should be from second message. | 509 // Echo_token should be from second message. |
510 EXPECT_EQ("echo.token", get_last_echo_token()); | 510 EXPECT_EQ("echo.token", get_last_echo_token()); |
511 } | 511 } |
512 #endif | 512 #endif |
513 | 513 |
514 } // namespace syncer | 514 } // namespace syncer |
OLD | NEW |