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

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

Issue 1109793005: Fix the issue where the active output device is lost after the device suspend/resume without any ac… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 "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"
(...skipping 2411 matching lines...) Expand 10 before | Expand all | Expand 10 after
2422 AudioNode hdmi(kHDMIOutput); 2422 AudioNode hdmi(kHDMIOutput);
2423 hdmi.plugged_time = 90000000; 2423 hdmi.plugged_time = 90000000;
2424 audio_nodes.push_back(hdmi); 2424 audio_nodes.push_back(hdmi);
2425 ChangeAudioNodes(audio_nodes); 2425 ChangeAudioNodes(audio_nodes);
2426 2426
2427 // The active output should not change. 2427 // The active output should not change.
2428 EXPECT_EQ(kInternalSpeaker.id, 2428 EXPECT_EQ(kInternalSpeaker.id,
2429 cras_audio_handler_->GetPrimaryActiveOutputNode()); 2429 cras_audio_handler_->GetPrimaryActiveOutputNode());
2430 } 2430 }
2431 2431
2432 // Test the case in which the active device was set to inactive from cras after
2433 // resuming from suspension state. See crbug.com/478968.
2434 TEST_F(CrasAudioHandlerTest, ActiveNodeLostAfterResume) {
2435 AudioNodeList audio_nodes;
2436 EXPECT_FALSE(kHeadphone.active);
2437 audio_nodes.push_back(kHeadphone);
2438 EXPECT_FALSE(kHDMIOutput.active);
2439 audio_nodes.push_back(kHDMIOutput);
2440 SetUpCrasAudioHandler(audio_nodes);
2441
2442 // Verify the headphone is selected as the active output.
2443 AudioDeviceList audio_devices;
2444 cras_audio_handler_->GetAudioDevices(&audio_devices);
2445 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
2446 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode());
2447 const AudioDevice* active_headphone = GetDeviceFromId(kHeadphone.id);
2448 EXPECT_EQ(kHeadphone.id, active_headphone->id);
2449 EXPECT_TRUE(active_headphone->active);
2450
2451 // Simulate NodesChanged signal with headphone turning into inactive state,
2452 // and HDMI node removed.
2453 audio_nodes.clear();
2454 audio_nodes.push_back(kHeadphone);
2455 ChangeAudioNodes(audio_nodes);
2456
2457 // Verify the headphone is set to active again.
2458 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode());
2459 const AudioDevice* headphone_resumed = GetDeviceFromId(kHeadphone.id);
2460 EXPECT_EQ(kHeadphone.id, headphone_resumed->id);
2461 EXPECT_TRUE(headphone_resumed->active);
2462 }
2463
2464 // Test the case in which there are two NodesChanged signal for discovering
2465 // output devices, and there is race between NodesChange and SetActiveOutput
2466 // during this process. See crbug.com/478968.
2467 TEST_F(CrasAudioHandlerTest, ActiveNodeLostDuringLoginSession) {
2468 AudioNodeList audio_nodes;
2469 EXPECT_FALSE(kHeadphone.active);
2470 audio_nodes.push_back(kHeadphone);
2471 SetUpCrasAudioHandler(audio_nodes);
2472
2473 // Verify the headphone is selected as the active output.
2474 AudioDeviceList audio_devices;
2475 cras_audio_handler_->GetAudioDevices(&audio_devices);
2476 EXPECT_EQ(audio_nodes.size(), audio_devices.size());
2477 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode());
2478 const AudioDevice* active_headphone = GetDeviceFromId(kHeadphone.id);
2479 EXPECT_EQ(kHeadphone.id, active_headphone->id);
2480 EXPECT_TRUE(active_headphone->active);
2481
2482 // Simulate NodesChanged signal with headphone turning into inactive state,
2483 // and add a new HDMI output node.
2484 audio_nodes.clear();
2485 audio_nodes.push_back(kHeadphone);
2486 audio_nodes.push_back(kHDMIOutput);
2487 ChangeAudioNodes(audio_nodes);
2488
2489 // Verify the headphone is set to active again.
2490 EXPECT_EQ(kHeadphone.id, cras_audio_handler_->GetPrimaryActiveOutputNode());
2491 const AudioDevice* headphone_resumed = GetDeviceFromId(kHeadphone.id);
2492 EXPECT_EQ(kHeadphone.id, headphone_resumed->id);
2493 EXPECT_TRUE(headphone_resumed->active);
2494 }
2495
2432 } // namespace chromeos 2496 } // 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