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

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

Issue 824593003: Revert of Adding CopresenceState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 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 3af0859f74559d24fcd8984b1a33560148106b70..4a64e6d633edd7d8fb481fa20e6b49f317136b00 100644
--- a/components/copresence/handlers/audio/audio_directive_handler_unittest.cc
+++ b/components/copresence/handlers/audio/audio_directive_handler_unittest.cc
@@ -1,9 +1,6 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
-#include <string>
-#include <vector>
#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
@@ -18,22 +15,6 @@
#include "testing/gtest/include/gtest/gtest.h"
namespace copresence {
-
-namespace {
-
-const Directive CreateDirective(TokenInstructionType type,
- bool audible,
- int64 ttl) {
- Directive directive;
- directive.mutable_token_instruction()->set_token_instruction_type(type);
- directive.mutable_token_instruction()->set_token_id("token");
- directive.mutable_token_instruction()->set_medium(audible ?
- AUDIO_AUDIBLE_DTMF : AUDIO_ULTRASOUND_PASSBAND);
- directive.set_ttl_millis(ttl);
- return directive;
-}
-
-} // namespace
class AudioManagerStub final : public AudioManager {
public:
@@ -70,8 +51,6 @@
clock_ptr_ = new base::SimpleTestTickClock;
directive_handler_.reset(new AudioDirectiveHandlerImpl(
- base::Bind(&AudioDirectiveHandlerTest::GetDirectiveUpdates,
- base::Unretained(this)),
make_scoped_ptr<AudioManager>(manager_ptr_),
make_scoped_ptr<base::Timer>(timer_ptr_),
make_scoped_refptr(new TickClockRefCounted(clock_ptr_))));
@@ -80,8 +59,22 @@
~AudioDirectiveHandlerTest() override {}
protected:
- const std::vector<Directive>& current_directives() {
- return current_directives_;
+ TokenInstruction CreateTransmitInstruction(const std::string& token,
+ bool audible) {
+ TokenInstruction instruction;
+ instruction.set_token_instruction_type(TRANSMIT);
+ instruction.set_token_id(token);
+ instruction.set_medium(audible ? AUDIO_AUDIBLE_DTMF
+ : AUDIO_ULTRASOUND_PASSBAND);
+ return instruction;
+ }
+
+ TokenInstruction CreateReceiveInstruction(bool audible) {
+ TokenInstruction instruction;
+ instruction.set_token_instruction_type(RECEIVE);
+ instruction.set_medium(audible ? AUDIO_AUDIBLE_DTMF
+ : AUDIO_ULTRASOUND_PASSBAND);
+ return instruction;
}
bool IsPlaying(AudioType type) { return manager_ptr_->IsPlaying(type); }
@@ -94,35 +87,29 @@
base::MessageLoop message_loop_;
scoped_ptr<AudioDirectiveHandler> directive_handler_;
- std::vector<Directive> current_directives_;
-
// Unowned.
AudioManagerStub* manager_ptr_;
base::MockTimer* timer_ptr_;
base::SimpleTestTickClock* clock_ptr_;
private:
- void GetDirectiveUpdates(const std::vector<Directive>& current_directives) {
- current_directives_ = current_directives;
- }
-
DISALLOW_COPY_AND_ASSIGN(AudioDirectiveHandlerTest);
};
TEST_F(AudioDirectiveHandlerTest, Basic) {
- const int64 kTtl = 10;
- directive_handler_->AddInstruction(CreateDirective(TRANSMIT, true, kTtl),
- "op_id1");
- directive_handler_->AddInstruction(CreateDirective(TRANSMIT, false, kTtl),
- "op_id1");
- directive_handler_->AddInstruction(CreateDirective(TRANSMIT, false, kTtl),
- "op_id2");
- directive_handler_->AddInstruction(CreateDirective(RECEIVE, false, kTtl),
- "op_id1");
- directive_handler_->AddInstruction(CreateDirective(RECEIVE, true, kTtl),
- "op_id2");
- directive_handler_->AddInstruction(CreateDirective(RECEIVE, false, kTtl),
- "op_id3");
+ const base::TimeDelta kTtl = base::TimeDelta::FromMilliseconds(9999);
+ directive_handler_->AddInstruction(
+ CreateTransmitInstruction("token", true), "op_id1", kTtl);
+ directive_handler_->AddInstruction(
+ CreateTransmitInstruction("token", false), "op_id1", kTtl);
+ directive_handler_->AddInstruction(
+ CreateTransmitInstruction("token", false), "op_id2", kTtl);
+ directive_handler_->AddInstruction(
+ CreateReceiveInstruction(false), "op_id1", kTtl);
+ directive_handler_->AddInstruction(
+ CreateReceiveInstruction(true), "op_id2", kTtl);
+ directive_handler_->AddInstruction(
+ CreateReceiveInstruction(false), "op_id3", kTtl);
EXPECT_TRUE(IsPlaying(AUDIBLE));
EXPECT_TRUE(IsPlaying(INAUDIBLE));
@@ -145,47 +132,54 @@
}
TEST_F(AudioDirectiveHandlerTest, Timed) {
- directive_handler_->AddInstruction(CreateDirective(TRANSMIT, true, 6),
- "op_id1");
- directive_handler_->AddInstruction(CreateDirective(TRANSMIT, false, 8),
- "op_id1");
- directive_handler_->AddInstruction(CreateDirective(RECEIVE, false, 4),
- "op_id3");
+ 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));
- // Every time we advance and a directive expires, the timer should fire also.
- clock_ptr_->Advance(base::TimeDelta::FromMilliseconds(5));
- timer_ptr_->Fire();
+ // 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_ptr_->Advance(kTtl3 + base::TimeDelta::FromMilliseconds(1));
- // We are now at +5ms. This instruction expires at +10ms.
- directive_handler_->AddInstruction(CreateDirective(RECEIVE, true, 5),
- "op_id4");
+ // 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));
- // Advance to +7ms.
- const base::TimeDelta twoMs = base::TimeDelta::FromMilliseconds(2);
- clock_ptr_->Advance(twoMs);
+ clock_ptr_->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));
- // Advance to +9ms.
- clock_ptr_->Advance(twoMs);
+ clock_ptr_->Advance(base::TimeDelta::FromMilliseconds(1));
+
+ // We are now at base + 1339ms.
timer_ptr_->Fire();
EXPECT_FALSE(IsPlaying(INAUDIBLE));
EXPECT_TRUE(IsRecording(AUDIBLE));
- // Advance to +11ms.
- clock_ptr_->Advance(twoMs);
+ clock_ptr_->Advance(kTtl3);
+
+ // We are now at base + 2676ms.
timer_ptr_->Fire();
EXPECT_FALSE(IsRecording(AUDIBLE));
}

Powered by Google App Engine
This is Rietveld 408576698