Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: components/copresence/handlers/directive_handler_unittest.cc

Issue 764673003: Adding CopresenceState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing overzealous DCHECK Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string>
6 #include <vector>
7
8 #include "base/bind.h"
5 #include "base/time/time.h" 9 #include "base/time/time.h"
6 #include "components/copresence/handlers/audio/audio_directive_handler.h" 10 #include "components/copresence/handlers/audio/audio_directive_handler.h"
7 #include "components/copresence/handlers/directive_handler_impl.h" 11 #include "components/copresence/handlers/directive_handler_impl.h"
8 #include "components/copresence/proto/data.pb.h" 12 #include "components/copresence/proto/data.pb.h"
9 #include "components/copresence/test/stub_whispernet_client.h" 13 #include "components/copresence/test/stub_whispernet_client.h"
10 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
11 15
12 using testing::ElementsAre; 16 using testing::ElementsAre;
13 using testing::IsEmpty; 17 using testing::IsEmpty;
14 18
15 namespace {
xiyuan 2014/12/18 18:10:52 nit: keep the anonymous namespace?
Charlie 2014/12/19 03:53:33 Done.
16
17 const int64 kMaxUnlabeledTtl = 60000; // 1 minute 19 const int64 kMaxUnlabeledTtl = 60000; // 1 minute
18 const int64 kExcessiveUnlabeledTtl = 120000; // 2 minutes 20 const int64 kExcessiveUnlabeledTtl = 120000; // 2 minutes
19 const int64 kDefaultTtl = 600000; // 10 minutes 21 const int64 kDefaultTtl = 600000; // 10 minutes
20 22
21 } // namespace
22
23 namespace copresence { 23 namespace copresence {
24 24
25 Directive CreateDirective(const std::string& publish_id, 25 void IgnoreDirectiveUpdates(const std::vector<Directive>& /* directives */) {}
26 const std::string& subscribe_id, 26
27 const std::string& token, 27 const Directive CreateDirective(const std::string& publish_id,
28 int64 ttl_ms) { 28 const std::string& subscribe_id,
29 const std::string& token,
30 int64 ttl_ms) {
29 Directive directive; 31 Directive directive;
30 directive.set_instruction_type(TOKEN); 32 directive.set_instruction_type(TOKEN);
31 directive.set_published_message_id(publish_id); 33 directive.set_published_message_id(publish_id);
32 directive.set_subscription_id(subscribe_id); 34 directive.set_subscription_id(subscribe_id);
33 directive.set_ttl_millis(ttl_ms); 35 directive.set_ttl_millis(ttl_ms);
34 36
35 TokenInstruction* instruction = new TokenInstruction; 37 TokenInstruction* instruction = new TokenInstruction;
36 instruction->set_token_id(token); 38 instruction->set_token_id(token);
37 instruction->set_medium(AUDIO_ULTRASOUND_PASSBAND); 39 instruction->set_medium(AUDIO_ULTRASOUND_PASSBAND);
38 directive.set_allocated_token_instruction(instruction); 40 directive.set_allocated_token_instruction(instruction);
39 41
40 return directive; 42 return directive;
41 } 43 }
42 44
43 Directive CreateDirective(const std::string& publish_id, 45 const Directive CreateDirective(const std::string& publish_id,
44 const std::string& subscribe_id, 46 const std::string& subscribe_id,
45 const std::string& token) { 47 const std::string& token) {
46 return CreateDirective(publish_id, subscribe_id, token, kDefaultTtl); 48 return CreateDirective(publish_id, subscribe_id, token, kDefaultTtl);
47 } 49 }
48 50
49 class FakeAudioDirectiveHandler final : public AudioDirectiveHandler { 51 class FakeAudioDirectiveHandler final : public AudioDirectiveHandler {
50 public: 52 public:
51 FakeAudioDirectiveHandler() {} 53 FakeAudioDirectiveHandler() {}
52 54
53 void Initialize(WhispernetClient* /* whispernet_client */, 55 void Initialize(WhispernetClient* /* whispernet_client */,
54 const TokensCallback& /* tokens_cb */) override {} 56 const TokensCallback& /* tokens_cb */) override {}
55 57
56 void AddInstruction(const TokenInstruction& instruction, 58 void AddInstruction(const Directive& directive,
57 const std::string& /* op_id */, 59 const std::string& /* op_id */) override {
58 base::TimeDelta ttl) override { 60 added_tokens_.push_back(directive.token_instruction().token_id());
59 added_tokens_.push_back(instruction.token_id()); 61 added_ttls_.push_back(directive.ttl_millis());
60 added_ttls_.push_back(ttl.InMilliseconds());
61 } 62 }
62 63
63 void RemoveInstructions(const std::string& op_id) override { 64 void RemoveInstructions(const std::string& op_id) override {
64 removed_operations_.push_back(op_id); 65 removed_operations_.push_back(op_id);
65 } 66 }
66 67
67 const std::string PlayingToken(AudioType /* type */) const override { 68 const std::string PlayingToken(AudioType /* type */) const override {
68 NOTREACHED(); 69 NOTREACHED();
69 return ""; 70 return "";
70 } 71 }
(...skipping 20 matching lines...) Expand all
91 std::vector<int64> added_ttls_; 92 std::vector<int64> added_ttls_;
92 std::vector<std::string> removed_operations_; 93 std::vector<std::string> removed_operations_;
93 }; 94 };
94 95
95 class DirectiveHandlerTest : public testing::Test { 96 class DirectiveHandlerTest : public testing::Test {
96 public: 97 public:
97 DirectiveHandlerTest() 98 DirectiveHandlerTest()
98 : whispernet_client_(new StubWhispernetClient), 99 : whispernet_client_(new StubWhispernetClient),
99 audio_handler_(new FakeAudioDirectiveHandler), 100 audio_handler_(new FakeAudioDirectiveHandler),
100 directive_handler_( 101 directive_handler_(
102 base::Bind(&IgnoreDirectiveUpdates),
101 make_scoped_ptr<AudioDirectiveHandler>(audio_handler_)) {} 103 make_scoped_ptr<AudioDirectiveHandler>(audio_handler_)) {}
102 104
103 protected: 105 protected:
104 void StartDirectiveHandler() { 106 void StartDirectiveHandler() {
105 directive_handler_.Start(whispernet_client_.get(), TokensCallback()); 107 directive_handler_.Start(whispernet_client_.get(), TokensCallback());
106 } 108 }
107 109
108 scoped_ptr<WhispernetClient> whispernet_client_; 110 scoped_ptr<WhispernetClient> whispernet_client_;
109 FakeAudioDirectiveHandler* audio_handler_; 111 FakeAudioDirectiveHandler* audio_handler_;
110 DirectiveHandlerImpl directive_handler_; 112 DirectiveHandlerImpl directive_handler_;
(...skipping 20 matching lines...) Expand all
131 133
132 StartDirectiveHandler(); 134 StartDirectiveHandler();
133 directive_handler_.RemoveDirectives("id 3"); 135 directive_handler_.RemoveDirectives("id 3");
134 136
135 EXPECT_THAT(audio_handler_->added_tokens(), ElementsAre("token 3")); 137 EXPECT_THAT(audio_handler_->added_tokens(), ElementsAre("token 3"));
136 EXPECT_THAT(audio_handler_->added_ttls(), ElementsAre(kDefaultTtl)); 138 EXPECT_THAT(audio_handler_->added_ttls(), ElementsAre(kDefaultTtl));
137 EXPECT_THAT(audio_handler_->removed_operations(), ElementsAre("id 3")); 139 EXPECT_THAT(audio_handler_->removed_operations(), ElementsAre("id 3"));
138 } 140 }
139 141
140 } // namespace copresence 142 } // namespace copresence
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698