| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/media/media_internals.h" | 5 #include "content/browser/media/media_internals.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "content/public/test/test_browser_thread_bundle.h" | 12 #include "content/public/test/test_browser_thread_bundle.h" |
| 13 #include "media/audio/audio_parameters.h" | 13 #include "media/audio/audio_parameters.h" |
| 14 #include "media/base/channel_layout.h" | 14 #include "media/base/channel_layout.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 const int kTestComponentID = 0; | 18 const int kTestComponentID = 0; |
| 19 const char kTestInputDeviceID[] = "test-input-id"; | 19 const char kTestDeviceID[] = "test-device-id"; |
| 20 const char kTestOutputDeviceID[] = "test-output-id"; | |
| 21 } // namespace | 20 } // namespace |
| 22 | 21 |
| 23 namespace content { | 22 namespace content { |
| 24 | 23 |
| 25 class MediaInternalsTest | 24 class MediaInternalsTest |
| 26 : public testing::TestWithParam<media::AudioLogFactory::AudioComponent> { | 25 : public testing::TestWithParam<media::AudioLogFactory::AudioComponent> { |
| 27 public: | 26 public: |
| 28 MediaInternalsTest() | 27 MediaInternalsTest() |
| 29 : media_internals_(MediaInternals::GetInstance()), | 28 : media_internals_(MediaInternals::GetInstance()), |
| 30 update_cb_(base::Bind(&MediaInternalsTest::UpdateCallbackImpl, | 29 update_cb_(base::Bind(&MediaInternalsTest::UpdateCallbackImpl, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 MediaInternals* const media_internals_; | 79 MediaInternals* const media_internals_; |
| 81 MediaInternals::UpdateCallback update_cb_; | 80 MediaInternals::UpdateCallback update_cb_; |
| 82 base::DictionaryValue update_data_; | 81 base::DictionaryValue update_data_; |
| 83 const media::AudioParameters test_params_; | 82 const media::AudioParameters test_params_; |
| 84 const media::AudioLogFactory::AudioComponent test_component_; | 83 const media::AudioLogFactory::AudioComponent test_component_; |
| 85 scoped_ptr<media::AudioLog> audio_log_; | 84 scoped_ptr<media::AudioLog> audio_log_; |
| 86 }; | 85 }; |
| 87 | 86 |
| 88 TEST_P(MediaInternalsTest, AudioLogCreateStartStopErrorClose) { | 87 TEST_P(MediaInternalsTest, AudioLogCreateStartStopErrorClose) { |
| 89 audio_log_->OnCreated( | 88 audio_log_->OnCreated( |
| 90 kTestComponentID, test_params_, kTestInputDeviceID, kTestOutputDeviceID); | 89 kTestComponentID, test_params_, kTestDeviceID); |
| 91 base::RunLoop().RunUntilIdle(); | 90 base::RunLoop().RunUntilIdle(); |
| 92 | 91 |
| 93 ExpectString("channel_layout", | 92 ExpectString("channel_layout", |
| 94 media::ChannelLayoutToString(test_params_.channel_layout())); | 93 media::ChannelLayoutToString(test_params_.channel_layout())); |
| 95 ExpectInt("sample_rate", test_params_.sample_rate()); | 94 ExpectInt("sample_rate", test_params_.sample_rate()); |
| 96 ExpectInt("frames_per_buffer", test_params_.frames_per_buffer()); | 95 ExpectInt("frames_per_buffer", test_params_.frames_per_buffer()); |
| 97 ExpectInt("channels", test_params_.channels()); | 96 ExpectInt("channels", test_params_.channels()); |
| 98 ExpectInt("input_channels", test_params_.input_channels()); | 97 ExpectInt("input_channels", test_params_.input_channels()); |
| 99 ExpectString("output_device_id", kTestOutputDeviceID); | 98 ExpectString("device_id", kTestDeviceID); |
| 100 ExpectString("input_device_id", kTestInputDeviceID); | |
| 101 ExpectInt("component_id", kTestComponentID); | 99 ExpectInt("component_id", kTestComponentID); |
| 102 ExpectInt("component_type", test_component_); | 100 ExpectInt("component_type", test_component_); |
| 103 ExpectStatus("created"); | 101 ExpectStatus("created"); |
| 104 | 102 |
| 105 // Verify OnStarted(). | 103 // Verify OnStarted(). |
| 106 audio_log_->OnStarted(kTestComponentID); | 104 audio_log_->OnStarted(kTestComponentID); |
| 107 base::RunLoop().RunUntilIdle(); | 105 base::RunLoop().RunUntilIdle(); |
| 108 ExpectStatus("started"); | 106 ExpectStatus("started"); |
| 109 | 107 |
| 110 // Verify OnStopped(). | 108 // Verify OnStopped(). |
| (...skipping 10 matching lines...) Expand all Loading... |
| 121 ExpectString(kErrorKey, "true"); | 119 ExpectString(kErrorKey, "true"); |
| 122 | 120 |
| 123 // Verify OnClosed(). | 121 // Verify OnClosed(). |
| 124 audio_log_->OnClosed(kTestComponentID); | 122 audio_log_->OnClosed(kTestComponentID); |
| 125 base::RunLoop().RunUntilIdle(); | 123 base::RunLoop().RunUntilIdle(); |
| 126 ExpectStatus("closed"); | 124 ExpectStatus("closed"); |
| 127 } | 125 } |
| 128 | 126 |
| 129 TEST_P(MediaInternalsTest, AudioLogCreateClose) { | 127 TEST_P(MediaInternalsTest, AudioLogCreateClose) { |
| 130 audio_log_->OnCreated( | 128 audio_log_->OnCreated( |
| 131 kTestComponentID, test_params_, kTestInputDeviceID, kTestOutputDeviceID); | 129 kTestComponentID, test_params_, kTestDeviceID); |
| 132 base::RunLoop().RunUntilIdle(); | 130 base::RunLoop().RunUntilIdle(); |
| 133 ExpectStatus("created"); | 131 ExpectStatus("created"); |
| 134 | 132 |
| 135 audio_log_->OnClosed(kTestComponentID); | 133 audio_log_->OnClosed(kTestComponentID); |
| 136 base::RunLoop().RunUntilIdle(); | 134 base::RunLoop().RunUntilIdle(); |
| 137 ExpectStatus("closed"); | 135 ExpectStatus("closed"); |
| 138 } | 136 } |
| 139 | 137 |
| 140 INSTANTIATE_TEST_CASE_P( | 138 INSTANTIATE_TEST_CASE_P( |
| 141 MediaInternalsTest, MediaInternalsTest, testing::Values( | 139 MediaInternalsTest, MediaInternalsTest, testing::Values( |
| 142 media::AudioLogFactory::AUDIO_INPUT_CONTROLLER, | 140 media::AudioLogFactory::AUDIO_INPUT_CONTROLLER, |
| 143 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER, | 141 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER, |
| 144 media::AudioLogFactory::AUDIO_OUTPUT_STREAM)); | 142 media::AudioLogFactory::AUDIO_OUTPUT_STREAM)); |
| 145 | 143 |
| 146 } // namespace content | 144 } // namespace content |
| OLD | NEW |