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

Side by Side Diff: components/copresence/handlers/audio/audio_directive_handler_unittest.cc

Issue 665353002: Add AudioDirectiveHandler timed tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@audio_redesign
Patch Set: build fix. Created 6 years, 1 month 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 "components/copresence/handlers/audio/audio_directive_handler.h" 5 #include "components/copresence/handlers/audio/audio_directive_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/test/simple_test_tick_clock.h"
11 #include "base/timer/mock_timer.h"
12 #include "components/copresence/handlers/audio/tick_clock_ref_counted.h"
10 #include "components/copresence/mediums/audio/audio_manager.h" 13 #include "components/copresence/mediums/audio/audio_manager.h"
11 #include "components/copresence/test/audio_test_support.h" 14 #include "components/copresence/test/audio_test_support.h"
12 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
13 16
14 namespace copresence { 17 namespace copresence {
15 18
16 namespace { 19 namespace {
17 20
18 // Callback stubs to pass into the directive handler. 21 // Callback stubs to pass into the directive handler.
19 void DecodeSamples(AudioType, const std::string&) { 22 void DecodeSamples(AudioType, const std::string&) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 131
129 directive_handler_->RemoveInstructions("op_id2"); 132 directive_handler_->RemoveInstructions("op_id2");
130 EXPECT_FALSE(IsPlaying(INAUDIBLE)); 133 EXPECT_FALSE(IsPlaying(INAUDIBLE));
131 EXPECT_FALSE(IsRecording(AUDIBLE)); 134 EXPECT_FALSE(IsRecording(AUDIBLE));
132 EXPECT_TRUE(IsRecording(INAUDIBLE)); 135 EXPECT_TRUE(IsRecording(INAUDIBLE));
133 136
134 directive_handler_->RemoveInstructions("op_id3"); 137 directive_handler_->RemoveInstructions("op_id3");
135 EXPECT_FALSE(IsRecording(INAUDIBLE)); 138 EXPECT_FALSE(IsRecording(INAUDIBLE));
136 } 139 }
137 140
141 TEST_F(AudioDirectiveHandlerTest, Timed) {
142 scoped_ptr<base::SimpleTestTickClock> clock(new base::SimpleTestTickClock());
143 base::SimpleTestTickClock* clock_ptr = clock.get();
144
145 scoped_refptr<TickClockRefCounted> clock_proxy =
146 new TickClockRefCounted(clock.Pass());
147 directive_handler_->set_clock_for_testing(clock_proxy);
148
149 scoped_ptr<base::Timer> timer(new base::MockTimer(false, false));
150 base::MockTimer* timer_ptr = static_cast<base::MockTimer*>(timer.get());
151 directive_handler_->set_timer_for_testing(timer.Pass());
152
153 const base::TimeDelta kTtl1 = base::TimeDelta::FromMilliseconds(1337);
154 directive_handler_->AddInstruction(
155 CreateTransmitInstruction("token", true), "op_id1", kTtl1);
156
157 const base::TimeDelta kTtl2 = base::TimeDelta::FromMilliseconds(1338);
158 directive_handler_->AddInstruction(
159 CreateTransmitInstruction("token", false), "op_id1", kTtl2);
160
161 const base::TimeDelta kTtl3 = base::TimeDelta::FromMilliseconds(1336);
162 directive_handler_->AddInstruction(
163 CreateReceiveInstruction(false), "op_id3", kTtl3);
164 EXPECT_TRUE(IsPlaying(AUDIBLE));
165 EXPECT_TRUE(IsPlaying(INAUDIBLE));
166 EXPECT_FALSE(IsRecording(AUDIBLE));
167 EXPECT_TRUE(IsRecording(INAUDIBLE));
168
169 // We *have* to call an operation on the directive handler after we advance
170 // time to trigger the next set of operations, so ensure that after calling
171 // advance, we are also calling another operation.
172 clock_ptr->Advance(kTtl3 + base::TimeDelta::FromMilliseconds(1));
173
174 // We are now at base + 1337ms.
175 // This instruction expires at base + (1337 + 1337 = 2674)
176 directive_handler_->AddInstruction(
177 CreateReceiveInstruction(true), "op_id4", kTtl1);
178 EXPECT_TRUE(IsPlaying(AUDIBLE));
179 EXPECT_TRUE(IsPlaying(INAUDIBLE));
180 EXPECT_TRUE(IsRecording(AUDIBLE));
181 EXPECT_FALSE(IsRecording(INAUDIBLE));
182
183 clock_ptr->Advance(base::TimeDelta::FromMilliseconds(1));
184
185 // We are now at base + 1338ms.
186 timer_ptr->Fire();
187 EXPECT_FALSE(IsPlaying(AUDIBLE));
188 EXPECT_TRUE(IsPlaying(INAUDIBLE));
189 EXPECT_TRUE(IsRecording(AUDIBLE));
190
191 clock_ptr->Advance(base::TimeDelta::FromMilliseconds(1));
192
193 // We are now at base + 1339ms.
194 timer_ptr->Fire();
195 EXPECT_FALSE(IsPlaying(INAUDIBLE));
196 EXPECT_TRUE(IsRecording(AUDIBLE));
197
198 clock_ptr->Advance(kTtl3);
199
200 // We are now at base + 2676ms.
201 timer_ptr->Fire();
202 EXPECT_FALSE(IsRecording(AUDIBLE));
203 }
204
138 // TODO(rkc): Write more tests that check more convoluted sequences of 205 // TODO(rkc): Write more tests that check more convoluted sequences of
139 // transmits/receives. 206 // transmits/receives.
140 // TODO(rkc): Write tests to move time forward and test functionality.
141 207
142 } // namespace copresence 208 } // namespace copresence
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698