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

Side by Side Diff: components/copresence/mediums/audio/audio_player_unittest.cc

Issue 637223011: Redesign the copresence audio handlers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: 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 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/mediums/audio/audio_player.h" 5 #include "components/copresence/mediums/audio/audio_player.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "components/copresence/public/copresence_constants.h" 9 #include "components/copresence/public/copresence_constants.h"
10 #include "components/copresence/test/audio_test_support.h" 10 #include "components/copresence/test/audio_test_support.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 public: 74 public:
75 AudioPlayerTest() : buffer_index_(0), player_(NULL) { 75 AudioPlayerTest() : buffer_index_(0), player_(NULL) {
76 if (!media::AudioManager::Get()) 76 if (!media::AudioManager::Get())
77 media::AudioManager::CreateForTesting(); 77 media::AudioManager::CreateForTesting();
78 } 78 }
79 79
80 virtual ~AudioPlayerTest() { DeletePlayer(); } 80 virtual ~AudioPlayerTest() { DeletePlayer(); }
81 81
82 void CreatePlayer() { 82 void CreatePlayer() {
83 DeletePlayer(); 83 DeletePlayer();
84 player_ = new AudioPlayer(); 84 player_ = new AudioPlayerImpl();
85 player_->set_output_stream_for_testing(new TestAudioOutputStream( 85 player_->set_output_stream_for_testing(new TestAudioOutputStream(
86 kDefaultFrameCount, 86 kDefaultFrameCount,
87 kMaxFrameCount, 87 kMaxFrameCount,
88 base::Bind(&AudioPlayerTest::GatherSamples, AsWeakPtr()))); 88 base::Bind(&AudioPlayerTest::GatherSamples, AsWeakPtr())));
89 player_->Initialize(); 89 player_->Initialize();
90 } 90 }
91 91
92 void DeletePlayer() { 92 void DeletePlayer() {
93 if (!player_) 93 if (!player_)
94 return; 94 return;
(...skipping 27 matching lines...) Expand all
122 player_->FlushAudioLoopForTesting(); 122 player_->FlushAudioLoopForTesting();
123 return player_->is_playing_; 123 return player_->is_playing_;
124 } 124 }
125 125
126 static const int kDefaultFrameCount = 1024; 126 static const int kDefaultFrameCount = 1024;
127 static const int kMaxFrameCount = 1024 * 10; 127 static const int kMaxFrameCount = 1024 * 10;
128 128
129 scoped_ptr<media::AudioBus> buffer_; 129 scoped_ptr<media::AudioBus> buffer_;
130 int buffer_index_; 130 int buffer_index_;
131 131
132 AudioPlayer* player_; 132 AudioPlayerImpl* player_;
133 base::MessageLoop message_loop_; 133 base::MessageLoop message_loop_;
134 }; 134 };
135 135
136 TEST_F(AudioPlayerTest, BasicPlayAndStop) { 136 TEST_F(AudioPlayerTest, BasicPlayAndStop) {
137 CreatePlayer(); 137 CreatePlayer();
138 scoped_refptr<media::AudioBusRefCounted> samples = 138 scoped_refptr<media::AudioBusRefCounted> samples =
139 media::AudioBusRefCounted::Create(1, 7331); 139 media::AudioBusRefCounted::Create(1, 7331);
140 140
141 player_->Play(samples); 141 player_->Play(samples);
142 EXPECT_TRUE(IsPlaying()); 142 EXPECT_TRUE(IsPlaying());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 TEST_F(AudioPlayerTest, PlayingEndToEnd) { 180 TEST_F(AudioPlayerTest, PlayingEndToEnd) {
181 const int kNumSamples = kDefaultFrameCount * 10; 181 const int kNumSamples = kDefaultFrameCount * 10;
182 CreatePlayer(); 182 CreatePlayer();
183 183
184 PlayAndVerifySamples(CreateRandomAudioRefCounted(0x1337, 1, kNumSamples)); 184 PlayAndVerifySamples(CreateRandomAudioRefCounted(0x1337, 1, kNumSamples));
185 185
186 DeletePlayer(); 186 DeletePlayer();
187 } 187 }
188 188
189 } // namespace copresence 189 } // namespace copresence
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698