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

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

Issue 2270693005: Fix the corner case for new audio device is not selected as active if it is plugged in for the firs… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 4 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
« no previous file with comments | « chromeos/audio/cras_audio_handler.cc ('k') | no next file » | 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 2354 matching lines...) Expand 10 before | Expand all | Expand 10 after
2365 audio_nodes.push_back(kHeadphone); 2365 audio_nodes.push_back(kHeadphone);
2366 ChangeAudioNodes(audio_nodes); 2366 ChangeAudioNodes(audio_nodes);
2367 2367
2368 // Verify the active output has been restored to internal speaker. 2368 // Verify the active output has been restored to internal speaker.
2369 cras_audio_handler_->GetAudioDevices(&audio_devices); 2369 cras_audio_handler_->GetAudioDevices(&audio_devices);
2370 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); 2370 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
2371 EXPECT_EQ(kInternalSpeaker.id, 2371 EXPECT_EQ(kInternalSpeaker.id,
2372 cras_audio_handler_->GetPrimaryActiveOutputNode()); 2372 cras_audio_handler_->GetPrimaryActiveOutputNode());
2373 } 2373 }
2374 2374
2375 // Test the corner case that headphone is plugged in for the first time on
2376 // a cros device after the device is shutdown.
2377 // crbug.com/622045.
2378 TEST_F(CrasAudioHandlerTest, PlugInHeadphoneFirstTimeAfterPowerDown) {
2379 // Simulate plugging headphone for the first on a cros device after it is
2380 // powered down. Internal speaker is set up in audio prefs as active
2381 // before the new cros session starts.
2382 AudioNodeList audio_nodes_in_pref;
2383 audio_nodes_in_pref.push_back(kInternalSpeaker);
2384
2385 AudioNodeList audio_nodes;
2386 audio_nodes.push_back(kInternalSpeaker);
2387 audio_nodes.push_back(kHeadphone);
2388
2389 SetupCrasAudioHandlerWithActiveNodeInPref(
2390 audio_nodes, audio_nodes_in_pref, AudioDevice(kInternalSpeaker), false);
2391
2392 // Verify the audio devices size.
2393 AudioDeviceList audio_devices;
2394 cras_audio_handler_->GetAudioDevices(&audio_devices);
2395 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
2396
2397 // Verify headphone becomes the active output.
2398 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode());
2399 }
2400
2375 TEST_F(CrasAudioHandlerTest, 2401 TEST_F(CrasAudioHandlerTest,
2376 PersistActiveUsbHeadphoneAcrossRebootUsbComeLater) { 2402 PersistActiveUsbHeadphoneAcrossRebootUsbComeLater) {
2377 // Simulates the device was shut down with three audio devices, and 2403 // Simulates the device was shut down with three audio devices, and
2378 // usb headphone being the active one selected by priority. 2404 // usb headphone being the active one selected by priority.
2379 AudioNodeList audio_nodes_in_pref; 2405 AudioNodeList audio_nodes_in_pref;
2380 audio_nodes_in_pref.push_back(kInternalSpeaker); 2406 audio_nodes_in_pref.push_back(kInternalSpeaker);
2381 audio_nodes_in_pref.push_back(kHeadphone); 2407 audio_nodes_in_pref.push_back(kHeadphone);
2382 audio_nodes_in_pref.push_back(kUSBHeadphone1); 2408 audio_nodes_in_pref.push_back(kUSBHeadphone1);
2383 2409
2384 // Simulate the first NodesChanged signal coming with only internal speaker 2410 // Simulate the first NodesChanged signal coming with only internal speaker
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
3267 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); 3293 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output));
3268 EXPECT_EQ(kInternalSpeaker.id, active_output.id); 3294 EXPECT_EQ(kInternalSpeaker.id, active_output.id);
3269 EXPECT_EQ(kInternalSpeaker.id, 3295 EXPECT_EQ(kInternalSpeaker.id,
3270 cras_audio_handler_->GetPrimaryActiveOutputNode()); 3296 cras_audio_handler_->GetPrimaryActiveOutputNode());
3271 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); 3297 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted());
3272 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); 3298 EXPECT_EQ(1, test_observer_->output_mute_changed_count());
3273 EXPECT_TRUE(test_observer_->output_mute_by_system()); 3299 EXPECT_TRUE(test_observer_->output_mute_by_system());
3274 } 3300 }
3275 3301
3276 } // namespace chromeos 3302 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/audio/cras_audio_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698