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

Unified Diff: extensions/browser/api/media_perception_private/conversion_utils_unittest.cc

Issue 2858353002: MediaPerceptionPrivate API impl and testing. (Closed)
Patch Set: Addressing reviewer comments. Created 3 years, 7 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
Index: extensions/browser/api/media_perception_private/conversion_utils_unittest.cc
diff --git a/extensions/browser/api/media_perception_private/conversion_utils_unittest.cc b/extensions/browser/api/media_perception_private/conversion_utils_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..735345ecf10383625dd8351530939d583066ad3f
--- /dev/null
+++ b/extensions/browser/api/media_perception_private/conversion_utils_unittest.cc
@@ -0,0 +1,175 @@
+// Copyright (c) 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/browser/api/media_perception_private/conversion_utils.h"
+
+#include "base/memory/ptr_util.h"
+#include "chromeos/media_perception/media_perception.pb.h"
+#include "testing/gmock/include/gmock/gmock.h"
tbarzic 2017/05/19 20:22:38 do you need gmock?
Luke Sorenson 2017/05/19 21:45:22 Done.
tbarzic 2017/05/22 17:40:56 not done? :)
Luke Sorenson 2017/05/22 18:40:48 Oops, weird definitely remember removing that.
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace media_perception = extensions::api::media_perception_private;
+
+namespace extensions {
+
+namespace {
+
+const char kTestDeviceContext[] = "Video camera";
+
+void InitializeFakeFramePerception(mri::FramePerception* frame_perception) {
+ frame_perception->set_frame_id(2);
+ frame_perception->set_frame_width_in_px(3);
+ frame_perception->set_frame_height_in_px(4);
+ frame_perception->set_timestamp(5);
+
+ mri::Entity* entity_one = frame_perception->add_entity();
+ entity_one->set_id(6);
+ entity_one->set_type(mri::Entity::FACE);
+ entity_one->set_confidence(7);
+
+ mri::Entity* e_two = frame_perception->add_entity();
+ e_two->set_id(8);
+ e_two->set_type(mri::Entity::PERSON);
+ e_two->set_confidence(9);
+
+ mri::BoundingBox* bounding_box_one = entity_one->mutable_bounding_box();
+ bounding_box_one->mutable_top_left()->set_x(10);
+ bounding_box_one->mutable_top_left()->set_y(11);
+ bounding_box_one->mutable_bottom_right()->set_x(12);
+ bounding_box_one->mutable_bottom_right()->set_y(13);
+ bounding_box_one->set_normalized(false);
+
+ mri::BoundingBox* bounding_box_two = e_two->mutable_bounding_box();
+ bounding_box_two->mutable_top_left()->set_x(14);
+ bounding_box_two->mutable_top_left()->set_y(15);
+ bounding_box_two->set_normalized(true);
+}
+
+void ValidateFramePerceptionResult(
+ const media_perception::FramePerception& frame_perception_result) {
+ EXPECT_EQ(*frame_perception_result.frame_id, 2);
+ EXPECT_EQ(*frame_perception_result.frame_width_in_px, 3);
+ EXPECT_EQ(*frame_perception_result.frame_height_in_px, 4);
+ EXPECT_EQ(*frame_perception_result.timestamp, 5);
+
+ ASSERT_EQ(2u, frame_perception_result.entities->size());
+ const auto& entity_result_one = (*frame_perception_result.entities)[0];
+ EXPECT_EQ(*entity_result_one.id, 6);
+ EXPECT_EQ(*entity_result_one.confidence, 7);
+ EXPECT_EQ(entity_result_one.type, media_perception::ENTITY_TYPE_FACE);
+
+ const auto& entity_result_two = (*frame_perception_result.entities)[1];
+ EXPECT_EQ(*entity_result_two.id, 8);
+ EXPECT_EQ(*entity_result_two.confidence, 9);
+ EXPECT_EQ(entity_result_two.type, media_perception::ENTITY_TYPE_PERSON);
+
+ const auto& bounding_box_result_one = *entity_result_one.bounding_box;
tbarzic 2017/05/19 20:22:38 can you move this up with the rest of entity_resul
Luke Sorenson 2017/05/19 21:45:22 Done.
+ EXPECT_EQ(*(*bounding_box_result_one.top_left).x, 10);
tbarzic 2017/05/19 20:22:38 bounding_box_result_one->top_left->x? also, can yo
Luke Sorenson 2017/05/19 21:45:22 Done.
+ EXPECT_EQ(*(*bounding_box_result_one.top_left).y, 11);
+ EXPECT_EQ(*(*bounding_box_result_one.bottom_right).x, 12);
+ EXPECT_EQ(*(*bounding_box_result_one.bottom_right).y, 13);
+ EXPECT_FALSE(*bounding_box_result_one.normalized);
+
+ const auto& bounding_box_result_two = *entity_result_two.bounding_box;
+ EXPECT_EQ(*(*bounding_box_result_two.top_left).x, 14);
+ EXPECT_EQ(*(*bounding_box_result_two.top_left).y, 15);
+ EXPECT_FALSE(bounding_box_result_two.bottom_right);
+ EXPECT_TRUE(*bounding_box_result_two.normalized);
+}
+
+void InitializeFakeImageFrameData(int index, mri::ImageFrame* image_frame) {
+ image_frame->set_width(index);
+ image_frame->set_height(2);
+ image_frame->set_data_length(3);
+ image_frame->set_pixel_data(" ");
+ image_frame->set_format(mri::ImageFrame::JPEG);
+}
+
+void ValidateFakeImageFrameData(
+ int index,
+ const media_perception::ImageFrame& image_frame_result) {
+ EXPECT_EQ(*image_frame_result.width, index);
+ EXPECT_EQ(*image_frame_result.height, 2);
+ EXPECT_EQ(*image_frame_result.data_length, 3);
+ EXPECT_EQ((*image_frame_result.frame).size(), 4ul);
+ EXPECT_EQ(image_frame_result.format, media_perception::IMAGE_FORMAT_JPEG);
+}
+
+} // namespace
+
+// Verifies that the data is converted successfully and as expected in each of
+// these cases.
+
+TEST(MediaPerceptionConversionUtilsTest, MediaPerceptionProtoToIdl) {
+ mri::MediaPerception media_perception;
+ // Fill in fake values for the media_perception proto.
+ media_perception.set_timestamp(1);
+ mri::FramePerception* frame_perception =
+ media_perception.add_frame_perception();
+ InitializeFakeFramePerception(frame_perception);
+ media_perception::MediaPerception media_perception_result =
+ media_perception::MediaPerceptionProtoToIdl(media_perception);
+ EXPECT_EQ(*media_perception_result.timestamp, 1);
+ ASSERT_TRUE(media_perception_result.frame_perceptions);
+ ASSERT_EQ(1u, media_perception_result.frame_perceptions->size());
+ ValidateFramePerceptionResult(
+ media_perception_result.frame_perceptions->at(0));
+}
+
+TEST(MediaPerceptionConversionUtilsTest, DiagnosticsProtoToIdl) {
+ const size_t kNumSamples = 3;
+ mri::Diagnostics diagnostics;
+ for (size_t i = 0; i < kNumSamples; i++) {
+ mri::PerceptionSample* perception_sample =
+ diagnostics.add_perception_sample();
+ mri::FramePerception* frame_perception =
+ perception_sample->mutable_frame_perception();
+ InitializeFakeFramePerception(frame_perception);
+ mri::ImageFrame* image_frame = perception_sample->mutable_image_frame();
+ InitializeFakeImageFrameData(i, image_frame);
+ }
+ media_perception::Diagnostics diagnostics_result =
+ media_perception::DiagnosticsProtoToIdl(diagnostics);
+ ASSERT_EQ(kNumSamples, diagnostics_result.perception_samples->size());
+ for (size_t i = 0; i < kNumSamples; i++) {
+ const media_perception::PerceptionSample& perception_sample_result =
+ (*diagnostics_result.perception_samples)[i];
+ const media_perception::FramePerception& frame_perception_result =
+ (*perception_sample_result.frame_perception);
+ const media_perception::ImageFrame& image_frame_result =
+ (*perception_sample_result.image_frame);
+ ValidateFramePerceptionResult(frame_perception_result);
+ ValidateFakeImageFrameData(i, image_frame_result);
+ }
+}
+
+TEST(MediaPerceptionConversionUtilsTest, StateProtoToIdl) {
+ mri::State state;
+ state.set_status(mri::State::RUNNING);
+ media_perception::State state_result =
+ media_perception::StateProtoToIdl(state);
+ EXPECT_EQ(state_result.status, media_perception::STATUS_RUNNING);
+
+ state.set_status(mri::State::STARTED);
+ state.set_device_context(kTestDeviceContext);
+ state_result = media_perception::StateProtoToIdl(state);
+ EXPECT_EQ(state_result.status, media_perception::STATUS_STARTED);
+ EXPECT_EQ(*state_result.device_context, kTestDeviceContext);
+}
+
+TEST(MediaPerceptionConversionUtilsTest, StateIdlToProto) {
+ media_perception::State state;
+ state.status = media_perception::STATUS_UNINITIALIZED;
+ mri::State state_proto = StateIdlToProto(state);
+ EXPECT_EQ(state_proto.status(), mri::State::UNINITIALIZED);
+ EXPECT_FALSE(state_proto.has_device_context());
+
+ state.status = media_perception::STATUS_SUSPENDED;
+ state.device_context = base::MakeUnique<std::string>(kTestDeviceContext);
+ state_proto = StateIdlToProto(state);
+ EXPECT_EQ(state_proto.status(), mri::State::SUSPENDED);
+ EXPECT_EQ(state_proto.device_context(), kTestDeviceContext);
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698