| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "extensions/common/permissions/permission_set.h" | 36 #include "extensions/common/permissions/permission_set.h" |
| 37 #include "extensions/common/permissions/permissions_data.h" | 37 #include "extensions/common/permissions/permissions_data.h" |
| 38 #include "media/audio/audio_device_description.h" | 38 #include "media/audio/audio_device_description.h" |
| 39 #include "media/audio/audio_manager.h" | 39 #include "media/audio/audio_manager.h" |
| 40 #include "net/test/embedded_test_server/embedded_test_server.h" | 40 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 42 | 42 |
| 43 using base::JSONWriter; | 43 using base::JSONWriter; |
| 44 using content::RenderProcessHost; | 44 using content::RenderProcessHost; |
| 45 using content::WebContents; | 45 using content::WebContents; |
| 46 using media::AudioDeviceNames; | 46 using media::AudioDeviceDescriptions; |
| 47 using media::AudioManager; | 47 using media::AudioManager; |
| 48 | 48 |
| 49 namespace extensions { | 49 namespace extensions { |
| 50 | 50 |
| 51 using extension_function_test_utils::RunFunctionAndReturnError; | 51 using extension_function_test_utils::RunFunctionAndReturnError; |
| 52 using extension_function_test_utils::RunFunctionAndReturnSingleResult; | 52 using extension_function_test_utils::RunFunctionAndReturnSingleResult; |
| 53 | 53 |
| 54 class AudioWaitingExtensionTest : public ExtensionApiTest { | 54 class AudioWaitingExtensionTest : public ExtensionApiTest { |
| 55 protected: | 55 protected: |
| 56 void WaitUntilAudioIsPlaying(WebContents* tab) { | 56 void WaitUntilAudioIsPlaying(WebContents* tab) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 function->set_source_url(source_url_); | 122 function->set_source_url(source_url_); |
| 123 | 123 |
| 124 std::unique_ptr<base::Value> result( | 124 std::unique_ptr<base::Value> result( |
| 125 RunFunctionAndReturnSingleResult(function.get(), "[]", browser())); | 125 RunFunctionAndReturnSingleResult(function.get(), "[]", browser())); |
| 126 result->GetAsList(sink_list); | 126 result->GetAsList(sink_list); |
| 127 return result; | 127 return result; |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Synchronously (from the calling thread's point of view) runs the | 130 // Synchronously (from the calling thread's point of view) runs the |
| 131 // given enumeration function on the device thread. On return, | 131 // given enumeration function on the device thread. On return, |
| 132 // |device_names| has been filled with the device names resulting | 132 // |device_descriptions| has been filled with the device descriptions |
| 133 // from that call. | 133 // resulting from that call. |
| 134 void GetAudioDeviceNames( | 134 void GetAudioDeviceDescriptions( |
| 135 void (AudioManager::*EnumerationFunc)(AudioDeviceNames*), | 135 void (AudioManager::*EnumerationFunc)(AudioDeviceDescriptions*), |
| 136 AudioDeviceNames* device_names) { | 136 AudioDeviceDescriptions* device_descriptions) { |
| 137 AudioManager* audio_manager = AudioManager::Get(); | 137 AudioManager* audio_manager = AudioManager::Get(); |
| 138 | 138 |
| 139 if (!audio_manager->GetTaskRunner()->BelongsToCurrentThread()) { | 139 if (!audio_manager->GetTaskRunner()->BelongsToCurrentThread()) { |
| 140 audio_manager->GetTaskRunner()->PostTask( | 140 audio_manager->GetTaskRunner()->PostTask( |
| 141 FROM_HERE, | 141 FROM_HERE, |
| 142 base::Bind(&WebrtcAudioPrivateTest::GetAudioDeviceNames, | 142 base::Bind(&WebrtcAudioPrivateTest::GetAudioDeviceDescriptions, |
| 143 base::Unretained(this), | 143 base::Unretained(this), EnumerationFunc, |
| 144 EnumerationFunc, device_names)); | 144 device_descriptions)); |
| 145 enumeration_event_.Wait(); | 145 enumeration_event_.Wait(); |
| 146 } else { | 146 } else { |
| 147 (audio_manager->*EnumerationFunc)(device_names); | 147 (audio_manager->*EnumerationFunc)(device_descriptions); |
| 148 enumeration_event_.Signal(); | 148 enumeration_event_.Signal(); |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 // Synchronously (from the calling thread's point of view) retrieve the | 152 // Synchronously (from the calling thread's point of view) retrieve the |
| 153 // device id in the |origin| on the IO thread. On return, | 153 // device id in the |origin| on the IO thread. On return, |
| 154 // |id_in_origin| contains the id |raw_device_id| is known by in | 154 // |id_in_origin| contains the id |raw_device_id| is known by in |
| 155 // the origin. | 155 // the origin. |
| 156 void GetIDInOrigin(content::ResourceContext* resource_context, | 156 void GetIDInOrigin(content::ResourceContext* resource_context, |
| 157 GURL origin, | 157 GURL origin, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 174 | 174 |
| 175 // Event used to signal completion of enumeration. | 175 // Event used to signal completion of enumeration. |
| 176 base::WaitableEvent enumeration_event_; | 176 base::WaitableEvent enumeration_event_; |
| 177 | 177 |
| 178 GURL source_url_; | 178 GURL source_url_; |
| 179 }; | 179 }; |
| 180 | 180 |
| 181 #if !defined(OS_MACOSX) | 181 #if !defined(OS_MACOSX) |
| 182 // http://crbug.com/334579 | 182 // http://crbug.com/334579 |
| 183 IN_PROC_BROWSER_TEST_F(WebrtcAudioPrivateTest, GetSinks) { | 183 IN_PROC_BROWSER_TEST_F(WebrtcAudioPrivateTest, GetSinks) { |
| 184 AudioDeviceNames devices; | 184 AudioDeviceDescriptions devices; |
| 185 GetAudioDeviceNames(&AudioManager::GetAudioOutputDeviceNames, &devices); | 185 GetAudioDeviceDescriptions(&AudioManager::GetAudioOutputDeviceDescriptions, |
| 186 &devices); |
| 186 | 187 |
| 187 base::ListValue* sink_list = NULL; | 188 base::ListValue* sink_list = NULL; |
| 188 std::unique_ptr<base::Value> result = InvokeGetSinks(&sink_list); | 189 std::unique_ptr<base::Value> result = InvokeGetSinks(&sink_list); |
| 189 | 190 |
| 190 std::string result_string; | 191 std::string result_string; |
| 191 JSONWriter::Write(*result, &result_string); | 192 JSONWriter::Write(*result, &result_string); |
| 192 VLOG(2) << result_string; | 193 VLOG(2) << result_string; |
| 193 | 194 |
| 194 EXPECT_EQ(devices.size(), sink_list->GetSize()); | 195 EXPECT_EQ(devices.size(), sink_list->GetSize()); |
| 195 | 196 |
| 196 // Iterate through both lists in lockstep and compare. The order | 197 // Iterate through both lists in lockstep and compare. The order |
| 197 // should be identical. | 198 // should be identical. |
| 198 size_t ix = 0; | 199 size_t ix = 0; |
| 199 AudioDeviceNames::const_iterator it = devices.begin(); | 200 AudioDeviceDescriptions::const_iterator it = devices.begin(); |
| 200 for (; ix < sink_list->GetSize() && it != devices.end(); | 201 for (; ix < sink_list->GetSize() && it != devices.end(); |
| 201 ++ix, ++it) { | 202 ++ix, ++it) { |
| 202 base::DictionaryValue* dict = NULL; | 203 base::DictionaryValue* dict = NULL; |
| 203 sink_list->GetDictionary(ix, &dict); | 204 sink_list->GetDictionary(ix, &dict); |
| 204 std::string sink_id; | 205 std::string sink_id; |
| 205 dict->GetString("sinkId", &sink_id); | 206 dict->GetString("sinkId", &sink_id); |
| 206 | 207 |
| 207 std::string expected_id; | 208 std::string expected_id; |
| 208 if (media::AudioDeviceDescription::IsDefaultDevice(it->unique_id)) { | 209 if (media::AudioDeviceDescription::IsDefaultDevice(it->unique_id)) { |
| 209 expected_id = media::AudioDeviceDescription::kDefaultDeviceId; | 210 expected_id = media::AudioDeviceDescription::kDefaultDeviceId; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 VLOG(2) << "After setting to " << target_device | 326 VLOG(2) << "After setting to " << target_device |
| 326 << ", current device is " << current_device; | 327 << ", current device is " << current_device; |
| 327 EXPECT_EQ(target_device, current_device); | 328 EXPECT_EQ(target_device, current_device); |
| 328 } | 329 } |
| 329 } | 330 } |
| 330 | 331 |
| 331 IN_PROC_BROWSER_TEST_F(WebrtcAudioPrivateTest, GetAssociatedSink) { | 332 IN_PROC_BROWSER_TEST_F(WebrtcAudioPrivateTest, GetAssociatedSink) { |
| 332 // Get the list of input devices. We can cheat in the unit test and | 333 // Get the list of input devices. We can cheat in the unit test and |
| 333 // run this on the main thread since nobody else will be running at | 334 // run this on the main thread since nobody else will be running at |
| 334 // the same time. | 335 // the same time. |
| 335 AudioDeviceNames devices; | 336 AudioDeviceDescriptions devices; |
| 336 GetAudioDeviceNames(&AudioManager::GetAudioInputDeviceNames, &devices); | 337 GetAudioDeviceDescriptions(&AudioManager::GetAudioInputDeviceDescriptions, |
| 338 &devices); |
| 337 | 339 |
| 338 // Try to get an associated sink for each source. | 340 // Try to get an associated sink for each source. |
| 339 for (AudioDeviceNames::const_iterator device = devices.begin(); | 341 for (const auto& device : devices) { |
| 340 device != devices.end(); | |
| 341 ++device) { | |
| 342 scoped_refptr<WebrtcAudioPrivateGetAssociatedSinkFunction> function = | 342 scoped_refptr<WebrtcAudioPrivateGetAssociatedSinkFunction> function = |
| 343 new WebrtcAudioPrivateGetAssociatedSinkFunction(); | 343 new WebrtcAudioPrivateGetAssociatedSinkFunction(); |
| 344 function->set_source_url(source_url_); | 344 function->set_source_url(source_url_); |
| 345 | 345 |
| 346 std::string raw_device_id = device->unique_id; | 346 std::string raw_device_id = device.unique_id; |
| 347 VLOG(2) << "Trying to find associated sink for device " << raw_device_id; | 347 VLOG(2) << "Trying to find associated sink for device " << raw_device_id; |
| 348 std::string source_id_in_origin; | 348 std::string source_id_in_origin; |
| 349 GURL origin(GURL("http://www.google.com/").GetOrigin()); | 349 GURL origin(GURL("http://www.google.com/").GetOrigin()); |
| 350 GetIDInOrigin(profile()->GetResourceContext(), | 350 GetIDInOrigin(profile()->GetResourceContext(), |
| 351 origin, | 351 origin, |
| 352 raw_device_id, | 352 raw_device_id, |
| 353 &source_id_in_origin); | 353 &source_id_in_origin); |
| 354 | 354 |
| 355 base::ListValue parameters; | 355 base::ListValue parameters; |
| 356 parameters.AppendString(origin.spec()); | 356 parameters.AppendString(origin.spec()); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16("failure")); | 433 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16("failure")); |
| 434 base::string16 result = title_watcher.WaitAndGetTitle(); | 434 base::string16 result = title_watcher.WaitAndGetTitle(); |
| 435 EXPECT_EQ(base::ASCIIToUTF16("success"), result); | 435 EXPECT_EQ(base::ASCIIToUTF16("success"), result); |
| 436 | 436 |
| 437 g_browser_process->webrtc_log_uploader()->OverrideUploadWithBufferForTesting( | 437 g_browser_process->webrtc_log_uploader()->OverrideUploadWithBufferForTesting( |
| 438 NULL); | 438 NULL); |
| 439 } | 439 } |
| 440 #endif // BUILDFLAG(ENABLE_HANGOUT_SERVICES_EXTENSION) | 440 #endif // BUILDFLAG(ENABLE_HANGOUT_SERVICES_EXTENSION) |
| 441 | 441 |
| 442 } // namespace extensions | 442 } // namespace extensions |
| OLD | NEW |