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

Side by Side Diff: chromeos/audio/cras_audio_handler_unittest.cc

Issue 675403002: Rename CrasAudioClientStubImpl to FakeCrasAudioClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix the app_shell_unittests build Created 6 years, 1 month 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
« no previous file with comments | « no previous file | chromeos/chromeos.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chromeos/audio/cras_audio_handler.h" 5 #include "chromeos/audio/cras_audio_handler.h"
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chromeos/audio/audio_devices_pref_handler_stub.h" 11 #include "chromeos/audio/audio_devices_pref_handler_stub.h"
12 #include "chromeos/dbus/audio_node.h" 12 #include "chromeos/dbus/audio_node.h"
13 #include "chromeos/dbus/cras_audio_client_stub_impl.h"
14 #include "chromeos/dbus/dbus_thread_manager.h" 13 #include "chromeos/dbus/dbus_thread_manager.h"
14 #include "chromeos/dbus/fake_cras_audio_client.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace chromeos { 17 namespace chromeos {
18 18
19 const uint64 kInternalSpeakerId = 10001; 19 const uint64 kInternalSpeakerId = 10001;
20 const uint64 kHeadphoneId = 10002; 20 const uint64 kHeadphoneId = 10002;
21 const uint64 kInternalMicId = 10003; 21 const uint64 kInternalMicId = 10003;
22 const uint64 kUSBMicId = 10004; 22 const uint64 kUSBMicId = 10004;
23 const uint64 kBluetoothHeadsetId = 10005; 23 const uint64 kBluetoothHeadsetId = 10005;
24 const uint64 kHDMIOutputId = 10006; 24 const uint64 kHDMIOutputId = 10006;
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 int input_mute_changed_count_; 229 int input_mute_changed_count_;
230 int output_volume_changed_count_; 230 int output_volume_changed_count_;
231 int input_gain_changed_count_; 231 int input_gain_changed_count_;
232 232
233 DISALLOW_COPY_AND_ASSIGN(TestObserver); 233 DISALLOW_COPY_AND_ASSIGN(TestObserver);
234 }; 234 };
235 235
236 class CrasAudioHandlerTest : public testing::Test { 236 class CrasAudioHandlerTest : public testing::Test {
237 public: 237 public:
238 CrasAudioHandlerTest() : cras_audio_handler_(NULL), 238 CrasAudioHandlerTest() : cras_audio_handler_(NULL),
239 cras_audio_client_stub_(NULL) { 239 fake_cras_audio_client_(NULL) {
240 } 240 }
241 virtual ~CrasAudioHandlerTest() {} 241 virtual ~CrasAudioHandlerTest() {}
242 242
243 virtual void SetUp() override { 243 virtual void SetUp() override {
244 } 244 }
245 245
246 virtual void TearDown() override { 246 virtual void TearDown() override {
247 cras_audio_handler_->RemoveAudioObserver(test_observer_.get()); 247 cras_audio_handler_->RemoveAudioObserver(test_observer_.get());
248 test_observer_.reset(); 248 test_observer_.reset();
249 CrasAudioHandler::Shutdown(); 249 CrasAudioHandler::Shutdown();
250 audio_pref_handler_ = NULL; 250 audio_pref_handler_ = NULL;
251 DBusThreadManager::Shutdown(); 251 DBusThreadManager::Shutdown();
252 } 252 }
253 253
254 void SetUpCrasAudioHandler(const AudioNodeList& audio_nodes) { 254 void SetUpCrasAudioHandler(const AudioNodeList& audio_nodes) {
255 DBusThreadManager::Initialize(); 255 DBusThreadManager::Initialize();
256 cras_audio_client_stub_ = static_cast<CrasAudioClientStubImpl*>( 256 fake_cras_audio_client_ = static_cast<FakeCrasAudioClient*>(
257 DBusThreadManager::Get()->GetCrasAudioClient()); 257 DBusThreadManager::Get()->GetCrasAudioClient());
258 cras_audio_client_stub_->SetAudioNodesForTesting(audio_nodes); 258 fake_cras_audio_client_->SetAudioNodesForTesting(audio_nodes);
259 audio_pref_handler_ = new AudioDevicesPrefHandlerStub(); 259 audio_pref_handler_ = new AudioDevicesPrefHandlerStub();
260 CrasAudioHandler::Initialize(audio_pref_handler_); 260 CrasAudioHandler::Initialize(audio_pref_handler_);
261 cras_audio_handler_ = CrasAudioHandler::Get(); 261 cras_audio_handler_ = CrasAudioHandler::Get();
262 test_observer_.reset(new TestObserver); 262 test_observer_.reset(new TestObserver);
263 cras_audio_handler_->AddAudioObserver(test_observer_.get()); 263 cras_audio_handler_->AddAudioObserver(test_observer_.get());
264 message_loop_.RunUntilIdle(); 264 message_loop_.RunUntilIdle();
265 } 265 }
266 266
267 void SetUpCrasAudioHandlerWithPrimaryActiveNode( 267 void SetUpCrasAudioHandlerWithPrimaryActiveNode(
268 const AudioNodeList& audio_nodes, 268 const AudioNodeList& audio_nodes,
269 const AudioNode& primary_active_node) { 269 const AudioNode& primary_active_node) {
270 DBusThreadManager::Initialize(); 270 DBusThreadManager::Initialize();
271 cras_audio_client_stub_ = static_cast<CrasAudioClientStubImpl*>( 271 fake_cras_audio_client_ = static_cast<FakeCrasAudioClient*>(
272 DBusThreadManager::Get()->GetCrasAudioClient()); 272 DBusThreadManager::Get()->GetCrasAudioClient());
273 cras_audio_client_stub_->SetAudioNodesForTesting(audio_nodes); 273 fake_cras_audio_client_->SetAudioNodesForTesting(audio_nodes);
274 cras_audio_client_stub_->SetActiveOutputNode(primary_active_node.id), 274 fake_cras_audio_client_->SetActiveOutputNode(primary_active_node.id),
275 audio_pref_handler_ = new AudioDevicesPrefHandlerStub(); 275 audio_pref_handler_ = new AudioDevicesPrefHandlerStub();
276 CrasAudioHandler::Initialize(audio_pref_handler_); 276 CrasAudioHandler::Initialize(audio_pref_handler_);
277 cras_audio_handler_ = CrasAudioHandler::Get(); 277 cras_audio_handler_ = CrasAudioHandler::Get();
278 test_observer_.reset(new TestObserver); 278 test_observer_.reset(new TestObserver);
279 cras_audio_handler_->AddAudioObserver(test_observer_.get()); 279 cras_audio_handler_->AddAudioObserver(test_observer_.get());
280 message_loop_.RunUntilIdle(); 280 message_loop_.RunUntilIdle();
281 } 281 }
282 282
283 void ChangeAudioNodes(const AudioNodeList& audio_nodes) { 283 void ChangeAudioNodes(const AudioNodeList& audio_nodes) {
284 cras_audio_client_stub_->SetAudioNodesAndNotifyObserversForTesting( 284 fake_cras_audio_client_->SetAudioNodesAndNotifyObserversForTesting(
285 audio_nodes); 285 audio_nodes);
286 message_loop_.RunUntilIdle(); 286 message_loop_.RunUntilIdle();
287 } 287 }
288 288
289 const AudioDevice* GetDeviceFromId(uint64 id) { 289 const AudioDevice* GetDeviceFromId(uint64 id) {
290 return cras_audio_handler_->GetDeviceFromId(id); 290 return cras_audio_handler_->GetDeviceFromId(id);
291 } 291 }
292 292
293 protected: 293 protected:
294 base::MessageLoopForUI message_loop_; 294 base::MessageLoopForUI message_loop_;
295 CrasAudioHandler* cras_audio_handler_; // Not owned. 295 CrasAudioHandler* cras_audio_handler_; // Not owned.
296 CrasAudioClientStubImpl* cras_audio_client_stub_; // Not owned. 296 FakeCrasAudioClient* fake_cras_audio_client_; // Not owned.
297 scoped_ptr<TestObserver> test_observer_; 297 scoped_ptr<TestObserver> test_observer_;
298 scoped_refptr<AudioDevicesPrefHandlerStub> audio_pref_handler_; 298 scoped_refptr<AudioDevicesPrefHandlerStub> audio_pref_handler_;
299 299
300 private: 300 private:
301 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandlerTest); 301 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandlerTest);
302 }; 302 };
303 303
304 TEST_F(CrasAudioHandlerTest, InitializeWithOnlyDefaultAudioDevices) { 304 TEST_F(CrasAudioHandlerTest, InitializeWithOnlyDefaultAudioDevices) {
305 AudioNodeList audio_nodes; 305 AudioNodeList audio_nodes;
306 audio_nodes.push_back(kInternalSpeaker); 306 audio_nodes.push_back(kInternalSpeaker);
(...skipping 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after
1931 // nodes. 1931 // nodes.
1932 cras_audio_handler_->AddActiveNode(kInternalSpeaker.id); 1932 cras_audio_handler_->AddActiveNode(kInternalSpeaker.id);
1933 EXPECT_FALSE( 1933 EXPECT_FALSE(
1934 cras_audio_handler_->IsOutputMutedForDevice(kInternalSpeaker.id)); 1934 cras_audio_handler_->IsOutputMutedForDevice(kInternalSpeaker.id));
1935 EXPECT_EQ(25, 1935 EXPECT_EQ(25,
1936 cras_audio_handler_->GetOutputVolumePercentForDevice( 1936 cras_audio_handler_->GetOutputVolumePercentForDevice(
1937 kInternalSpeaker.id)); 1937 kInternalSpeaker.id));
1938 } 1938 }
1939 1939
1940 } // namespace chromeos 1940 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chromeos/chromeos.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698