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

Side by Side Diff: content/browser/shapedetection/shapedetection_browsertest.cc

Issue 2419273002: Shape Detection: Add two content browser tests for face detection (Closed)
Patch Set: Approximate comparisons Created 4 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
« no previous file with comments | « no previous file | content/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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 "base/command_line.h"
6 #include "base/strings/string_tokenizer.h"
7 #include "content/public/common/content_switches.h"
8 #include "content/public/test/browser_test_utils.h"
9 #include "content/public/test/content_browser_test.h"
10 #include "content/public/test/content_browser_test_utils.h"
11
12 namespace content {
13
14 // TODO(xianglu): Enable other platforms with support. https://crbug.com/646083
15 #if defined(OS_ANDROID)
16 #define MAYBE_DetectFacesOnImageWithNoFaces DetectFacesOnImageWithNoFaces
17 #define MAYBE_DetectFacesOnImageWithOneFace DetectFacesOnImageWithOneFace
18 #else
19 #define MAYBE_DetectFacesOnImageWithNoFaces DISABLED_DetectFacesOnImageWithNoFac es
20 #define MAYBE_DetectFacesOnImageWithOneFace DISABLED_DetectFacesOnImageWithOneFa ce
21 #endif
22
23 namespace {
24
25 const char kFaceDetectionTestHtml[] = "/media/face_detection_test.html";
26
27 } // namespace
28
29 // This class contains content_browsertests for Shape Detection API, which
30 // allows for generating bounding boxes for faces on still images..
31 class ShapeDetectionBrowserTest : public ContentBrowserTest {
32 public:
33 void SetUpCommandLine(base::CommandLine* command_line) override {
34 // Specific flag to enable ShapeDetection and DOMRect API.
35 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
36 switches::kEnableBlinkFeatures, "ShapeDetection, GeometryInterfaces");
37 }
38
39 protected:
40 void RunDetectFacesOnImageUrl(
41 const std::string& image_path,
42 const std::vector<std::vector<float>>& expected_results) {
43 ASSERT_TRUE(embedded_test_server()->Start());
44
45 const GURL html_url(embedded_test_server()->GetURL(kFaceDetectionTestHtml));
46 const GURL image_url(embedded_test_server()->GetURL(image_path));
47 NavigateToURL(shell(), html_url);
48 const std::string js_command =
49 "detectFacesOnImageUrl('" + image_url.spec() + "')";
50 std::string response_string;
51 ASSERT_TRUE(
52 ExecuteScriptAndExtractString(shell(), js_command, &response_string));
53
54 base::StringTokenizer outer_tokenizer(response_string, "#");
55 std::vector<std::vector<float>> results;
56 while (outer_tokenizer.GetNext()) {
57 std::string s = outer_tokenizer.token().c_str();
58 std::vector<float> res;
59 base::StringTokenizer inner_tokenizer(s, ",");
60 while (inner_tokenizer.GetNext()) {
61 res.push_back(atof(inner_tokenizer.token().c_str()));
62 }
mcasas 2016/10/19 23:41:11 nit: no need for curly brackets {} for one line bo
xianglu 2016/10/20 17:58:48 Done.
63 results.push_back(res);
64 }
65
66 ASSERT_EQ(expected_results.size(), results.size());
mcasas 2016/10/19 23:41:11 Good!
67 for (size_t face_id = 0; face_id < results.size(); face_id++) {
68 std::vector<float> expected_result = expected_results[face_id];
69 std::vector<float> result = results[face_id];
70 for (size_t pram_idx = 0; pram_idx < 4; pram_idx++) {
mcasas 2016/10/19 23:41:11 Micro-nit: try to get used to preincrement the in
xianglu 2016/10/20 17:58:47 Done.
71 // TODO(xianglu): Always verify if EXPECT_FLOAT_EQ is sufficient for
72 // different platforms.
mcasas 2016/10/19 23:41:11 You can also consider using e.g. EXPECT_NEAR(expec
xianglu 2016/10/20 17:58:48 Done.
73 EXPECT_FLOAT_EQ(expected_result[pram_idx], result[pram_idx]);
Reilly Grant (use Gerrit) 2016/10/19 23:48:40 Tip: Add << " at index " << param_index; to the en
xianglu 2016/10/20 17:58:48 Done.
74 }
75 }
76 }
77 };
78
79 IN_PROC_BROWSER_TEST_F(ShapeDetectionBrowserTest,
80 MAYBE_DetectFacesOnImageWithNoFaces) {
81 const std::string image_path = "/blank.jpg";
82 std::vector<std::vector<float>> expected_results;
83 RunDetectFacesOnImageUrl(image_path, expected_results);
84 }
85
86 IN_PROC_BROWSER_TEST_F(ShapeDetectionBrowserTest,
87 MAYBE_DetectFacesOnImageWithOneFace) {
88 const std::string image_path = "/single_face.jpg";
89 std::vector<float> expected_result = {68.640625, 102.96875, 171.5625,
90 171.5625};
mcasas 2016/10/19 23:41:11 nit: const :)
xianglu 2016/10/20 17:58:48 Done.
91 std::vector<std::vector<float>> expected_results = {expected_result};
92 RunDetectFacesOnImageUrl(image_path, expected_results);
93 }
94
95 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698