| 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 14 matching lines...) Expand all Loading... |
| 25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
| 27 #include "extensions/common/permissions/permission_set.h" | 27 #include "extensions/common/permissions/permission_set.h" |
| 28 #include "extensions/common/permissions/permissions_data.h" | 28 #include "extensions/common/permissions/permissions_data.h" |
| 29 #include "media/audio/audio_manager.h" | 29 #include "media/audio/audio_manager.h" |
| 30 #include "media/audio/audio_manager_base.h" | 30 #include "media/audio/audio_manager_base.h" |
| 31 #include "net/test/embedded_test_server/embedded_test_server.h" | 31 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 33 | 33 |
| 34 using base::JSONWriter; | 34 using base::JSONWriter; |
| 35 using content::RenderViewHost; | 35 using content::RenderProcessHost; |
| 36 using content::WebContents; | 36 using content::WebContents; |
| 37 using media::AudioDeviceNames; | 37 using media::AudioDeviceNames; |
| 38 using media::AudioManager; | 38 using media::AudioManager; |
| 39 | 39 |
| 40 namespace extensions { | 40 namespace extensions { |
| 41 | 41 |
| 42 using extension_function_test_utils::RunFunctionAndReturnError; | 42 using extension_function_test_utils::RunFunctionAndReturnError; |
| 43 using extension_function_test_utils::RunFunctionAndReturnSingleResult; | 43 using extension_function_test_utils::RunFunctionAndReturnSingleResult; |
| 44 | 44 |
| 45 class AudioWaitingExtensionTest : public ExtensionApiTest { | 45 class AudioWaitingExtensionTest : public ExtensionApiTest { |
| 46 protected: | 46 protected: |
| 47 void WaitUntilAudioIsPlaying(WebContents* tab) { | 47 void WaitUntilAudioIsPlaying(WebContents* tab) { |
| 48 // Wait for audio to start playing. We gate this on there being one | 48 // Wait for audio to start playing. We gate this on there being one |
| 49 // or more AudioOutputController objects for our tab. | 49 // or more AudioOutputController objects for our tab. |
| 50 bool audio_playing = false; | 50 bool audio_playing = false; |
| 51 for (size_t remaining_tries = 50; remaining_tries > 0; --remaining_tries) { | 51 for (size_t remaining_tries = 50; remaining_tries > 0; --remaining_tries) { |
| 52 tab->GetRenderViewHost()->GetAudioOutputControllers( | 52 tab->GetRenderProcessHost()->GetAudioOutputControllers( |
| 53 base::Bind(OnAudioControllers, &audio_playing)); | 53 base::Bind(OnAudioControllers, &audio_playing)); |
| 54 base::MessageLoop::current()->RunUntilIdle(); | 54 base::MessageLoop::current()->RunUntilIdle(); |
| 55 if (audio_playing) | 55 if (audio_playing) |
| 56 break; | 56 break; |
| 57 | 57 |
| 58 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); | 58 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 if (!audio_playing) | 61 if (!audio_playing) |
| 62 FAIL() << "Audio did not start playing within ~5 seconds."; | 62 FAIL() << "Audio did not start playing within ~5 seconds."; |
| 63 } | 63 } |
| 64 | 64 |
| 65 // Used by the test above to wait until audio is playing. | 65 // Used by the test above to wait until audio is playing. |
| 66 static void OnAudioControllers( | 66 static void OnAudioControllers( |
| 67 bool* audio_playing, | 67 bool* audio_playing, |
| 68 const RenderViewHost::AudioOutputControllerList& list) { | 68 const RenderProcessHost::AudioOutputControllerList& list) { |
| 69 if (!list.empty()) | 69 if (!list.empty()) |
| 70 *audio_playing = true; | 70 *audio_playing = true; |
| 71 } | 71 } |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 class WebrtcAudioPrivateTest : public AudioWaitingExtensionTest { | 74 class WebrtcAudioPrivateTest : public AudioWaitingExtensionTest { |
| 75 public: | 75 public: |
| 76 WebrtcAudioPrivateTest() | 76 WebrtcAudioPrivateTest() |
| 77 : enumeration_event_(false, false) { | 77 : enumeration_event_(false, false) { |
| 78 } | 78 } |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16("failure")); | 410 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16("failure")); |
| 411 base::string16 result = title_watcher.WaitAndGetTitle(); | 411 base::string16 result = title_watcher.WaitAndGetTitle(); |
| 412 EXPECT_EQ(base::ASCIIToUTF16("success"), result); | 412 EXPECT_EQ(base::ASCIIToUTF16("success"), result); |
| 413 | 413 |
| 414 g_browser_process->webrtc_log_uploader()->OverrideUploadWithBufferForTesting( | 414 g_browser_process->webrtc_log_uploader()->OverrideUploadWithBufferForTesting( |
| 415 NULL); | 415 NULL); |
| 416 } | 416 } |
| 417 #endif // defined(GOOGLE_CHROME_BUILD) || defined(ENABLE_HANGOUT_SERVICES_EXTEN
SION) | 417 #endif // defined(GOOGLE_CHROME_BUILD) || defined(ENABLE_HANGOUT_SERVICES_EXTEN
SION) |
| 418 | 418 |
| 419 } // namespace extensions | 419 } // namespace extensions |
| OLD | NEW |