| 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 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 // TODO(ckehoe): Make DirectiveHandler an interface. | 46 // TODO(ckehoe): Make DirectiveHandler an interface. |
| 47 class FakeDirectiveHandler final : public DirectiveHandler { | 47 class FakeDirectiveHandler final : public DirectiveHandler { |
| 48 public: | 48 public: |
| 49 FakeDirectiveHandler() {} | 49 FakeDirectiveHandler() {} |
| 50 | 50 |
| 51 const std::vector<std::string>& added_directives() const { | 51 const std::vector<std::string>& added_directives() const { |
| 52 return added_directives_; | 52 return added_directives_; |
| 53 } | 53 } |
| 54 | 54 |
| 55 void Start(WhispernetClient* /* whispernet_client */) override { | 55 void Start(WhispernetClient* /* whispernet_client */, |
| 56 const TokensCallback& /* tokens_cb */) override { |
| 56 NOTREACHED(); | 57 NOTREACHED(); |
| 57 } | 58 } |
| 58 | 59 |
| 59 void AddDirective(const Directive& directive) override { | 60 void AddDirective(const Directive& directive) override { |
| 60 added_directives_.push_back(directive.subscription_id()); | 61 added_directives_.push_back(directive.subscription_id()); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void RemoveDirectives(const std::string& op_id) override { | 64 void RemoveDirectives(const std::string& op_id) override { |
| 64 NOTREACHED(); | 65 NOTREACHED(); |
| 65 } | 66 } |
| 66 | 67 |
| 67 const std::string GetCurrentAudioToken(AudioType type) const override { | 68 const std::string GetCurrentAudioToken(AudioType type) const override { |
| 68 return type == AUDIBLE ? "current audible" : "current inaudible"; | 69 return type == AUDIBLE ? "current audible" : "current inaudible"; |
| 69 } | 70 } |
| 70 | 71 |
| 72 bool IsAudioTokenHeard(AudioType type) const override { return true; } |
| 73 |
| 71 private: | 74 private: |
| 72 std::vector<std::string> added_directives_; | 75 std::vector<std::string> added_directives_; |
| 73 | 76 |
| 74 DISALLOW_COPY_AND_ASSIGN(FakeDirectiveHandler); | 77 DISALLOW_COPY_AND_ASSIGN(FakeDirectiveHandler); |
| 75 }; | 78 }; |
| 76 | 79 |
| 77 } // namespace | 80 } // namespace |
| 78 | 81 |
| 79 class RpcHandlerTest : public testing::Test, public CopresenceDelegate { | 82 class RpcHandlerTest : public testing::Test, public CopresenceDelegate { |
| 80 public: | 83 public: |
| 81 RpcHandlerTest() | 84 RpcHandlerTest() |
| 82 : whispernet_client_(new StubWhispernetClient), | 85 : whispernet_client_(new StubWhispernetClient), |
| 83 rpc_handler_(this, | 86 rpc_handler_(this, |
| 84 &directive_handler_, | 87 &directive_handler_, |
| 85 base::Bind(&RpcHandlerTest::CaptureHttpPost, | 88 base::Bind(&RpcHandlerTest::CaptureHttpPost, |
| 86 base::Unretained(this))), | 89 base::Unretained(this))), |
| 87 status_(SUCCESS) {} | 90 status_(SUCCESS) {} |
| 88 | 91 |
| 89 // CopresenceDelegate implementation | 92 // CopresenceDelegate implementation |
| 90 | 93 |
| 91 void HandleMessages(const std::string& /* app_id */, | 94 void HandleMessages(const std::string& /* app_id */, |
| 92 const std::string& subscription_id, | 95 const std::string& subscription_id, |
| 93 const std::vector<Message>& messages) override { | 96 const std::vector<Message>& messages) override { |
| 94 // app_id is unused for now, pending a server fix. | 97 // app_id is unused for now, pending a server fix. |
| 95 for (const Message& message : messages) { | 98 for (const Message& message : messages) { |
| 96 messages_by_subscription_[subscription_id].push_back(message.payload()); | 99 messages_by_subscription_[subscription_id].push_back(message.payload()); |
| 97 } | 100 } |
| 98 } | 101 } |
| 99 | 102 |
| 103 void HandleStatusUpdate(CopresenceStatus /* status */) override{}; |
| 104 |
| 100 net::URLRequestContextGetter* GetRequestContext() const override { | 105 net::URLRequestContextGetter* GetRequestContext() const override { |
| 101 return nullptr; | 106 return nullptr; |
| 102 } | 107 } |
| 103 | 108 |
| 104 const std::string GetPlatformVersionString() const override { | 109 const std::string GetPlatformVersionString() const override { |
| 105 return kChromeVersion; | 110 return kChromeVersion; |
| 106 } | 111 } |
| 107 | 112 |
| 108 const std::string GetAPIKey(const std::string& app_id) const override { | 113 const std::string GetAPIKey(const std::string& app_id) const override { |
| 109 return app_id + " API Key"; | 114 return app_id + " API Key"; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 EXPECT_THAT(messages_by_subscription_["Subscription 1"], | 288 EXPECT_THAT(messages_by_subscription_["Subscription 1"], |
| 284 ElementsAre("Message A", "Message C")); | 289 ElementsAre("Message A", "Message C")); |
| 285 EXPECT_THAT(messages_by_subscription_["Subscription 2"], | 290 EXPECT_THAT(messages_by_subscription_["Subscription 2"], |
| 286 ElementsAre("Message B", "Message C")); | 291 ElementsAre("Message B", "Message C")); |
| 287 | 292 |
| 288 EXPECT_THAT(directive_handler_.added_directives(), | 293 EXPECT_THAT(directive_handler_.added_directives(), |
| 289 ElementsAre("Subscription 1", "Subscription 2")); | 294 ElementsAre("Subscription 1", "Subscription 2")); |
| 290 } | 295 } |
| 291 | 296 |
| 292 } // namespace copresence | 297 } // namespace copresence |
| OLD | NEW |