| 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" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/threading/platform_thread.h" | 16 #include "base/threading/platform_thread.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_privat
e_api.h" | 20 #include "chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_privat
e_api.h" |
| 21 #include "chrome/browser/extensions/component_loader.h" | 21 #include "chrome/browser/extensions/component_loader.h" |
| 22 #include "chrome/browser/extensions/extension_apitest.h" | 22 #include "chrome/browser/extensions/extension_apitest.h" |
| 23 #include "chrome/browser/extensions/extension_function_test_utils.h" | 23 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 24 #include "chrome/browser/extensions/extension_tab_util.h" | 24 #include "chrome/browser/extensions/extension_tab_util.h" |
| 25 #include "chrome/browser/media/webrtc/webrtc_log_uploader.h" | 25 #include "chrome/browser/media/webrtc/webrtc_log_uploader.h" |
| 26 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
| 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 28 #include "chrome/common/features.h" | 29 #include "chrome/common/features.h" |
| 29 #include "chrome/test/base/in_process_browser_test.h" | 30 #include "chrome/test/base/in_process_browser_test.h" |
| 30 #include "chrome/test/base/ui_test_utils.h" | 31 #include "chrome/test/base/ui_test_utils.h" |
| 31 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/media_device_id.h" | 33 #include "content/public/browser/media_device_id.h" |
| 33 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 34 #include "content/public/test/browser_test_utils.h" | 35 #include "content/public/test/browser_test_utils.h" |
| 35 #include "extensions/common/permissions/permission_set.h" | 36 #include "extensions/common/permissions/permission_set.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 } else { | 150 } else { |
| 150 (audio_manager->*EnumerationFunc)(device_descriptions); | 151 (audio_manager->*EnumerationFunc)(device_descriptions); |
| 151 enumeration_event_.Signal(); | 152 enumeration_event_.Signal(); |
| 152 } | 153 } |
| 153 } | 154 } |
| 154 | 155 |
| 155 // Synchronously (from the calling thread's point of view) retrieve the | 156 // Synchronously (from the calling thread's point of view) retrieve the |
| 156 // device id in the |origin| on the IO thread. On return, | 157 // device id in the |origin| on the IO thread. On return, |
| 157 // |id_in_origin| contains the id |raw_device_id| is known by in | 158 // |id_in_origin| contains the id |raw_device_id| is known by in |
| 158 // the origin. | 159 // the origin. |
| 159 void GetIDInOrigin(content::ResourceContext* resource_context, | 160 void GetIDInOrigin(Profile* profile, |
| 160 GURL origin, | 161 GURL origin, |
| 161 const std::string& raw_device_id, | 162 const std::string& raw_device_id, |
| 162 std::string* id_in_origin) { | 163 std::string* id_in_origin) { |
| 163 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | 164 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
| 164 content::BrowserThread::PostTask( | 165 content::BrowserThread::PostTask( |
| 165 content::BrowserThread::UI, FROM_HERE, | 166 content::BrowserThread::UI, FROM_HERE, |
| 166 base::Bind(&WebrtcAudioPrivateTest::GetIDInOrigin, | 167 base::Bind(&WebrtcAudioPrivateTest::GetIDInOrigin, |
| 167 base::Unretained(this), | 168 base::Unretained(this), profile, origin, raw_device_id, |
| 168 resource_context, origin, raw_device_id, id_in_origin)); | 169 id_in_origin)); |
| 169 enumeration_event_.Wait(); | 170 enumeration_event_.Wait(); |
| 170 } else { | 171 } else { |
| 171 *id_in_origin = content::GetHMACForMediaDeviceID( | 172 *id_in_origin = content::GetHMACForMediaDeviceID( |
| 172 resource_context->GetMediaDeviceIDSalt(), url::Origin(origin), | 173 profile->GetMediaDeviceIDSalt(), url::Origin(origin), raw_device_id); |
| 173 raw_device_id); | |
| 174 enumeration_event_.Signal(); | 174 enumeration_event_.Signal(); |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 // Event used to signal completion of enumeration. | 178 // Event used to signal completion of enumeration. |
| 179 base::WaitableEvent enumeration_event_; | 179 base::WaitableEvent enumeration_event_; |
| 180 | 180 |
| 181 GURL source_url_; | 181 GURL source_url_; |
| 182 }; | 182 }; |
| 183 | 183 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 205 ++ix, ++it) { | 205 ++ix, ++it) { |
| 206 base::DictionaryValue* dict = NULL; | 206 base::DictionaryValue* dict = NULL; |
| 207 sink_list->GetDictionary(ix, &dict); | 207 sink_list->GetDictionary(ix, &dict); |
| 208 std::string sink_id; | 208 std::string sink_id; |
| 209 dict->GetString("sinkId", &sink_id); | 209 dict->GetString("sinkId", &sink_id); |
| 210 | 210 |
| 211 std::string expected_id; | 211 std::string expected_id; |
| 212 if (media::AudioDeviceDescription::IsDefaultDevice(it->unique_id)) { | 212 if (media::AudioDeviceDescription::IsDefaultDevice(it->unique_id)) { |
| 213 expected_id = media::AudioDeviceDescription::kDefaultDeviceId; | 213 expected_id = media::AudioDeviceDescription::kDefaultDeviceId; |
| 214 } else { | 214 } else { |
| 215 GetIDInOrigin(profile()->GetResourceContext(), | 215 GetIDInOrigin(profile(), source_url_.GetOrigin(), it->unique_id, |
| 216 source_url_.GetOrigin(), | |
| 217 it->unique_id, | |
| 218 &expected_id); | 216 &expected_id); |
| 219 } | 217 } |
| 220 | 218 |
| 221 EXPECT_EQ(expected_id, sink_id); | 219 EXPECT_EQ(expected_id, sink_id); |
| 222 std::string sink_label; | 220 std::string sink_label; |
| 223 dict->GetString("sinkLabel", &sink_label); | 221 dict->GetString("sinkLabel", &sink_label); |
| 224 EXPECT_EQ(it->device_name, sink_label); | 222 EXPECT_EQ(it->device_name, sink_label); |
| 225 | 223 |
| 226 // TODO(joi): Verify the contents of these once we start actually | 224 // TODO(joi): Verify the contents of these once we start actually |
| 227 // filling them in. | 225 // filling them in. |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 // Try to get an associated sink for each source. | 341 // Try to get an associated sink for each source. |
| 344 for (const auto& device : devices) { | 342 for (const auto& device : devices) { |
| 345 scoped_refptr<WebrtcAudioPrivateGetAssociatedSinkFunction> function = | 343 scoped_refptr<WebrtcAudioPrivateGetAssociatedSinkFunction> function = |
| 346 new WebrtcAudioPrivateGetAssociatedSinkFunction(); | 344 new WebrtcAudioPrivateGetAssociatedSinkFunction(); |
| 347 function->set_source_url(source_url_); | 345 function->set_source_url(source_url_); |
| 348 | 346 |
| 349 std::string raw_device_id = device.unique_id; | 347 std::string raw_device_id = device.unique_id; |
| 350 VLOG(2) << "Trying to find associated sink for device " << raw_device_id; | 348 VLOG(2) << "Trying to find associated sink for device " << raw_device_id; |
| 351 std::string source_id_in_origin; | 349 std::string source_id_in_origin; |
| 352 GURL origin(GURL("http://www.google.com/").GetOrigin()); | 350 GURL origin(GURL("http://www.google.com/").GetOrigin()); |
| 353 GetIDInOrigin(profile()->GetResourceContext(), | 351 GetIDInOrigin(profile(), origin, raw_device_id, &source_id_in_origin); |
| 354 origin, | |
| 355 raw_device_id, | |
| 356 &source_id_in_origin); | |
| 357 | 352 |
| 358 base::ListValue parameters; | 353 base::ListValue parameters; |
| 359 parameters.AppendString(origin.spec()); | 354 parameters.AppendString(origin.spec()); |
| 360 parameters.AppendString(source_id_in_origin); | 355 parameters.AppendString(source_id_in_origin); |
| 361 std::string parameter_string; | 356 std::string parameter_string; |
| 362 JSONWriter::Write(parameters, ¶meter_string); | 357 JSONWriter::Write(parameters, ¶meter_string); |
| 363 | 358 |
| 364 std::unique_ptr<base::Value> result(RunFunctionAndReturnSingleResult( | 359 std::unique_ptr<base::Value> result(RunFunctionAndReturnSingleResult( |
| 365 function.get(), parameter_string, browser())); | 360 function.get(), parameter_string, browser())); |
| 366 std::string result_string; | 361 std::string result_string; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16("failure")); | 424 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16("failure")); |
| 430 base::string16 result = title_watcher.WaitAndGetTitle(); | 425 base::string16 result = title_watcher.WaitAndGetTitle(); |
| 431 EXPECT_EQ(base::ASCIIToUTF16("success"), result); | 426 EXPECT_EQ(base::ASCIIToUTF16("success"), result); |
| 432 | 427 |
| 433 g_browser_process->webrtc_log_uploader()->OverrideUploadWithBufferForTesting( | 428 g_browser_process->webrtc_log_uploader()->OverrideUploadWithBufferForTesting( |
| 434 NULL); | 429 NULL); |
| 435 } | 430 } |
| 436 #endif // BUILDFLAG(ENABLE_HANGOUT_SERVICES_EXTENSION) | 431 #endif // BUILDFLAG(ENABLE_HANGOUT_SERVICES_EXTENSION) |
| 437 | 432 |
| 438 } // namespace extensions | 433 } // namespace extensions |
| OLD | NEW |