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

Unified Diff: media/audio/win/audio_device_listener_win_unittest.cc

Issue 1248543002: Remove device change deduplication based on device id. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests. Created 5 years, 5 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
« no previous file with comments | « media/audio/win/audio_device_listener_win.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/win/audio_device_listener_win_unittest.cc
diff --git a/media/audio/win/audio_device_listener_win_unittest.cc b/media/audio/win/audio_device_listener_win_unittest.cc
index 052b1bb8c396e8fee5cd8fe4fd1e7df3df554bd6..0c5b7d7813a90c4b0a302157f3771133ee9e7f45 100644
--- a/media/audio/win/audio_device_listener_win_unittest.cc
+++ b/media/audio/win/audio_device_listener_win_unittest.cc
@@ -8,6 +8,7 @@
#include "base/bind_helpers.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/test/simple_test_tick_clock.h"
#include "base/win/scoped_com_initializer.h"
#include "media/audio/audio_manager.h"
#include "media/audio/audio_unittest_util.h"
@@ -36,6 +37,15 @@ class AudioDeviceListenerWinTest : public testing::Test {
output_device_listener_.reset(new AudioDeviceListenerWin(base::Bind(
&AudioDeviceListenerWinTest::OnDeviceChange, base::Unretained(this))));
+
+ tick_clock_ = new base::SimpleTestTickClock();
+ tick_clock_->Advance(base::TimeDelta::FromSeconds(12345));
+ output_device_listener_->tick_clock_.reset(tick_clock_);
+ }
+
+ void AdvanceLastDeviceChangeTime() {
henrika (OOO until Aug 14) 2015/07/22 07:58:20 Perhaps add a comment here to explain why you add
+ tick_clock_->Advance(base::TimeDelta::FromMilliseconds(
+ AudioDeviceListenerWin::kDeviceChangeLimitMs + 1));
}
// Simulate a device change where no output devices are available.
@@ -51,15 +61,13 @@ class AudioDeviceListenerWinTest : public testing::Test {
base::ASCIIToUTF16(new_device_id).c_str()) == S_OK;
}
- void SetOutputDeviceId(std::string new_device_id) {
- output_device_listener_->default_render_device_id_ = new_device_id;
- }
MOCK_METHOD0(OnDeviceChange, void());
private:
ScopedCOMInitializer com_init_;
scoped_ptr<AudioDeviceListenerWin> output_device_listener_;
+ base::SimpleTestTickClock* tick_clock_;
DISALLOW_COPY_AND_ASSIGN(AudioDeviceListenerWinTest);
};
@@ -68,16 +76,15 @@ class AudioDeviceListenerWinTest : public testing::Test {
TEST_F(AudioDeviceListenerWinTest, OutputDeviceChange) {
ABORT_AUDIO_TEST_IF_NOT(CoreAudioUtil::IsSupported());
- SetOutputDeviceId(kNoDevice);
EXPECT_CALL(*this, OnDeviceChange()).Times(1);
ASSERT_TRUE(SimulateDefaultOutputDeviceChange(kFirstTestDevice));
testing::Mock::VerifyAndClear(this);
+ AdvanceLastDeviceChangeTime();
EXPECT_CALL(*this, OnDeviceChange()).Times(1);
ASSERT_TRUE(SimulateDefaultOutputDeviceChange(kSecondTestDevice));
- // The second device event should be ignored since the device id has not
- // changed.
+ // The second device event should be ignored since it occurs too soon.
ASSERT_TRUE(SimulateDefaultOutputDeviceChange(kSecondTestDevice));
}
@@ -86,15 +93,16 @@ TEST_F(AudioDeviceListenerWinTest, OutputDeviceChange) {
TEST_F(AudioDeviceListenerWinTest, NullOutputDeviceChange) {
ABORT_AUDIO_TEST_IF_NOT(CoreAudioUtil::IsSupported());
- SetOutputDeviceId(kNoDevice);
- EXPECT_CALL(*this, OnDeviceChange()).Times(0);
+ EXPECT_CALL(*this, OnDeviceChange()).Times(1);
ASSERT_TRUE(SimulateNullDefaultOutputDeviceChange());
testing::Mock::VerifyAndClear(this);
+ AdvanceLastDeviceChangeTime();
EXPECT_CALL(*this, OnDeviceChange()).Times(1);
ASSERT_TRUE(SimulateDefaultOutputDeviceChange(kFirstTestDevice));
testing::Mock::VerifyAndClear(this);
+ AdvanceLastDeviceChangeTime();
EXPECT_CALL(*this, OnDeviceChange()).Times(1);
ASSERT_TRUE(SimulateNullDefaultOutputDeviceChange());
}
« no previous file with comments | « media/audio/win/audio_device_listener_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698