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, |
+ * 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 |
Maria
2017/02/28 18:40:56
I think this is actually a large test because it s
mcasas
2017/02/28 21:06:57
Done.
|
+ @Restriction(ChromeRestriction.RESTRICTION_TYPE_GOOGLE_PLAY_SERVICES) |
+ @RetryOnFailure |
Maria
2017/02/28 18:40:56
Why are you adding @RetryOnFailure here? This is a
mcasas
2017/02/28 21:06:57
Removed. It was copy-pasted, but should never
be f
|
+ 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()); |
Maria
2017/02/28 18:40:56
extract title into a const?
mcasas
2017/02/28 21:06:57
Done.
|
+ } 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 |
Maria
2017/02/28 18:40:56
same comments on annotation as above
|
+ 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(); |
+ } |
+} |