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 "components/copresence/rpc/rpc_handler.h" | 5 #include "components/copresence/rpc/rpc_handler.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "components/copresence/copresence_state_impl.h" | |
16 #include "components/copresence/handlers/directive_handler.h" | 15 #include "components/copresence/handlers/directive_handler.h" |
17 #include "components/copresence/mediums/audio/audio_manager.h" | 16 #include "components/copresence/mediums/audio/audio_manager.h" |
18 #include "components/copresence/proto/data.pb.h" | 17 #include "components/copresence/proto/data.pb.h" |
19 #include "components/copresence/proto/enums.pb.h" | 18 #include "components/copresence/proto/enums.pb.h" |
20 #include "components/copresence/proto/rpcs.pb.h" | 19 #include "components/copresence/proto/rpcs.pb.h" |
21 #include "components/copresence/test/fake_directive_handler.h" | 20 #include "components/copresence/test/fake_directive_handler.h" |
22 #include "components/copresence/test/stub_whispernet_client.h" | 21 #include "components/copresence/test/stub_whispernet_client.h" |
23 #include "net/http/http_status_code.h" | 22 #include "net/http/http_status_code.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
25 | 24 |
(...skipping 18 matching lines...) Expand all Loading... |
44 message_proto->add_subscription_id(subscription_id); | 43 message_proto->add_subscription_id(subscription_id); |
45 } | 44 } |
46 } | 45 } |
47 | 46 |
48 } // namespace | 47 } // namespace |
49 | 48 |
50 class RpcHandlerTest : public testing::Test, public CopresenceDelegate { | 49 class RpcHandlerTest : public testing::Test, public CopresenceDelegate { |
51 public: | 50 public: |
52 RpcHandlerTest() | 51 RpcHandlerTest() |
53 : whispernet_client_(new StubWhispernetClient), | 52 : whispernet_client_(new StubWhispernetClient), |
54 // TODO(ckehoe): Use a FakeCopresenceState here | |
55 // and test that it gets called correctly. | |
56 state_(new CopresenceStateImpl), | |
57 rpc_handler_(this, | 53 rpc_handler_(this, |
58 state_.get(), | |
59 &directive_handler_, | 54 &directive_handler_, |
60 nullptr, | 55 nullptr, |
61 base::Bind(&RpcHandlerTest::CaptureHttpPost, | 56 base::Bind(&RpcHandlerTest::CaptureHttpPost, |
62 base::Unretained(this))), | 57 base::Unretained(this))), |
63 status_(SUCCESS) {} | 58 status_(SUCCESS) {} |
64 | 59 |
65 // CopresenceDelegate implementation | 60 // CopresenceDelegate implementation |
66 | 61 |
67 void HandleMessages(const std::string& /* app_id */, | 62 void HandleMessages(const std::string& /* app_id */, |
68 const std::string& subscription_id, | 63 const std::string& subscription_id, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 147 |
153 bool TokenIsInvalid(const std::string& token) { | 148 bool TokenIsInvalid(const std::string& token) { |
154 return rpc_handler_.invalid_audio_token_cache_.HasKey(token); | 149 return rpc_handler_.invalid_audio_token_cache_.HasKey(token); |
155 } | 150 } |
156 | 151 |
157 // For rpc_handler_.invalid_audio_token_cache_ | 152 // For rpc_handler_.invalid_audio_token_cache_ |
158 base::MessageLoop message_loop_; | 153 base::MessageLoop message_loop_; |
159 | 154 |
160 scoped_ptr<WhispernetClient> whispernet_client_; | 155 scoped_ptr<WhispernetClient> whispernet_client_; |
161 FakeDirectiveHandler directive_handler_; | 156 FakeDirectiveHandler directive_handler_; |
162 scoped_ptr<CopresenceStateImpl> state_; | |
163 RpcHandler rpc_handler_; | 157 RpcHandler rpc_handler_; |
164 | 158 |
165 CopresenceStatus status_; | 159 CopresenceStatus status_; |
166 std::string rpc_name_; | 160 std::string rpc_name_; |
167 std::string api_key_; | 161 std::string api_key_; |
168 std::string auth_token_; | 162 std::string auth_token_; |
169 ScopedVector<MessageLite> request_protos_; | 163 ScopedVector<MessageLite> request_protos_; |
170 std::map<std::string, std::vector<std::string>> messages_by_subscription_; | 164 std::map<std::string, std::vector<std::string>> messages_by_subscription_; |
171 | 165 |
172 private: | 166 private: |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 EXPECT_TRUE(TokenIsInvalid("bad token")); | 349 EXPECT_TRUE(TokenIsInvalid("bad token")); |
356 EXPECT_THAT(messages_by_subscription_["Subscription 1"], | 350 EXPECT_THAT(messages_by_subscription_["Subscription 1"], |
357 ElementsAre("Message A", "Message C")); | 351 ElementsAre("Message A", "Message C")); |
358 EXPECT_THAT(messages_by_subscription_["Subscription 2"], | 352 EXPECT_THAT(messages_by_subscription_["Subscription 2"], |
359 ElementsAre("Message B", "Message C")); | 353 ElementsAre("Message B", "Message C")); |
360 EXPECT_THAT(directive_handler_.added_directives(), | 354 EXPECT_THAT(directive_handler_.added_directives(), |
361 ElementsAre("Subscription 1", "Subscription 2")); | 355 ElementsAre("Subscription 1", "Subscription 2")); |
362 } | 356 } |
363 | 357 |
364 } // namespace copresence | 358 } // namespace copresence |
OLD | NEW |