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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/shape_detection/ShapeDetectionTest.java

Issue 2711893003: Shape detection: moar content_browsertests (face, qr/barcode) (Closed)
Patch Set: 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: chrome/android/javatests/src/org/chromium/chrome/browser/shape_detection/ShapeDetectionTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/shape_detection/ShapeDetectionTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/shape_detection/ShapeDetectionTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..8b571ba9a16a3f74a1a9c3bf081c575439835551
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/shape_detection/ShapeDetectionTest.java
@@ -0,0 +1,113 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.shape_detection;
+
+import android.os.StrictMode;
+import android.support.test.filters.MediumTest;
+
+import org.chromium.base.ThreadUtils;
+import org.chromium.base.test.util.CommandLineFlags;
+import org.chromium.base.test.util.Feature;
+import org.chromium.base.test.util.Restriction;
+import org.chromium.base.test.util.RetryOnFailure;
+import org.chromium.chrome.browser.ChromeActivity;
+import org.chromium.chrome.browser.tab.Tab;
+import org.chromium.chrome.test.ChromeActivityTestCaseBase;
+import org.chromium.chrome.test.util.ChromeRestriction;
+import org.chromium.chrome.test.util.browser.TabTitleObserver;
+import org.chromium.net.test.EmbeddedTestServer;
+
+import java.util.concurrent.TimeoutException;
+
+/**
+ * Testing of the Shape Detection API. This API has three parts: QR/Barcodes,
Reilly Grant (use Gerrit) 2017/02/28 00:35:11 nit: extra indentation here
mcasas 2017/02/28 18:10:18 It's supposed to be like that when using JavaDocs
+ * Text and Faces. Only the first two are tested here since Face detection
+ * is based on android.media.FaceDetector and doesn't need special treatment,
+ * hence is tested via content_browsertests.
+ */
+public class ShapeDetectionTest extends ChromeActivityTestCaseBase<ChromeActivity> {
+ private StrictMode.ThreadPolicy mOldPolicy;
+
+ public ShapeDetectionTest() {
+ super(ChromeActivity.class);
+ }
+
+ /**
+ * Verifies that QR codes are detected correctly.
+ */
+ @CommandLineFlags.Add("enable-experimental-web-platform-features")
+ @Feature({"ShapeDetection"})
+ @MediumTest
+ @Restriction(ChromeRestriction.RESTRICTION_TYPE_GOOGLE_PLAY_SERVICES)
+ @RetryOnFailure
+ public void testBarcodeDetection() throws InterruptedException, TimeoutException {
+ EmbeddedTestServer testServer =
+ EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
+ try {
+ Tab tab = getActivity().getActivityTab();
+ TabTitleObserver titleObserver = new TabTitleObserver(tab, "found 1 shapes");
+ loadUrl(testServer.getURL("/chrome/test/data/android/barcode_detection.html"));
+ titleObserver.waitForTitleUpdate(10);
+
+ assertEquals("found 1 shapes", tab.getTitle());
+ } finally {
+ testServer.stopAndDestroyServer();
+ }
+ }
+
+ /**
+ * Verifies that text is detected correctly.
+ */
+ @CommandLineFlags.Add("enable-experimental-web-platform-features")
+ @Feature({"ShapeDetection"})
+ @MediumTest
+ @Restriction(ChromeRestriction.RESTRICTION_TYPE_GOOGLE_PLAY_SERVICES)
+ @RetryOnFailure
+ public void testTextDetection() throws InterruptedException, TimeoutException {
+ EmbeddedTestServer testServer =
+ EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
+ try {
+ Tab tab = getActivity().getActivityTab();
+ TabTitleObserver titleObserver = new TabTitleObserver(tab, "found 1 shapes");
+ loadUrl(testServer.getURL("/chrome/test/data/android/text_detection.html"));
+ titleObserver.waitForTitleUpdate(10);
+
+ assertEquals("found 1 shapes", tab.getTitle());
+ } finally {
+ testServer.stopAndDestroyServer();
+ }
+ }
+
+ /**
+ * We need to allow a looser policy due to the Google Play Services internals.
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ mOldPolicy = StrictMode.allowThreadDiskReads();
+ StrictMode.allowThreadDiskWrites();
+ }
+ });
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ StrictMode.setThreadPolicy(mOldPolicy);
+ }
+ });
+ super.tearDown();
+ }
+
+ @Override
+ public void startMainActivity() throws InterruptedException {
+ startMainActivityOnBlankPage();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698