| Index: chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_browsertest.cc
|
| diff --git a/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_browsertest.cc b/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_browsertest.cc
|
| index 2be15af2684e80851984b9e35dd8c3606828eb3e..53fa13bec9eecc6f39185c274fd7ab094759462e 100644
|
| --- a/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_browsertest.cc
|
| +++ b/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_browsertest.cc
|
| @@ -35,7 +35,7 @@
|
| #include "extensions/common/permissions/permission_set.h"
|
| #include "extensions/common/permissions/permissions_data.h"
|
| #include "media/audio/audio_device_description.h"
|
| -#include "media/audio/audio_manager.h"
|
| +#include "media/audio/audio_system.h"
|
| #include "net/test/embedded_test_server/embedded_test_server.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -47,13 +47,35 @@ using base::JSONWriter;
|
| using content::RenderProcessHost;
|
| using content::WebContents;
|
| using media::AudioDeviceDescriptions;
|
| -using media::AudioManager;
|
|
|
| namespace extensions {
|
|
|
| using extension_function_test_utils::RunFunctionAndReturnError;
|
| using extension_function_test_utils::RunFunctionAndReturnSingleResult;
|
|
|
| +namespace {
|
| +
|
| +// Synchronously (from the calling thread's point of view) runs the
|
| +// given enumeration function on the device thread. On return,
|
| +// |device_descriptions| has been filled with the device descriptions
|
| +// resulting from that call.
|
| +void GetAudioDeviceDescriptions(bool for_input,
|
| + AudioDeviceDescriptions* device_descriptions) {
|
| + base::RunLoop run_loop;
|
| + media::AudioSystem::Get()->GetDeviceDescriptions(
|
| + base::Bind(
|
| + [](base::Closure finished_callback, AudioDeviceDescriptions* result,
|
| + AudioDeviceDescriptions received) {
|
| + *result = std::move(received);
|
| + finished_callback.Run();
|
| + },
|
| + base::Passed(run_loop.QuitClosure()), device_descriptions),
|
| + for_input);
|
| + run_loop.Run();
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| class AudioWaitingExtensionTest : public ExtensionApiTest {
|
| protected:
|
| void WaitUntilAudioIsPlaying(WebContents* tab) {
|
| @@ -64,10 +86,8 @@ class AudioWaitingExtensionTest : public ExtensionApiTest {
|
| base::RunLoop().RunUntilIdle();
|
| if (audio_playing)
|
| break;
|
| -
|
| base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
|
| }
|
| -
|
| if (!audio_playing)
|
| FAIL() << "Audio did not start playing within ~5 seconds.";
|
| }
|
| @@ -75,9 +95,7 @@ class AudioWaitingExtensionTest : public ExtensionApiTest {
|
|
|
| class WebrtcAudioPrivateTest : public AudioWaitingExtensionTest {
|
| public:
|
| - WebrtcAudioPrivateTest()
|
| - : enumeration_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
|
| - base::WaitableEvent::InitialState::NOT_SIGNALED) {}
|
| + WebrtcAudioPrivateTest() {}
|
|
|
| void SetUpOnMainThread() override {
|
| AudioWaitingExtensionTest::SetUpOnMainThread();
|
| @@ -104,54 +122,6 @@ class WebrtcAudioPrivateTest : public AudioWaitingExtensionTest {
|
| return result;
|
| }
|
|
|
| - // Synchronously (from the calling thread's point of view) runs the
|
| - // given enumeration function on the device thread. On return,
|
| - // |device_descriptions| has been filled with the device descriptions
|
| - // resulting from that call.
|
| - void GetAudioDeviceDescriptions(
|
| - void (AudioManager::*EnumerationFunc)(AudioDeviceDescriptions*),
|
| - AudioDeviceDescriptions* device_descriptions) {
|
| - AudioManager* audio_manager = AudioManager::Get();
|
| -
|
| - if (!audio_manager->GetTaskRunner()->BelongsToCurrentThread()) {
|
| - audio_manager->GetTaskRunner()->PostTask(
|
| - FROM_HERE,
|
| - base::BindOnce(&WebrtcAudioPrivateTest::GetAudioDeviceDescriptions,
|
| - base::Unretained(this), EnumerationFunc,
|
| - device_descriptions));
|
| - enumeration_event_.Wait();
|
| - } else {
|
| - (audio_manager->*EnumerationFunc)(device_descriptions);
|
| - enumeration_event_.Signal();
|
| - }
|
| - }
|
| -
|
| - // Synchronously (from the calling thread's point of view) retrieve the
|
| - // device id in the |origin| on the IO thread. On return,
|
| - // |id_in_origin| contains the id |raw_device_id| is known by in
|
| - // the origin.
|
| - void GetIDInOrigin(content::ResourceContext* resource_context,
|
| - GURL origin,
|
| - const std::string& raw_device_id,
|
| - std::string* id_in_origin) {
|
| - if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
|
| - content::BrowserThread::PostTask(
|
| - content::BrowserThread::UI, FROM_HERE,
|
| - base::BindOnce(&WebrtcAudioPrivateTest::GetIDInOrigin,
|
| - base::Unretained(this), resource_context, origin,
|
| - raw_device_id, id_in_origin));
|
| - enumeration_event_.Wait();
|
| - } else {
|
| - *id_in_origin = content::GetHMACForMediaDeviceID(
|
| - resource_context->GetMediaDeviceIDSalt(), url::Origin(origin),
|
| - raw_device_id);
|
| - enumeration_event_.Signal();
|
| - }
|
| - }
|
| -
|
| - // Event used to signal completion of enumeration.
|
| - base::WaitableEvent enumeration_event_;
|
| -
|
| GURL source_url_;
|
| };
|
|
|
| @@ -159,8 +129,7 @@ class WebrtcAudioPrivateTest : public AudioWaitingExtensionTest {
|
| // http://crbug.com/334579
|
| IN_PROC_BROWSER_TEST_F(WebrtcAudioPrivateTest, GetSinks) {
|
| AudioDeviceDescriptions devices;
|
| - GetAudioDeviceDescriptions(&AudioManager::GetAudioOutputDeviceDescriptions,
|
| - &devices);
|
| + GetAudioDeviceDescriptions(false, &devices);
|
|
|
| base::ListValue* sink_list = NULL;
|
| std::unique_ptr<base::Value> result = InvokeGetSinks(&sink_list);
|
| @@ -182,15 +151,12 @@ IN_PROC_BROWSER_TEST_F(WebrtcAudioPrivateTest, GetSinks) {
|
| std::string sink_id;
|
| dict->GetString("sinkId", &sink_id);
|
|
|
| - std::string expected_id;
|
| - if (media::AudioDeviceDescription::IsDefaultDevice(it->unique_id)) {
|
| - expected_id = media::AudioDeviceDescription::kDefaultDeviceId;
|
| - } else {
|
| - GetIDInOrigin(profile()->GetResourceContext(),
|
| - source_url_.GetOrigin(),
|
| - it->unique_id,
|
| - &expected_id);
|
| - }
|
| + std::string expected_id =
|
| + media::AudioDeviceDescription::IsDefaultDevice(it->unique_id)
|
| + ? media::AudioDeviceDescription::kDefaultDeviceId
|
| + : content::GetHMACForMediaDeviceID(
|
| + profile()->GetResourceContext()->GetMediaDeviceIDSalt(),
|
| + url::Origin(source_url_.GetOrigin()), it->unique_id);
|
|
|
| EXPECT_EQ(expected_id, sink_id);
|
| std::string sink_label;
|
| @@ -211,8 +177,7 @@ IN_PROC_BROWSER_TEST_F(WebrtcAudioPrivateTest, GetAssociatedSink) {
|
| // run this on the main thread since nobody else will be running at
|
| // the same time.
|
| AudioDeviceDescriptions devices;
|
| - GetAudioDeviceDescriptions(&AudioManager::GetAudioInputDeviceDescriptions,
|
| - &devices);
|
| + GetAudioDeviceDescriptions(true, &devices);
|
|
|
| // Try to get an associated sink for each source.
|
| for (const auto& device : devices) {
|
| @@ -222,12 +187,10 @@ IN_PROC_BROWSER_TEST_F(WebrtcAudioPrivateTest, GetAssociatedSink) {
|
|
|
| std::string raw_device_id = device.unique_id;
|
| VLOG(2) << "Trying to find associated sink for device " << raw_device_id;
|
| - std::string source_id_in_origin;
|
| GURL origin(GURL("http://www.google.com/").GetOrigin());
|
| - GetIDInOrigin(profile()->GetResourceContext(),
|
| - origin,
|
| - raw_device_id,
|
| - &source_id_in_origin);
|
| + std::string source_id_in_origin = content::GetHMACForMediaDeviceID(
|
| + profile()->GetResourceContext()->GetMediaDeviceIDSalt(),
|
| + url::Origin(origin), raw_device_id);
|
|
|
| base::ListValue parameters;
|
| parameters.AppendString(origin.spec());
|
|
|