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

Unified Diff: components/copresence/handlers/audio/audio_directive_handler_unittest.cc

Issue 670623002: Change base::TickClock to a ref counted class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@audio_redesign
Patch Set: y Created 6 years, 2 months 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 side-by-side diff with in-line comments
Download patch
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 93b352927a76ac8ef7c81b41f5c80685524a7b4e..bb847c38a439dbc27dea7bebc9a330ecef1d715f 100644
--- a/components/copresence/handlers/audio/audio_directive_handler_unittest.cc
+++ b/components/copresence/handlers/audio/audio_directive_handler_unittest.cc
@@ -7,6 +7,8 @@
#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/mediums/audio/audio_manager.h"
#include "components/copresence/test/audio_test_support.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -112,8 +114,68 @@ TEST_F(AudioDirectiveHandlerTest, Basic) {
EXPECT_FALSE(IsRecording(INAUDIBLE));
}
+TEST_F(AudioDirectiveHandlerTest, Timed) {
+ scoped_refptr<base::SimpleTestTickClock> clock =
+ new base::SimpleTestTickClock;
+ directive_handler_->set_clock_for_testing(clock);
+
+ 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

Powered by Google App Engine
This is Rietveld 408576698