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

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: mcasas@ and reillyg@ comments 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
ncarter (slow) 2016/10/20 21:39:31 Might be simpler to do the DISABLED_ trick on the
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 results.push_back(res);
63 }
64
65 ASSERT_EQ(expected_results.size(), results.size()) << "Number of faces";
66 for (size_t face_id = 0; face_id < results.size(); ++face_id) {
67 const std::vector<float> expected_result = expected_results[face_id];
68 const std::vector<float> result = results[face_id];
69 for (size_t i = 0; i < 4; ++i)
70 EXPECT_NEAR(expected_result[i], result[i], 0.1) << "At index " << i;
71 }
72 }
73 };
74
75 IN_PROC_BROWSER_TEST_F(ShapeDetectionBrowserTest,
76 MAYBE_DetectFacesOnImageWithNoFaces) {
77 const std::string image_path = "/blank.jpg";
78 const std::vector<std::vector<float>> expected_results;
79 RunDetectFacesOnImageUrl(image_path, expected_results);
80 }
81
82 IN_PROC_BROWSER_TEST_F(ShapeDetectionBrowserTest,
83 MAYBE_DetectFacesOnImageWithOneFace) {
84 const std::string image_path = "/single_face.jpg";
85 const std::vector<float> expected_result = {68.640625, 102.96875, 171.5625,
86 171.5625};
mcasas 2016/10/20 18:27:40 Nit: indent. (run `git cl format` before uploading
87 const std::vector<std::vector<float>> expected_results = {expected_result};
88 RunDetectFacesOnImageUrl(image_path, expected_results);
89 }
90
91 } // 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