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

Side by Side Diff: extensions/browser/api/media_perception_private/media_perception_api_manager_unittest.cc

Issue 2791983004: DBus MediaAnalyticsClient and media_perception pb. (Closed)
Patch Set: Upstart process management 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "extensions/browser/api/media_perception_private/media_perception_api_m anager.h"
6
7 #include "chromeos/media_perception/media_perception.pb.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace mpp = extensions::api::media_perception_private;
12
13 namespace extensions {
14
15 namespace {
16 const char kTestDeviceContext[] = "Video camera";
17 } // namespace
18
19 void InitializeFakeFramePerception(mri::FramePerception* frame_perception) {
20 frame_perception->set_frame_id(2);
21 frame_perception->set_frame_width_in_px(3);
22 frame_perception->set_frame_height_in_px(4);
23 frame_perception->set_timestamp(5);
24 mri::Entity* e_one = frame_perception->add_entity();
25 e_one->set_id(6);
26 e_one->set_type(mri::Entity::FACE);
27 e_one->set_confidence(7);
28 mri::Entity* e_two = frame_perception->add_entity();
29 e_two->set_id(8);
30 e_two->set_type(mri::Entity::PERSON);
31 e_two->set_confidence(9);
32 mri::BoundingBox* b_one = e_one->mutable_bounding_box();
33 b_one->mutable_top_left()->set_x(10);
34 b_one->mutable_top_left()->set_y(11);
35 b_one->mutable_bottom_right()->set_x(12);
36 b_one->mutable_bottom_right()->set_y(13);
37 b_one->set_normalized(false);
38 mri::BoundingBox* b_two = e_two->mutable_bounding_box();
39 b_two->mutable_top_left()->set_x(14);
40 b_two->mutable_top_left()->set_y(15);
41 b_two->mutable_bottom_right()->set_x(16);
42 b_two->mutable_bottom_right()->set_y(17);
43 b_two->set_normalized(true);
44 }
45
46 void ValidateFramePerceptionResult(const mpp::FramePerception& fp_result) {
47 EXPECT_EQ(*fp_result.frame_id, 2);
48 EXPECT_EQ(*fp_result.frame_width_in_px, 3);
49 EXPECT_EQ(*fp_result.frame_height_in_px, 4);
50 EXPECT_EQ(*fp_result.timestamp, 5);
51 const auto& e_result_one = (*fp_result.entities)[0];
52 EXPECT_EQ(*e_result_one.id, 6);
53 EXPECT_EQ(*e_result_one.confidence, 7);
54 EXPECT_EQ(e_result_one.type, mpp::ENTITY_TYPE_FACE);
55 const auto& e_result_two = (*fp_result.entities)[1];
56 EXPECT_EQ(*e_result_two.id, 8);
57 EXPECT_EQ(*e_result_two.confidence, 9);
58 EXPECT_EQ(e_result_two.type, mpp::ENTITY_TYPE_PERSON);
59 const auto& b_result_one = *e_result_one.bounding_box;
60 EXPECT_EQ(*(*b_result_one.top_left).x, 10);
61 EXPECT_EQ(*(*b_result_one.top_left).y, 11);
62 EXPECT_EQ(*(*b_result_one.bottom_right).x, 12);
63 EXPECT_EQ(*(*b_result_one.bottom_right).y, 13);
64 EXPECT_FALSE(*b_result_one.normalized);
65 const auto& b_result_two = *e_result_two.bounding_box;
66 EXPECT_EQ(*(*b_result_two.top_left).x, 14);
67 EXPECT_EQ(*(*b_result_two.top_left).y, 15);
68 EXPECT_EQ(*(*b_result_two.bottom_right).x, 16);
69 EXPECT_EQ(*(*b_result_two.bottom_right).y, 17);
70 EXPECT_TRUE(*b_result_two.normalized);
71 }
72 // Verifies that the data is converted successfully and as expected in each of
73 // these cases.
74
75 TEST(MediaPerceptionAPIManagerTest, MediaPerceptionProtoToIdl) {
76 mri::MediaPerception media_perception;
77 // Fill in fake values for the media_perception proto.
78 media_perception.set_timestamp(1);
79 mri::FramePerception* frame_perception =
80 media_perception.add_frame_perception();
81 InitializeFakeFramePerception(frame_perception);
82 mpp::MediaPerception mp_result = MediaPerceptionProtoToIdl(media_perception);
83 EXPECT_EQ(*mp_result.timestamp, 1);
84 const auto& fp_result = (*mp_result.frame_perceptions)[0];
85 ValidateFramePerceptionResult(fp_result);
86 }
87
88 TEST(MediaPerceptionAPIManagerTest, DiagnosticsProtoToIdl) {
89 const int kNumSamples = 3;
90 mri::Diagnostics diagnostics;
91 for (int i = 0; i < kNumSamples; i++) {
92 mri::PerceptionSample* perception_sample =
93 diagnostics.add_perception_sample();
94 mri::FramePerception* frame_perception =
95 perception_sample->mutable_frame_perception();
96 InitializeFakeFramePerception(frame_perception);
97 // TODO(lasoren): Test with PerceptionSample protos that have image data.
98 }
99 mpp::Diagnostics d_result = DiagnosticsProtoToIdl(diagnostics);
100 ASSERT_THAT(*d_result.perception_samples, testing::SizeIs(kNumSamples));
101 for (int i = 0; i < kNumSamples; i++) {
102 const auto& ps_result = (*d_result.perception_samples)[i];
103 const auto& fp_result = (*ps_result.frame_perception);
104 ValidateFramePerceptionResult(fp_result);
105 }
106 }
107
108 TEST(MediaPerceptionAPIManagerTest, StateProtoToIdl) {
109 mri::State state;
110 state.set_status(mri::State::RUNNING);
111 mpp::State s_result = StateProtoToIdl(state);
112 EXPECT_EQ(s_result.status, mpp::STATUS_RUNNING);
113
114 state.set_status(mri::State::STARTED);
115 state.set_device_context(kTestDeviceContext);
116 s_result = StateProtoToIdl(state);
117 EXPECT_EQ(s_result.status, mpp::STATUS_STARTED);
118 EXPECT_EQ(*s_result.device_context, kTestDeviceContext);
119 }
120
121 TEST(MediaPerceptionAPIManagerTest, StateIdlToProto) {
122 mpp::State state;
123 state.status = mpp::STATUS_UNINITIALIZED;
124 mri::State s_proto = StateIdlToProto(state);
125 EXPECT_EQ(s_proto.status(), mri::State::UNINITIALIZED);
126 EXPECT_FALSE(s_proto.has_device_context());
127
128 state.status = mpp::STATUS_SUSPENDED;
129 state.device_context.reset(new std::string(kTestDeviceContext));
130 s_proto = StateIdlToProto(state);
131 EXPECT_EQ(s_proto.status(), mri::State::SUSPENDED);
132 EXPECT_EQ(s_proto.device_context(), kTestDeviceContext);
133 }
134
135 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698