| 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 "base/json/json_writer.h" | 5 #include "base/json/json_writer.h" |
| 6 #include "base/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 void AppendTabIdToRequestInfo(base::ListValue* params, int tab_id) { | 87 void AppendTabIdToRequestInfo(base::ListValue* params, int tab_id) { |
| 88 base::DictionaryValue* request_info = new base::DictionaryValue(); | 88 base::DictionaryValue* request_info = new base::DictionaryValue(); |
| 89 request_info->SetInteger("tabId", tab_id); | 89 request_info->SetInteger("tabId", tab_id); |
| 90 params->Append(request_info); | 90 params->Append(request_info); |
| 91 } | 91 } |
| 92 | 92 |
| 93 std::string InvokeGetActiveSink(int tab_id) { | 93 std::string InvokeGetActiveSink(int tab_id) { |
| 94 base::ListValue parameters; | 94 base::ListValue parameters; |
| 95 AppendTabIdToRequestInfo(¶meters, tab_id); | 95 AppendTabIdToRequestInfo(¶meters, tab_id); |
| 96 std::string parameter_string; | 96 std::string parameter_string; |
| 97 JSONWriter::Write(¶meters, ¶meter_string); | 97 JSONWriter::Write(parameters, ¶meter_string); |
| 98 | 98 |
| 99 scoped_refptr<WebrtcAudioPrivateGetActiveSinkFunction> function = | 99 scoped_refptr<WebrtcAudioPrivateGetActiveSinkFunction> function = |
| 100 new WebrtcAudioPrivateGetActiveSinkFunction(); | 100 new WebrtcAudioPrivateGetActiveSinkFunction(); |
| 101 function->set_source_url(source_url_); | 101 function->set_source_url(source_url_); |
| 102 scoped_ptr<base::Value> result( | 102 scoped_ptr<base::Value> result( |
| 103 RunFunctionAndReturnSingleResult(function.get(), | 103 RunFunctionAndReturnSingleResult(function.get(), |
| 104 parameter_string, | 104 parameter_string, |
| 105 browser())); | 105 browser())); |
| 106 std::string device_id; | 106 std::string device_id; |
| 107 result->GetAsString(&device_id); | 107 result->GetAsString(&device_id); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 #if !defined(OS_MACOSX) | 173 #if !defined(OS_MACOSX) |
| 174 // http://crbug.com/334579 | 174 // http://crbug.com/334579 |
| 175 IN_PROC_BROWSER_TEST_F(WebrtcAudioPrivateTest, GetSinks) { | 175 IN_PROC_BROWSER_TEST_F(WebrtcAudioPrivateTest, GetSinks) { |
| 176 AudioDeviceNames devices; | 176 AudioDeviceNames devices; |
| 177 GetAudioDeviceNames(&AudioManager::GetAudioOutputDeviceNames, &devices); | 177 GetAudioDeviceNames(&AudioManager::GetAudioOutputDeviceNames, &devices); |
| 178 | 178 |
| 179 base::ListValue* sink_list = NULL; | 179 base::ListValue* sink_list = NULL; |
| 180 scoped_ptr<base::Value> result = InvokeGetSinks(&sink_list); | 180 scoped_ptr<base::Value> result = InvokeGetSinks(&sink_list); |
| 181 | 181 |
| 182 std::string result_string; | 182 std::string result_string; |
| 183 JSONWriter::Write(result.get(), &result_string); | 183 JSONWriter::Write(*result, &result_string); |
| 184 VLOG(2) << result_string; | 184 VLOG(2) << result_string; |
| 185 | 185 |
| 186 EXPECT_EQ(devices.size(), sink_list->GetSize()); | 186 EXPECT_EQ(devices.size(), sink_list->GetSize()); |
| 187 | 187 |
| 188 // Iterate through both lists in lockstep and compare. The order | 188 // Iterate through both lists in lockstep and compare. The order |
| 189 // should be identical. | 189 // should be identical. |
| 190 size_t ix = 0; | 190 size_t ix = 0; |
| 191 AudioDeviceNames::const_iterator it = devices.begin(); | 191 AudioDeviceNames::const_iterator it = devices.begin(); |
| 192 for (; ix < sink_list->GetSize() && it != devices.end(); | 192 for (; ix < sink_list->GetSize() && it != devices.end(); |
| 193 ++ix, ++it) { | 193 ++ix, ++it) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 222 #endif // OS_MACOSX | 222 #endif // OS_MACOSX |
| 223 | 223 |
| 224 // This exercises the case where you have a tab with no active media | 224 // This exercises the case where you have a tab with no active media |
| 225 // stream and try to retrieve the currently active audio sink. | 225 // stream and try to retrieve the currently active audio sink. |
| 226 IN_PROC_BROWSER_TEST_F(WebrtcAudioPrivateTest, GetActiveSinkNoMediaStream) { | 226 IN_PROC_BROWSER_TEST_F(WebrtcAudioPrivateTest, GetActiveSinkNoMediaStream) { |
| 227 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 227 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 228 int tab_id = ExtensionTabUtil::GetTabId(tab); | 228 int tab_id = ExtensionTabUtil::GetTabId(tab); |
| 229 base::ListValue parameters; | 229 base::ListValue parameters; |
| 230 AppendTabIdToRequestInfo(¶meters, tab_id); | 230 AppendTabIdToRequestInfo(¶meters, tab_id); |
| 231 std::string parameter_string; | 231 std::string parameter_string; |
| 232 JSONWriter::Write(¶meters, ¶meter_string); | 232 JSONWriter::Write(parameters, ¶meter_string); |
| 233 | 233 |
| 234 scoped_refptr<WebrtcAudioPrivateGetActiveSinkFunction> function = | 234 scoped_refptr<WebrtcAudioPrivateGetActiveSinkFunction> function = |
| 235 new WebrtcAudioPrivateGetActiveSinkFunction(); | 235 new WebrtcAudioPrivateGetActiveSinkFunction(); |
| 236 function->set_source_url(source_url_); | 236 function->set_source_url(source_url_); |
| 237 scoped_ptr<base::Value> result( | 237 scoped_ptr<base::Value> result( |
| 238 RunFunctionAndReturnSingleResult(function.get(), | 238 RunFunctionAndReturnSingleResult(function.get(), |
| 239 parameter_string, | 239 parameter_string, |
| 240 browser())); | 240 browser())); |
| 241 | 241 |
| 242 std::string result_string; | 242 std::string result_string; |
| 243 JSONWriter::Write(result.get(), &result_string); | 243 JSONWriter::Write(*result, &result_string); |
| 244 EXPECT_EQ("\"\"", result_string); | 244 EXPECT_EQ("\"\"", result_string); |
| 245 } | 245 } |
| 246 | 246 |
| 247 // This exercises the case where you have a tab with no active media | 247 // This exercises the case where you have a tab with no active media |
| 248 // stream and try to set the audio sink. | 248 // stream and try to set the audio sink. |
| 249 IN_PROC_BROWSER_TEST_F(WebrtcAudioPrivateTest, SetActiveSinkNoMediaStream) { | 249 IN_PROC_BROWSER_TEST_F(WebrtcAudioPrivateTest, SetActiveSinkNoMediaStream) { |
| 250 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 250 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 251 int tab_id = ExtensionTabUtil::GetTabId(tab); | 251 int tab_id = ExtensionTabUtil::GetTabId(tab); |
| 252 base::ListValue parameters; | 252 base::ListValue parameters; |
| 253 AppendTabIdToRequestInfo(¶meters, tab_id); | 253 AppendTabIdToRequestInfo(¶meters, tab_id); |
| 254 parameters.AppendString("no such id"); | 254 parameters.AppendString("no such id"); |
| 255 std::string parameter_string; | 255 std::string parameter_string; |
| 256 JSONWriter::Write(¶meters, ¶meter_string); | 256 JSONWriter::Write(parameters, ¶meter_string); |
| 257 | 257 |
| 258 scoped_refptr<WebrtcAudioPrivateSetActiveSinkFunction> function = | 258 scoped_refptr<WebrtcAudioPrivateSetActiveSinkFunction> function = |
| 259 new WebrtcAudioPrivateSetActiveSinkFunction(); | 259 new WebrtcAudioPrivateSetActiveSinkFunction(); |
| 260 function->set_source_url(source_url_); | 260 function->set_source_url(source_url_); |
| 261 std::string error(RunFunctionAndReturnError(function.get(), | 261 std::string error(RunFunctionAndReturnError(function.get(), |
| 262 parameter_string, | 262 parameter_string, |
| 263 browser())); | 263 browser())); |
| 264 EXPECT_EQ(base::StringPrintf("No active stream for tabId %d", tab_id), | 264 EXPECT_EQ(base::StringPrintf("No active stream for tabId %d", tab_id), |
| 265 error); | 265 error); |
| 266 } | 266 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 292 for (size_t ix = 0; ix < sink_list->GetSize(); ++ix) { | 292 for (size_t ix = 0; ix < sink_list->GetSize(); ++ix) { |
| 293 base::DictionaryValue* dict = NULL; | 293 base::DictionaryValue* dict = NULL; |
| 294 sink_list->GetDictionary(ix, &dict); | 294 sink_list->GetDictionary(ix, &dict); |
| 295 std::string target_device; | 295 std::string target_device; |
| 296 dict->GetString("sinkId", &target_device); | 296 dict->GetString("sinkId", &target_device); |
| 297 | 297 |
| 298 base::ListValue parameters; | 298 base::ListValue parameters; |
| 299 AppendTabIdToRequestInfo(¶meters, tab_id); | 299 AppendTabIdToRequestInfo(¶meters, tab_id); |
| 300 parameters.AppendString(target_device); | 300 parameters.AppendString(target_device); |
| 301 std::string parameter_string; | 301 std::string parameter_string; |
| 302 JSONWriter::Write(¶meters, ¶meter_string); | 302 JSONWriter::Write(parameters, ¶meter_string); |
| 303 | 303 |
| 304 scoped_refptr<WebrtcAudioPrivateSetActiveSinkFunction> function = | 304 scoped_refptr<WebrtcAudioPrivateSetActiveSinkFunction> function = |
| 305 new WebrtcAudioPrivateSetActiveSinkFunction(); | 305 new WebrtcAudioPrivateSetActiveSinkFunction(); |
| 306 function->set_source_url(source_url_); | 306 function->set_source_url(source_url_); |
| 307 scoped_ptr<base::Value> result(RunFunctionAndReturnSingleResult( | 307 scoped_ptr<base::Value> result(RunFunctionAndReturnSingleResult( |
| 308 function.get(), parameter_string, browser())); | 308 function.get(), parameter_string, browser())); |
| 309 // The function was successful if the above invocation doesn't | 309 // The function was successful if the above invocation doesn't |
| 310 // fail. Just for kicks, also check that it returns no result. | 310 // fail. Just for kicks, also check that it returns no result. |
| 311 EXPECT_EQ(NULL, result.get()); | 311 EXPECT_EQ(NULL, result.get()); |
| 312 | 312 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 338 GURL origin(GURL("http://www.google.com/").GetOrigin()); | 338 GURL origin(GURL("http://www.google.com/").GetOrigin()); |
| 339 GetIDInOrigin(profile()->GetResourceContext(), | 339 GetIDInOrigin(profile()->GetResourceContext(), |
| 340 origin, | 340 origin, |
| 341 raw_device_id, | 341 raw_device_id, |
| 342 &source_id_in_origin); | 342 &source_id_in_origin); |
| 343 | 343 |
| 344 base::ListValue parameters; | 344 base::ListValue parameters; |
| 345 parameters.AppendString(origin.spec()); | 345 parameters.AppendString(origin.spec()); |
| 346 parameters.AppendString(source_id_in_origin); | 346 parameters.AppendString(source_id_in_origin); |
| 347 std::string parameter_string; | 347 std::string parameter_string; |
| 348 JSONWriter::Write(¶meters, ¶meter_string); | 348 JSONWriter::Write(parameters, ¶meter_string); |
| 349 | 349 |
| 350 scoped_ptr<base::Value> result( | 350 scoped_ptr<base::Value> result( |
| 351 RunFunctionAndReturnSingleResult(function.get(), | 351 RunFunctionAndReturnSingleResult(function.get(), |
| 352 parameter_string, | 352 parameter_string, |
| 353 browser())); | 353 browser())); |
| 354 std::string result_string; | 354 std::string result_string; |
| 355 JSONWriter::Write(result.get(), &result_string); | 355 JSONWriter::Write(*result, &result_string); |
| 356 VLOG(2) << "Results: " << result_string; | 356 VLOG(2) << "Results: " << result_string; |
| 357 } | 357 } |
| 358 } | 358 } |
| 359 | 359 |
| 360 IN_PROC_BROWSER_TEST_F(WebrtcAudioPrivateTest, TriggerEvent) { | 360 IN_PROC_BROWSER_TEST_F(WebrtcAudioPrivateTest, TriggerEvent) { |
| 361 WebrtcAudioPrivateEventService* service = | 361 WebrtcAudioPrivateEventService* service = |
| 362 WebrtcAudioPrivateEventService::GetFactoryInstance()->Get(profile()); | 362 WebrtcAudioPrivateEventService::GetFactoryInstance()->Get(profile()); |
| 363 | 363 |
| 364 // Just trigger, without any extension listening. | 364 // Just trigger, without any extension listening. |
| 365 service->OnDevicesChanged(base::SystemMonitor::DEVTYPE_AUDIO_CAPTURE); | 365 service->OnDevicesChanged(base::SystemMonitor::DEVTYPE_AUDIO_CAPTURE); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16("failure")); | 416 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16("failure")); |
| 417 base::string16 result = title_watcher.WaitAndGetTitle(); | 417 base::string16 result = title_watcher.WaitAndGetTitle(); |
| 418 EXPECT_EQ(base::ASCIIToUTF16("success"), result); | 418 EXPECT_EQ(base::ASCIIToUTF16("success"), result); |
| 419 | 419 |
| 420 g_browser_process->webrtc_log_uploader()->OverrideUploadWithBufferForTesting( | 420 g_browser_process->webrtc_log_uploader()->OverrideUploadWithBufferForTesting( |
| 421 NULL); | 421 NULL); |
| 422 } | 422 } |
| 423 #endif // defined(GOOGLE_CHROME_BUILD) || defined(ENABLE_HANGOUT_SERVICES_EXTEN
SION) | 423 #endif // defined(GOOGLE_CHROME_BUILD) || defined(ENABLE_HANGOUT_SERVICES_EXTEN
SION) |
| 424 | 424 |
| 425 } // namespace extensions | 425 } // namespace extensions |
| OLD | NEW |