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

Unified Diff: content/browser/shape_detection/shape_detection_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, 10 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: content/browser/shape_detection/shape_detection_browsertest.cc
diff --git a/content/browser/shapedetection/shapedetection_browsertest.cc b/content/browser/shape_detection/shape_detection_browsertest.cc
similarity index 33%
rename from content/browser/shapedetection/shapedetection_browsertest.cc
rename to content/browser/shape_detection/shape_detection_browsertest.cc
index dd9f4ef546eaf7e366d6b85f19896a32335c11c7..8eb87b5f7e3d20d02f7326e2f95f692b0b512fc6 100644
--- a/content/browser/shapedetection/shapedetection_browsertest.cc
+++ b/content/browser/shape_detection/shape_detection_browsertest.cc
@@ -8,86 +8,111 @@
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
+#include "ui/gl/gl_switches.h"
+
+using base::CommandLine;
namespace content {
-// TODO(xianglu): Enable other platforms support. https://crbug.com/646083
+namespace {
+
+const char kShapeDetectionTestHtml[] = "/media/shape_detection_test.html";
+
+struct TestParameters {
+ const std::string detector_name;
+ const std::string image_path;
+ const std::vector<std::vector<float>>& expected_bounding_boxes;
+} const kTestParameters[] = {
+ {"FaceDetector", "/blank.jpg", std::vector<std::vector<float>>{}},
+ {"FaceDetector",
+ "/single_face.jpg",
#if defined(OS_ANDROID)
-#define MAYBE_ShapeDetectionBrowserTest ShapeDetectionBrowserTest
+ {{23, 20, 42, 42}}
#else
-#define MAYBE_ShapeDetectionBrowserTest DISABLED_ShapeDetectionBrowserTest
+ {{23, 26, 42, 42}}
#endif
+ },
+};
-namespace {
-
-const char kFaceDetectionTestHtml[] = "/media/face_detection_test.html";
+std::ostream& operator<<(std::ostream& out,
+ const struct TestParameters& parameters) {
+ out << parameters.detector_name << " running on: " << parameters.image_path;
+ return out;
+}
} // namespace
// This class contains content_browsertests for Shape Detection API, which
-// allows for generating bounding boxes in still images.
-class MAYBE_ShapeDetectionBrowserTest : public ContentBrowserTest {
+// detect features (Faces, QR/Barcodes, etc) in still or moving images.
+class ShapeDetectionBrowserTest
+ : public ContentBrowserTest,
+ public ::testing::WithParamInterface<struct TestParameters> {
public:
void SetUpCommandLine(base::CommandLine* command_line) override {
- // Flag to enable ShapeDetection and DOMRect API.
- base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ // Flags to enable ShapeDetection and DOMRect API.
+ CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kEnableBlinkFeatures, "ShapeDetection, GeometryInterfaces");
}
protected:
- void RunDetectFacesOnImageUrl(
+ void RunDetectShapesOnImage(
+ const std::string& detector_name,
const std::string& image_path,
- const std::vector<std::vector<float>>& expected_results) {
+ const std::vector<std::vector<float>>& expected_bounding_boxes) {
ASSERT_TRUE(embedded_test_server()->Start());
- const GURL html_url(embedded_test_server()->GetURL(kFaceDetectionTestHtml));
+ const GURL html_url(
+ embedded_test_server()->GetURL(kShapeDetectionTestHtml));
const GURL image_url(embedded_test_server()->GetURL(image_path));
NavigateToURL(shell(), html_url);
- const std::string js_command =
- "detectFacesOnImageUrl('" + image_url.spec() + "')";
+ const std::string js_command = "detectShapesOnImageUrl('" + detector_name +
+ "', '" + image_url.spec() + "')";
std::string response_string;
ASSERT_TRUE(
ExecuteScriptAndExtractString(shell(), js_command, &response_string));
base::StringTokenizer outer_tokenizer(response_string, "#");
- std::vector<std::vector<float>> results;
+ std::vector<std::vector<float>> detected_bounding_boxes;
while (outer_tokenizer.GetNext()) {
std::string s = outer_tokenizer.token().c_str();
- std::vector<float> res;
+ std::vector<float> bounding_box;
base::StringTokenizer inner_tokenizer(s, ",");
while (inner_tokenizer.GetNext())
- res.push_back(atof(inner_tokenizer.token().c_str()));
- results.push_back(res);
+ bounding_box.push_back(atof(inner_tokenizer.token().c_str()));
+ detected_bounding_boxes.push_back(bounding_box);
}
- ASSERT_EQ(expected_results.size(), results.size()) << "Number of faces";
- for (size_t face_id = 0; face_id < results.size(); ++face_id) {
- const std::vector<float> expected_result = expected_results[face_id];
- const std::vector<float> result = results[face_id];
- for (size_t i = 0; i < 4; ++i)
- EXPECT_NEAR(expected_result[i], result[i], 2) << "At index " << i;
+ ASSERT_EQ(expected_bounding_boxes.size(), detected_bounding_boxes.size());
+ for (size_t shape_id = 0; shape_id < detected_bounding_boxes.size();
+ ++shape_id) {
+ const auto expected_bounding_box = expected_bounding_boxes[shape_id];
+ const auto detected_bounding_box = detected_bounding_boxes[shape_id];
+ for (size_t i = 0; i < 4; ++i) {
+ EXPECT_NEAR(expected_bounding_box[i], detected_bounding_box[i], 2)
+ << ", index " << i;
+ }
}
}
};
-IN_PROC_BROWSER_TEST_F(MAYBE_ShapeDetectionBrowserTest,
- DetectFacesOnImageWithNoFaces) {
- const std::string image_path = "/blank.jpg";
- const std::vector<std::vector<float>> expected_empty_results;
- RunDetectFacesOnImageUrl(image_path, expected_empty_results);
-}
-
-IN_PROC_BROWSER_TEST_F(MAYBE_ShapeDetectionBrowserTest,
- DetectFacesOnImageWithOneFace) {
- const std::string image_path = "/single_face.jpg";
-#if defined(OS_ANDROID)
- const std::vector<std::vector<float>> expected_results{
- {68.640625, 102.96875, 171.5625, 171.5625}};
+// TODO(https://crbug.com/659138): Enable the test on other platforms.
+#if defined(OS_ANDROID) || defined(OS_MACOSX)
+#define MAYBE_DetectShapesInImage DetectShapesInImage
#else
- const std::vector<std::vector<float>> expected_results;
+#define MAYBE_DetectShapesInImage DISABLED_DetectShapesInImage
#endif
- RunDetectFacesOnImageUrl(image_path, expected_results);
+IN_PROC_BROWSER_TEST_P(ShapeDetectionBrowserTest, MAYBE_DetectShapesInImage) {
+ // Face detection needs GPU infrastructure.
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGpuInTests))
+ return;
+
+ RunDetectShapesOnImage(GetParam().detector_name, GetParam().image_path,
+ GetParam().expected_bounding_boxes);
}
+INSTANTIATE_TEST_CASE_P(,
+ ShapeDetectionBrowserTest,
+ testing::ValuesIn(kTestParameters));
+
} // namespace content
« no previous file with comments | « chrome/test/data/android/text_detection.html ('k') | content/browser/shapedetection/shapedetection_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698