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

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

Issue 2711893003: Shape detection: moar content_browsertests (face, qr/barcode) (Closed)
Patch Set: Make initialization of std::vector<std::vector<float>> explicit to avoid 'error: chosen constructor… Created 3 years, 9 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 | « content/browser/shape_detection/shape_detection_browsertest.cc ('k') | 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 support. https://crbug.com/646083
15 #if defined(OS_ANDROID)
16 #define MAYBE_ShapeDetectionBrowserTest ShapeDetectionBrowserTest
17 #else
18 #define MAYBE_ShapeDetectionBrowserTest DISABLED_ShapeDetectionBrowserTest
19 #endif
20
21 namespace {
22
23 const char kFaceDetectionTestHtml[] = "/media/face_detection_test.html";
24
25 } // namespace
26
27 // This class contains content_browsertests for Shape Detection API, which
28 // allows for generating bounding boxes in still images.
29 class MAYBE_ShapeDetectionBrowserTest : public ContentBrowserTest {
30 public:
31 void SetUpCommandLine(base::CommandLine* command_line) override {
32 // Flag to enable ShapeDetection and DOMRect API.
33 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
34 switches::kEnableBlinkFeatures, "ShapeDetection, GeometryInterfaces");
35 }
36
37 protected:
38 void RunDetectFacesOnImageUrl(
39 const std::string& image_path,
40 const std::vector<std::vector<float>>& expected_results) {
41 ASSERT_TRUE(embedded_test_server()->Start());
42
43 const GURL html_url(embedded_test_server()->GetURL(kFaceDetectionTestHtml));
44 const GURL image_url(embedded_test_server()->GetURL(image_path));
45 NavigateToURL(shell(), html_url);
46 const std::string js_command =
47 "detectFacesOnImageUrl('" + image_url.spec() + "')";
48 std::string response_string;
49 ASSERT_TRUE(
50 ExecuteScriptAndExtractString(shell(), js_command, &response_string));
51
52 base::StringTokenizer outer_tokenizer(response_string, "#");
53 std::vector<std::vector<float>> results;
54 while (outer_tokenizer.GetNext()) {
55 std::string s = outer_tokenizer.token().c_str();
56 std::vector<float> res;
57 base::StringTokenizer inner_tokenizer(s, ",");
58 while (inner_tokenizer.GetNext())
59 res.push_back(atof(inner_tokenizer.token().c_str()));
60 results.push_back(res);
61 }
62
63 ASSERT_EQ(expected_results.size(), results.size()) << "Number of faces";
64 for (size_t face_id = 0; face_id < results.size(); ++face_id) {
65 const std::vector<float> expected_result = expected_results[face_id];
66 const std::vector<float> result = results[face_id];
67 for (size_t i = 0; i < 4; ++i)
68 EXPECT_NEAR(expected_result[i], result[i], 2) << "At index " << i;
69 }
70 }
71 };
72
73 IN_PROC_BROWSER_TEST_F(MAYBE_ShapeDetectionBrowserTest,
74 DetectFacesOnImageWithNoFaces) {
75 const std::string image_path = "/blank.jpg";
76 const std::vector<std::vector<float>> expected_empty_results;
77 RunDetectFacesOnImageUrl(image_path, expected_empty_results);
78 }
79
80 IN_PROC_BROWSER_TEST_F(MAYBE_ShapeDetectionBrowserTest,
81 DetectFacesOnImageWithOneFace) {
82 const std::string image_path = "/single_face.jpg";
83 #if defined(OS_ANDROID)
84 const std::vector<std::vector<float>> expected_results{
85 {68.640625, 102.96875, 171.5625, 171.5625}};
86 #else
87 const std::vector<std::vector<float>> expected_results;
88 #endif
89
90 RunDetectFacesOnImageUrl(image_path, expected_results);
91 }
92
93 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/shape_detection/shape_detection_browsertest.cc ('k') | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698