| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/auto_reset.h" |
| 11 #include "base/command_line.h" |
| 8 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 10 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "extensions/common/features/feature_session_type.h" |
| 16 #include "extensions/common/switches.h" |
| 11 #include "extensions/shell/test/shell_apitest.h" | 17 #include "extensions/shell/test/shell_apitest.h" |
| 12 #include "extensions/test/extension_test_message_listener.h" | 18 #include "extensions/test/extension_test_message_listener.h" |
| 13 #include "extensions/test/result_catcher.h" | 19 #include "extensions/test/result_catcher.h" |
| 14 | 20 |
| 15 #if defined(OS_CHROMEOS) | 21 #if defined(OS_CHROMEOS) |
| 16 #include "chromeos/audio/audio_devices_pref_handler_stub.h" | 22 #include "chromeos/audio/audio_devices_pref_handler_stub.h" |
| 17 #include "chromeos/audio/cras_audio_handler.h" | 23 #include "chromeos/audio/cras_audio_handler.h" |
| 18 #include "chromeos/dbus/dbus_thread_manager.h" | 24 #include "chromeos/dbus/dbus_thread_manager.h" |
| 19 #include "chromeos/dbus/fake_cras_audio_client.h" | 25 #include "chromeos/dbus/fake_cras_audio_client.h" |
| 20 #endif | 26 #endif |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // stable_device_id_v2: | 86 // stable_device_id_v2: |
| 81 version == 2 ? info.stable_id ^ 0xFFFF : 0, info.device_name, | 87 version == 2 ? info.stable_id ^ 0xFFFF : 0, info.device_name, |
| 82 info.type, info.name, false, 0); | 88 info.type, info.name, false, 0); |
| 83 } | 89 } |
| 84 | 90 |
| 85 class AudioApiTest : public ShellApiTest { | 91 class AudioApiTest : public ShellApiTest { |
| 86 public: | 92 public: |
| 87 AudioApiTest() : cras_audio_handler_(NULL), fake_cras_audio_client_(NULL) {} | 93 AudioApiTest() : cras_audio_handler_(NULL), fake_cras_audio_client_(NULL) {} |
| 88 ~AudioApiTest() override {} | 94 ~AudioApiTest() override {} |
| 89 | 95 |
| 96 void SetUp() override { |
| 97 session_feature_type_ = extensions::ScopedCurrentFeatureSessionType( |
| 98 extensions::FeatureSessionType::KIOSK); |
| 99 |
| 100 ShellApiTest::SetUp(); |
| 101 } |
| 102 |
| 90 void SetUpCrasAudioHandlerWithTestingNodes(const AudioNodeList& audio_nodes) { | 103 void SetUpCrasAudioHandlerWithTestingNodes(const AudioNodeList& audio_nodes) { |
| 91 chromeos::DBusThreadManager* dbus_manager = | 104 chromeos::DBusThreadManager* dbus_manager = |
| 92 chromeos::DBusThreadManager::Get(); | 105 chromeos::DBusThreadManager::Get(); |
| 93 DCHECK(dbus_manager); | 106 DCHECK(dbus_manager); |
| 94 fake_cras_audio_client_ = static_cast<chromeos::FakeCrasAudioClient*>( | 107 fake_cras_audio_client_ = static_cast<chromeos::FakeCrasAudioClient*>( |
| 95 dbus_manager->GetCrasAudioClient()); | 108 dbus_manager->GetCrasAudioClient()); |
| 96 fake_cras_audio_client_->SetAudioNodesAndNotifyObserversForTesting( | 109 fake_cras_audio_client_->SetAudioNodesAndNotifyObserversForTesting( |
| 97 audio_nodes); | 110 audio_nodes); |
| 98 cras_audio_handler_ = chromeos::CrasAudioHandler::Get(); | 111 cras_audio_handler_ = chromeos::CrasAudioHandler::Get(); |
| 99 DCHECK(cras_audio_handler_); | 112 DCHECK(cras_audio_handler_); |
| 100 base::RunLoop().RunUntilIdle(); | 113 base::RunLoop().RunUntilIdle(); |
| 101 } | 114 } |
| 102 | 115 |
| 103 void ChangeAudioNodes(const AudioNodeList& audio_nodes) { | 116 void ChangeAudioNodes(const AudioNodeList& audio_nodes) { |
| 104 DCHECK(fake_cras_audio_client_); | 117 DCHECK(fake_cras_audio_client_); |
| 105 fake_cras_audio_client_->SetAudioNodesAndNotifyObserversForTesting( | 118 fake_cras_audio_client_->SetAudioNodesAndNotifyObserversForTesting( |
| 106 audio_nodes); | 119 audio_nodes); |
| 107 base::RunLoop().RunUntilIdle(); | 120 base::RunLoop().RunUntilIdle(); |
| 108 } | 121 } |
| 109 | 122 |
| 110 protected: | 123 protected: |
| 111 base::MessageLoopForUI message_loop_; | 124 base::MessageLoopForUI message_loop_; |
| 125 std::unique_ptr<base::AutoReset<extensions::FeatureSessionType>> |
| 126 session_feature_type_; |
| 112 chromeos::CrasAudioHandler* cras_audio_handler_; // Not owned. | 127 chromeos::CrasAudioHandler* cras_audio_handler_; // Not owned. |
| 113 chromeos::FakeCrasAudioClient* fake_cras_audio_client_; // Not owned. | 128 chromeos::FakeCrasAudioClient* fake_cras_audio_client_; // Not owned. |
| 114 }; | 129 }; |
| 115 | 130 |
| 116 IN_PROC_BROWSER_TEST_F(AudioApiTest, Audio) { | 131 IN_PROC_BROWSER_TEST_F(AudioApiTest, Audio) { |
| 117 // Set up the audio nodes for testing. | 132 // Set up the audio nodes for testing. |
| 118 AudioNodeList audio_nodes = { | 133 AudioNodeList audio_nodes = { |
| 119 CreateAudioNode(kJabraSpeaker1, 2), CreateAudioNode(kJabraSpeaker2, 2), | 134 CreateAudioNode(kJabraSpeaker1, 2), CreateAudioNode(kJabraSpeaker2, 2), |
| 120 CreateAudioNode(kHDMIOutput, 2), CreateAudioNode(kJabraMic1, 2), | 135 CreateAudioNode(kHDMIOutput, 2), CreateAudioNode(kJabraMic1, 2), |
| 121 CreateAudioNode(kJabraMic2, 2), CreateAudioNode(kUSBCameraMic, 2)}; | 136 CreateAudioNode(kJabraMic2, 2), CreateAudioNode(kUSBCameraMic, 2)}; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 audio_nodes.erase(audio_nodes.begin() + init_device_size - 1); | 277 audio_nodes.erase(audio_nodes.begin() + init_device_size - 1); |
| 263 ChangeAudioNodes(audio_nodes); | 278 ChangeAudioNodes(audio_nodes); |
| 264 cras_audio_handler_->GetAudioDevices(&audio_devices); | 279 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 265 EXPECT_EQ(init_device_size - 1, audio_devices.size()); | 280 EXPECT_EQ(init_device_size - 1, audio_devices.size()); |
| 266 | 281 |
| 267 // Verify the background app got the onNodesChanged event | 282 // Verify the background app got the onNodesChanged event |
| 268 // with the last node removed. | 283 // with the last node removed. |
| 269 EXPECT_TRUE(result_catcher.GetNextResult()) << result_catcher.message(); | 284 EXPECT_TRUE(result_catcher.GetNextResult()) << result_catcher.message(); |
| 270 } | 285 } |
| 271 | 286 |
| 287 class WhitelistedAudioApiTest : public AudioApiTest { |
| 288 public: |
| 289 WhitelistedAudioApiTest() {} |
| 290 ~WhitelistedAudioApiTest() override = default; |
| 291 |
| 292 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 293 command_line->AppendSwitchASCII( |
| 294 extensions::switches::kWhitelistedExtensionID, |
| 295 "jlgnoeceollaejlkenecblnjmdcfhfgc"); |
| 296 } |
| 297 }; |
| 298 |
| 299 IN_PROC_BROWSER_TEST_F(WhitelistedAudioApiTest, DeprecatedApi) { |
| 300 // Set up the audio nodes for testing. |
| 301 AudioNodeList audio_nodes = { |
| 302 CreateAudioNode(kJabraSpeaker1, 2), CreateAudioNode(kJabraSpeaker2, 2), |
| 303 CreateAudioNode(kHDMIOutput, 2), CreateAudioNode(kJabraMic1, 2), |
| 304 CreateAudioNode(kJabraMic2, 2), CreateAudioNode(kUSBCameraMic, 2)}; |
| 305 |
| 306 SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); |
| 307 |
| 308 EXPECT_TRUE(RunAppTest("api_test/audio/deprecated_api")) << message_; |
| 309 } |
| 310 |
| 272 #endif // OS_CHROMEOS | 311 #endif // OS_CHROMEOS |
| 273 | 312 |
| 274 } // namespace extensions | 313 } // namespace extensions |
| OLD | NEW |