OLD | NEW |
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 Loading... |
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 |
OLD | NEW |