| Index: components/copresence/handlers/audio/audio_directive_handler_unittest.cc
|
| diff --git a/components/copresence/handlers/audio/audio_directive_handler_unittest.cc b/components/copresence/handlers/audio/audio_directive_handler_unittest.cc
|
| index 0d5afd01dc04ae256af05311e3c1ecdefc287889..863d4a2ceb8860c146b2d663a1fd2906f81af927 100644
|
| --- a/components/copresence/handlers/audio/audio_directive_handler_unittest.cc
|
| +++ b/components/copresence/handlers/audio/audio_directive_handler_unittest.cc
|
| @@ -7,6 +7,9 @@
|
| #include "base/bind.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/message_loop/message_loop.h"
|
| +#include "base/test/simple_test_tick_clock.h"
|
| +#include "base/timer/mock_timer.h"
|
| +#include "components/copresence/handlers/audio/tick_clock_ref_counted.h"
|
| #include "components/copresence/mediums/audio/audio_manager.h"
|
| #include "components/copresence/test/audio_test_support.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| @@ -144,8 +147,69 @@ TEST_F(AudioDirectiveHandlerTest, Basic) {
|
| EXPECT_FALSE(IsRecording(INAUDIBLE));
|
| }
|
|
|
| +TEST_F(AudioDirectiveHandlerTest, Timed) {
|
| + base::SimpleTestTickClock* clock = new base::SimpleTestTickClock();
|
| + scoped_refptr<TickClockRefCounted> clock_proxy =
|
| + new TickClockRefCounted(clock);
|
| + directive_handler_->set_clock_for_testing(clock_proxy);
|
| +
|
| + scoped_ptr<base::Timer> timer(new base::MockTimer(false, false));
|
| + base::MockTimer* timer_ptr = static_cast<base::MockTimer*>(timer.get());
|
| + directive_handler_->set_timer_for_testing(timer.Pass());
|
| +
|
| + const base::TimeDelta kTtl1 = base::TimeDelta::FromMilliseconds(1337);
|
| + directive_handler_->AddInstruction(
|
| + CreateTransmitInstruction("token", true), "op_id1", kTtl1);
|
| +
|
| + const base::TimeDelta kTtl2 = base::TimeDelta::FromMilliseconds(1338);
|
| + directive_handler_->AddInstruction(
|
| + CreateTransmitInstruction("token", false), "op_id1", kTtl2);
|
| +
|
| + const base::TimeDelta kTtl3 = base::TimeDelta::FromMilliseconds(1336);
|
| + directive_handler_->AddInstruction(
|
| + CreateReceiveInstruction(false), "op_id3", kTtl3);
|
| + EXPECT_TRUE(IsPlaying(AUDIBLE));
|
| + EXPECT_TRUE(IsPlaying(INAUDIBLE));
|
| + EXPECT_FALSE(IsRecording(AUDIBLE));
|
| + EXPECT_TRUE(IsRecording(INAUDIBLE));
|
| +
|
| + // We *have* to call an operation on the directive handler after we advance
|
| + // time to trigger the next set of operations, so ensure that after calling
|
| + // advance, we are also calling another operation.
|
| + clock->Advance(kTtl3 + base::TimeDelta::FromMilliseconds(1));
|
| +
|
| + // We are now at base + 1337ms.
|
| + // This instruction expires at base + (1337 + 1337 = 2674)
|
| + directive_handler_->AddInstruction(
|
| + CreateReceiveInstruction(true), "op_id4", kTtl1);
|
| + EXPECT_TRUE(IsPlaying(AUDIBLE));
|
| + EXPECT_TRUE(IsPlaying(INAUDIBLE));
|
| + EXPECT_TRUE(IsRecording(AUDIBLE));
|
| + EXPECT_FALSE(IsRecording(INAUDIBLE));
|
| +
|
| + clock->Advance(base::TimeDelta::FromMilliseconds(1));
|
| +
|
| + // We are now at base + 1338ms.
|
| + timer_ptr->Fire();
|
| + EXPECT_FALSE(IsPlaying(AUDIBLE));
|
| + EXPECT_TRUE(IsPlaying(INAUDIBLE));
|
| + EXPECT_TRUE(IsRecording(AUDIBLE));
|
| +
|
| + clock->Advance(base::TimeDelta::FromMilliseconds(1));
|
| +
|
| + // We are now at base + 1339ms.
|
| + timer_ptr->Fire();
|
| + EXPECT_FALSE(IsPlaying(INAUDIBLE));
|
| + EXPECT_TRUE(IsRecording(AUDIBLE));
|
| +
|
| + clock->Advance(kTtl3);
|
| +
|
| + // We are now at base + 2676ms.
|
| + timer_ptr->Fire();
|
| + EXPECT_FALSE(IsRecording(AUDIBLE));
|
| +}
|
| +
|
| // TODO(rkc): Write more tests that check more convoluted sequences of
|
| // transmits/receives.
|
| -// TODO(rkc): Write tests to move time forward and test functionality.
|
|
|
| } // namespace copresence
|
|
|