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

Unified Diff: content/browser/media/media_internals_unittest.cc

Issue 643343004: Video Capture Capabilities available on chrome://media-internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated unit test 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/media/media_internals_proxy.cc ('k') | content/browser/resources/media/client_renderer.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/media/media_internals_unittest.cc
diff --git a/content/browser/media/media_internals_unittest.cc b/content/browser/media/media_internals_unittest.cc
index 8d038e12537681e41c8b197a6cfeb403261ed81c..cb3d15cce38557a163a9d94adef3b8ea4ce00d49 100644
--- a/content/browser/media/media_internals_unittest.cc
+++ b/content/browser/media/media_internals_unittest.cc
@@ -31,8 +31,11 @@ class MediaInternalsTestBase {
protected:
// Extracts and deserializes the JSON update data; merges into |update_data_|.
void UpdateCallbackImpl(const base::string16& update) {
- // Each update string looks like "<JavaScript Function Name>({<JSON>});", to
- // use the JSON reader we need to strip out the JavaScript code.
+ // Each update string looks like "<JavaScript Function Name>({<JSON>});"
+ // or for video capabilities: "<JavaScript Function Name>([{<JSON>}]);".
mcasas 2014/10/15 13:54:42 <JavaScript Function Name>([{<JSON>}]); is repeate
burnik 2014/10/15 14:21:57 Look more closely.
+ // In the second case we will be able to extract the dictionary if it is the
+ // only member of the list.
+ // To use the JSON reader we need to strip out the JS function name and ().
std::string utf8_update = base::UTF16ToUTF8(update);
const std::string::size_type first_brace = utf8_update.find('{');
const std::string::size_type last_brace = utf8_update.rfind('}');
@@ -62,6 +65,21 @@ class MediaInternalsTestBase {
ExpectString("status", expected_value);
}
+ void ExpectListOfStrings(const std::string& key,
+ base::ListValue * expected_list){
mcasas 2014/10/15 13:54:42 const base::ListValue& ? Also, method const.
burnik 2014/10/15 14:21:57 Done.
+ base::ListValue * actual_list;
+ ASSERT_TRUE(update_data_.GetList(key, &actual_list));
+ const size_t expected_size = expected_list->GetSize();
+ const size_t actual_size = actual_list->GetSize();
+ ASSERT_EQ(expected_size, actual_size);
+ for (size_t i = 0; i < expected_size; ++i) {
+ std::string expected_value, actual_value;
+ ASSERT_TRUE(expected_list->GetString(i, &expected_value));
+ ASSERT_TRUE(actual_list->GetString(i, &actual_value));
+ EXPECT_EQ(expected_value, actual_value);
+ }
+ }
+
const content::TestBrowserThreadBundle thread_bundle_;
base::DictionaryValue update_data_;
content::MediaInternals* const media_internals_;
@@ -72,10 +90,25 @@ class MediaInternalsTestBase {
namespace content {
class MediaInternalsVideoCaptureDeviceTest : public testing::Test,
- public MediaInternalsTestBase {};
+ public MediaInternalsTestBase {
+ public:
+ MediaInternalsVideoCaptureDeviceTest() :
+ update_cb_(base::Bind(
+ &MediaInternalsVideoCaptureDeviceTest::UpdateCallbackImpl,
+ base::Unretained(this))) {
+ media_internals_->AddUpdateCallback(update_cb_);
+ }
+
+ virtual ~MediaInternalsVideoCaptureDeviceTest() {
+ media_internals_->RemoveUpdateCallback(update_cb_);
+ }
+
+ protected:
+ MediaInternals::UpdateCallback update_cb_;
+};
TEST_F(MediaInternalsVideoCaptureDeviceTest,
- NotifyVideoCaptureDeviceCapabilitiesEnumerated) {
+ NotifyVideoCaptureDeviceCapabilitiesEnumerated) {
const int kWidth = 1280;
const int kHeight = 720;
const float kFrameRate = 30.0f;
@@ -100,10 +133,28 @@ TEST_F(MediaInternalsVideoCaptureDeviceTest,
media::VideoCaptureDeviceInfos device_infos{};
device_infos.push_back(device_info);
- // TODO(mcasas): Listen for the serialised version of |device_infos| and
- // check its content using ExpectInt(), ExpectString(), after RunUntilIdle().
+ // When updating video capture capabilities, the update will serialize
+ // a JSON array of objects to string. So here, the |UpdateCallbackImpl| will
+ // deserialize the first object in the array. This means we have to have
+ // exactly one device_info in the |device_infos|.
media_internals_->UpdateVideoCaptureDeviceCapabilities(device_infos);
base::RunLoop().RunUntilIdle();
+
+#if defined(OS_LINUX) || defined(OS_CHROMEOS)
+ ExpectString("id", "/dev/dummy");
+#else
+ ExpectString("id", "dummy");
+#endif
+ ExpectString("name", "dummy");
+ scoped_ptr<base::ListValue> expected_list(new base::ListValue());
+ expected_list->AppendString(
+ "resolution: 1280x720, fps: 30.000000, pixel format: I420");
mcasas 2014/10/15 13:54:42 Prefer to compose this on the fly calling format_h
burnik 2014/10/15 14:21:57 Done.
+ ExpectListOfStrings("formats", expected_list.get());
+#if defined(OS_MACOSX)
+ ExpectInteger("captureApi", media::VideoCaptureDevice::Name::QTKIT);
+#elif defined(OS_WIN)
+ ExpectInteger("captureApi", media::VideoCaptureDevice::Name::DIRECT_SHOW);
+#endif
}
class MediaInternalsAudioLogTest
« no previous file with comments | « content/browser/media/media_internals_proxy.cc ('k') | content/browser/resources/media/client_renderer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698