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