Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: content/browser/media/media_internals_unittest.cc

Issue 616833004: chrome://media-internals: update MediaInternals when devices capabilities are enumerated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: FakeVCDFactory needs to specify capture API for Win. Linux/CrOs MediaInternalsVideoCaptureDeviceTes… Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 kTestDeviceID[] = "test-device-id"; 19 const char kTestDeviceID[] = "test-device-id";
20 } // namespace
21 20
22 namespace content { 21 // This class encapsulates a MediaInternals reference. It also has some useful
23 22 // methods to receive a callback, deserialize its associated data and expect
24 class MediaInternalsTest 23 // integer/string values.
25 : public testing::TestWithParam<media::AudioLogFactory::AudioComponent> { 24 class MediaInternalsTestBase {
26 public: 25 public:
27 MediaInternalsTest() 26 MediaInternalsTestBase()
28 : media_internals_(MediaInternals::GetInstance()), 27 : media_internals_(content::MediaInternals::GetInstance()) {
29 update_cb_(base::Bind(&MediaInternalsTest::UpdateCallbackImpl,
30 base::Unretained(this))),
31 test_params_(media::AudioParameters::AUDIO_PCM_LINEAR,
32 media::CHANNEL_LAYOUT_MONO,
33 48000,
34 16,
35 128,
36 media::AudioParameters::ECHO_CANCELLER |
37 media::AudioParameters::DUCKING),
38 test_component_(GetParam()),
39 audio_log_(media_internals_->CreateAudioLog(test_component_)) {
40 media_internals_->AddUpdateCallback(update_cb_);
41 } 28 }
42 29 virtual ~MediaInternalsTestBase() {}
43 virtual ~MediaInternalsTest() {
44 media_internals_->RemoveUpdateCallback(update_cb_);
45 }
46 30
47 protected: 31 protected:
48 // Extracts and deserializes the JSON update data; merges into |update_data_|. 32 // Extracts and deserializes the JSON update data; merges into |update_data_|.
49 void UpdateCallbackImpl(const base::string16& update) { 33 void UpdateCallbackImpl(const base::string16& update) {
50 // Each update string looks like "<JavaScript Function Name>({<JSON>});", to 34 // Each update string looks like "<JavaScript Function Name>({<JSON>});", to
51 // use the JSON reader we need to strip out the JavaScript code. 35 // use the JSON reader we need to strip out the JavaScript code.
52 std::string utf8_update = base::UTF16ToUTF8(update); 36 std::string utf8_update = base::UTF16ToUTF8(update);
53 const std::string::size_type first_brace = utf8_update.find('{'); 37 const std::string::size_type first_brace = utf8_update.find('{');
54 const std::string::size_type last_brace = utf8_update.rfind('}'); 38 const std::string::size_type last_brace = utf8_update.rfind('}');
55 scoped_ptr<base::Value> output_value(base::JSONReader::Read( 39 scoped_ptr<base::Value> output_value(base::JSONReader::Read(
56 utf8_update.substr(first_brace, last_brace - first_brace + 1))); 40 utf8_update.substr(first_brace, last_brace - first_brace + 1)));
57 CHECK(output_value); 41 CHECK(output_value);
58 42
59 base::DictionaryValue* output_dict = NULL; 43 base::DictionaryValue* output_dict = NULL;
60 CHECK(output_value->GetAsDictionary(&output_dict)); 44 CHECK(output_value->GetAsDictionary(&output_dict));
61 update_data_.MergeDictionary(output_dict); 45 update_data_.MergeDictionary(output_dict);
62 } 46 }
63 47
64 void ExpectInt(const std::string& key, int expected_value) { 48 void ExpectInt(const std::string& key, int expected_value) const {
65 int actual_value = 0; 49 int actual_value = 0;
66 ASSERT_TRUE(update_data_.GetInteger(key, &actual_value)); 50 ASSERT_TRUE(update_data_.GetInteger(key, &actual_value));
67 EXPECT_EQ(expected_value, actual_value); 51 EXPECT_EQ(expected_value, actual_value);
68 } 52 }
69 53
70 void ExpectString(const std::string& key, const std::string& expected_value) { 54 void ExpectString(const std::string& key,
55 const std::string& expected_value) const {
71 std::string actual_value; 56 std::string actual_value;
72 ASSERT_TRUE(update_data_.GetString(key, &actual_value)); 57 ASSERT_TRUE(update_data_.GetString(key, &actual_value));
73 EXPECT_EQ(expected_value, actual_value); 58 EXPECT_EQ(expected_value, actual_value);
74 } 59 }
75 60
76 void ExpectStatus(const std::string& expected_value) { 61 void ExpectStatus(const std::string& expected_value) const {
77 ExpectString("status", expected_value); 62 ExpectString("status", expected_value);
78 } 63 }
79 64
80 TestBrowserThreadBundle thread_bundle_; 65 const content::TestBrowserThreadBundle thread_bundle_;
81 MediaInternals* const media_internals_; 66 base::DictionaryValue update_data_;
67 content::MediaInternals* const media_internals_;
68 };
69
70 } // namespace
71
72 namespace content {
73
74 class MediaInternalsVideoCaptureDeviceTest : public testing::Test,
75 public MediaInternalsTestBase {};
76
77 TEST_F(MediaInternalsVideoCaptureDeviceTest,
78 NotifyVideoCaptureDeviceCapabilitiesEnumerated) {
79 const int kWidth = 1280;
80 const int kHeight = 720;
81 const float kFrameRate = 30.0f;
82 const media::VideoPixelFormat kPixelFormat = media::PIXEL_FORMAT_I420;
83 const media::VideoCaptureFormat format_hd({kWidth, kHeight},
84 kFrameRate, kPixelFormat);
85 media::VideoCaptureFormats formats{};
86 formats.push_back(format_hd);
87 const media::VideoCaptureDeviceInfo device_info(
88 #if defined(OS_MACOSX)
89 media::VideoCaptureDevice::Name("dummy", "dummy",
90 media::VideoCaptureDevice::Name::QTKIT),
91 #elif defined(OS_WIN)
92 media::VideoCaptureDevice::Name("dummy", "dummy",
93 media::VideoCaptureDevice::Name::DIRECT_SHOW),
94 #elif defined(OS_LINUX) || defined(OS_CHROMEOS)
95 media::VideoCaptureDevice::Name("dummy", "/dev/dummy"),
96 #else
97 media::VideoCaptureDevice::Name("dummy", "dummy"),
98 #endif
99 formats);
100 media::VideoCaptureDeviceInfos device_infos{};
101 device_infos.push_back(device_info);
102
103 // TODO(mcasas): Listen for the serialised version of |device_infos| and
104 // check its content using ExpectInt(), ExpectString(), after RunUntilIdle().
105 media_internals_->UpdateVideoCaptureDeviceCapabilities(device_infos);
106 base::RunLoop().RunUntilIdle();
107 }
108
109 class MediaInternalsAudioLogTest
110 : public MediaInternalsTestBase,
111 public testing::TestWithParam<media::AudioLogFactory::AudioComponent> {
112 public:
113 MediaInternalsAudioLogTest() :
114 update_cb_(base::Bind(&MediaInternalsAudioLogTest::UpdateCallbackImpl,
115 base::Unretained(this))),
116 test_params_(media::AudioParameters::AUDIO_PCM_LINEAR,
117 media::CHANNEL_LAYOUT_MONO,
118 48000,
119 16,
120 128,
121 media::AudioParameters::ECHO_CANCELLER |
122 media::AudioParameters::DUCKING),
123 test_component_(GetParam()),
124 audio_log_(media_internals_->CreateAudioLog(test_component_)) {
125 media_internals_->AddUpdateCallback(update_cb_);
126 }
127
128 virtual ~MediaInternalsAudioLogTest() {
129 media_internals_->RemoveUpdateCallback(update_cb_);
130 }
131
132 protected:
82 MediaInternals::UpdateCallback update_cb_; 133 MediaInternals::UpdateCallback update_cb_;
83 base::DictionaryValue update_data_;
84 const media::AudioParameters test_params_; 134 const media::AudioParameters test_params_;
85 const media::AudioLogFactory::AudioComponent test_component_; 135 const media::AudioLogFactory::AudioComponent test_component_;
86 scoped_ptr<media::AudioLog> audio_log_; 136 scoped_ptr<media::AudioLog> audio_log_;
87 }; 137 };
88 138
89 TEST_P(MediaInternalsTest, AudioLogCreateStartStopErrorClose) { 139 TEST_P(MediaInternalsAudioLogTest, AudioLogCreateStartStopErrorClose) {
90 audio_log_->OnCreated( 140 audio_log_->OnCreated(kTestComponentID, test_params_, kTestDeviceID);
91 kTestComponentID, test_params_, kTestDeviceID);
92 base::RunLoop().RunUntilIdle(); 141 base::RunLoop().RunUntilIdle();
93 142
94 ExpectString("channel_layout", 143 ExpectString("channel_layout",
95 media::ChannelLayoutToString(test_params_.channel_layout())); 144 media::ChannelLayoutToString(test_params_.channel_layout()));
96 ExpectInt("sample_rate", test_params_.sample_rate()); 145 ExpectInt("sample_rate", test_params_.sample_rate());
97 ExpectInt("frames_per_buffer", test_params_.frames_per_buffer()); 146 ExpectInt("frames_per_buffer", test_params_.frames_per_buffer());
98 ExpectInt("channels", test_params_.channels()); 147 ExpectInt("channels", test_params_.channels());
99 ExpectString("effects", "ECHO_CANCELLER | DUCKING"); 148 ExpectString("effects", "ECHO_CANCELLER | DUCKING");
100 ExpectString("device_id", kTestDeviceID); 149 ExpectString("device_id", kTestDeviceID);
101 ExpectInt("component_id", kTestComponentID); 150 ExpectInt("component_id", kTestComponentID);
(...skipping 17 matching lines...) Expand all
119 audio_log_->OnError(kTestComponentID); 168 audio_log_->OnError(kTestComponentID);
120 base::RunLoop().RunUntilIdle(); 169 base::RunLoop().RunUntilIdle();
121 ExpectString(kErrorKey, "true"); 170 ExpectString(kErrorKey, "true");
122 171
123 // Verify OnClosed(). 172 // Verify OnClosed().
124 audio_log_->OnClosed(kTestComponentID); 173 audio_log_->OnClosed(kTestComponentID);
125 base::RunLoop().RunUntilIdle(); 174 base::RunLoop().RunUntilIdle();
126 ExpectStatus("closed"); 175 ExpectStatus("closed");
127 } 176 }
128 177
129 TEST_P(MediaInternalsTest, AudioLogCreateClose) { 178 TEST_P(MediaInternalsAudioLogTest, AudioLogCreateClose) {
130 audio_log_->OnCreated( 179 audio_log_->OnCreated(kTestComponentID, test_params_, kTestDeviceID);
131 kTestComponentID, test_params_, kTestDeviceID);
132 base::RunLoop().RunUntilIdle(); 180 base::RunLoop().RunUntilIdle();
133 ExpectStatus("created"); 181 ExpectStatus("created");
134 182
135 audio_log_->OnClosed(kTestComponentID); 183 audio_log_->OnClosed(kTestComponentID);
136 base::RunLoop().RunUntilIdle(); 184 base::RunLoop().RunUntilIdle();
137 ExpectStatus("closed"); 185 ExpectStatus("closed");
138 } 186 }
139 187
140 INSTANTIATE_TEST_CASE_P( 188 INSTANTIATE_TEST_CASE_P(
141 MediaInternalsTest, MediaInternalsTest, testing::Values( 189 MediaInternalsAudioLogTest, MediaInternalsAudioLogTest, testing::Values(
142 media::AudioLogFactory::AUDIO_INPUT_CONTROLLER, 190 media::AudioLogFactory::AUDIO_INPUT_CONTROLLER,
143 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER, 191 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER,
144 media::AudioLogFactory::AUDIO_OUTPUT_STREAM)); 192 media::AudioLogFactory::AUDIO_OUTPUT_STREAM));
145 193
146 } // namespace content 194 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/media_internals_proxy.cc ('k') | content/browser/renderer_host/media/video_capture_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698