| 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 <stdint.h> |
| 6 |
| 5 #include <string> | 7 #include <string> |
| 6 #include <vector> | 8 #include <vector> |
| 7 | 9 |
| 8 #include "base/bind.h" | 10 #include "base/bind.h" |
| 9 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 10 #include "components/audio_modem/test/stub_whispernet_client.h" | 12 #include "components/audio_modem/test/stub_whispernet_client.h" |
| 11 #include "components/copresence/handlers/audio/audio_directive_handler.h" | 13 #include "components/copresence/handlers/audio/audio_directive_handler.h" |
| 12 #include "components/copresence/handlers/directive_handler_impl.h" | 14 #include "components/copresence/handlers/directive_handler_impl.h" |
| 13 #include "components/copresence/proto/data.pb.h" | 15 #include "components/copresence/proto/data.pb.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 15 | 17 |
| 16 using testing::ElementsAre; | 18 using testing::ElementsAre; |
| 17 using testing::IsEmpty; | 19 using testing::IsEmpty; |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 const int64 kMaxUnlabeledTtl = 60000; // 1 minute | 23 const int64_t kMaxUnlabeledTtl = 60000; // 1 minute |
| 22 const int64 kExcessiveUnlabeledTtl = 120000; // 2 minutes | 24 const int64_t kExcessiveUnlabeledTtl = 120000; // 2 minutes |
| 23 const int64 kDefaultTtl = 600000; // 10 minutes | 25 const int64_t kDefaultTtl = 600000; // 10 minutes |
| 24 | 26 |
| 25 } // namespace | 27 } // namespace |
| 26 | 28 |
| 27 namespace copresence { | 29 namespace copresence { |
| 28 | 30 |
| 29 const Directive CreateDirective(const std::string& publish_id, | 31 const Directive CreateDirective(const std::string& publish_id, |
| 30 const std::string& subscribe_id, | 32 const std::string& subscribe_id, |
| 31 const std::string& token, | 33 const std::string& token, |
| 32 int64 ttl_ms) { | 34 int64_t ttl_ms) { |
| 33 Directive directive; | 35 Directive directive; |
| 34 directive.set_instruction_type(TOKEN); | 36 directive.set_instruction_type(TOKEN); |
| 35 directive.set_published_message_id(publish_id); | 37 directive.set_published_message_id(publish_id); |
| 36 directive.set_subscription_id(subscribe_id); | 38 directive.set_subscription_id(subscribe_id); |
| 37 directive.set_ttl_millis(ttl_ms); | 39 directive.set_ttl_millis(ttl_ms); |
| 38 | 40 |
| 39 TokenInstruction* instruction = new TokenInstruction; | 41 TokenInstruction* instruction = new TokenInstruction; |
| 40 instruction->set_token_id(token); | 42 instruction->set_token_id(token); |
| 41 instruction->set_medium(AUDIO_ULTRASOUND_PASSBAND); | 43 instruction->set_medium(AUDIO_ULTRASOUND_PASSBAND); |
| 42 directive.set_allocated_token_instruction(instruction); | 44 directive.set_allocated_token_instruction(instruction); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 78 |
| 77 bool IsPlayingTokenHeard(audio_modem::AudioType /* type */) const override { | 79 bool IsPlayingTokenHeard(audio_modem::AudioType /* type */) const override { |
| 78 NOTREACHED(); | 80 NOTREACHED(); |
| 79 return false; | 81 return false; |
| 80 } | 82 } |
| 81 | 83 |
| 82 const std::vector<std::string>& added_tokens() const { | 84 const std::vector<std::string>& added_tokens() const { |
| 83 return added_tokens_; | 85 return added_tokens_; |
| 84 } | 86 } |
| 85 | 87 |
| 86 const std::vector<int64>& added_ttls() const { | 88 const std::vector<int64_t>& added_ttls() const { return added_ttls_; } |
| 87 return added_ttls_; | |
| 88 } | |
| 89 | 89 |
| 90 const std::vector<std::string>& removed_operations() const { | 90 const std::vector<std::string>& removed_operations() const { |
| 91 return removed_operations_; | 91 return removed_operations_; |
| 92 } | 92 } |
| 93 | 93 |
| 94 private: | 94 private: |
| 95 std::vector<std::string> added_tokens_; | 95 std::vector<std::string> added_tokens_; |
| 96 std::vector<int64> added_ttls_; | 96 std::vector<int64_t> added_ttls_; |
| 97 std::vector<std::string> removed_operations_; | 97 std::vector<std::string> removed_operations_; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 class DirectiveHandlerTest : public testing::Test { | 100 class DirectiveHandlerTest : public testing::Test { |
| 101 public: | 101 public: |
| 102 DirectiveHandlerTest() | 102 DirectiveHandlerTest() |
| 103 : whispernet_client_(new audio_modem::StubWhispernetClient), | 103 : whispernet_client_(new audio_modem::StubWhispernetClient), |
| 104 audio_handler_(new FakeAudioDirectiveHandler), | 104 audio_handler_(new FakeAudioDirectiveHandler), |
| 105 directive_handler_( | 105 directive_handler_( |
| 106 make_scoped_ptr<AudioDirectiveHandler>(audio_handler_)) {} | 106 make_scoped_ptr<AudioDirectiveHandler>(audio_handler_)) {} |
| (...skipping 30 matching lines...) Expand all Loading... |
| 137 | 137 |
| 138 StartDirectiveHandler(); | 138 StartDirectiveHandler(); |
| 139 directive_handler_.RemoveDirectives("id 3"); | 139 directive_handler_.RemoveDirectives("id 3"); |
| 140 | 140 |
| 141 EXPECT_THAT(audio_handler_->added_tokens(), ElementsAre("token 3")); | 141 EXPECT_THAT(audio_handler_->added_tokens(), ElementsAre("token 3")); |
| 142 EXPECT_THAT(audio_handler_->added_ttls(), ElementsAre(kDefaultTtl)); | 142 EXPECT_THAT(audio_handler_->added_ttls(), ElementsAre(kDefaultTtl)); |
| 143 EXPECT_THAT(audio_handler_->removed_operations(), ElementsAre("id 3")); | 143 EXPECT_THAT(audio_handler_->removed_operations(), ElementsAre("id 3")); |
| 144 } | 144 } |
| 145 | 145 |
| 146 } // namespace copresence | 146 } // namespace copresence |
| OLD | NEW |