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

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/VibrationManagerImplTest.java

Issue 1324853004: Add browsertests for VibrationManager java impl on android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 5 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 side-by-side diff with in-line comments
Download patch
Index: content/public/android/javatests/src/org/chromium/content/browser/VibrationManagerImplTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/VibrationManagerImplTest.java b/content/public/android/javatests/src/org/chromium/content/browser/VibrationManagerImplTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..d1a7732dd62a06a14e9af98c46eba73cefb5bf08
--- /dev/null
+++ b/content/public/android/javatests/src/org/chromium/content/browser/VibrationManagerImplTest.java
@@ -0,0 +1,113 @@
+// Copyright 2015 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.content.browser;
+
+import android.test.suitebuilder.annotation.MediumTest;
+
+import org.chromium.base.test.util.Feature;
+import org.chromium.base.test.util.UrlUtils;
+import org.chromium.content.browser.test.util.Criteria;
+import org.chromium.content.browser.test.util.CriteriaHelper;
+import org.chromium.content_shell_apk.ContentShellTestBase;
+import org.chromium.device.vibration.VibrationManagerImpl;
+
+/**
+ * Tests java implementation of VibrationManager mojo service on android.
+ */
+public class VibrationManagerImplTest extends ContentShellTestBase {
+ private static final String URL_VIBRATOR_VIBRATE = UrlUtils.encodeHtmlDataUri("<html><body>"
+ + " <script type=\"text/javascript\">"
+ + " navigator.vibrate(3000);"
+ + " </script>"
+ + "</body></html>");
+ private static final String URL_VIBRATOR_CANCEL = UrlUtils.encodeHtmlDataUri("<html><body>"
+ + " <script type=\"text/javascript\">"
+ + " navigator.vibrate(10000);"
+ + " navigator.vibrate(0);"
+ + " </script>"
+ + "</body></html>");
+
+ private final FakeAndroidVibratorWrapper mFakeWrapper = new FakeAndroidVibratorWrapper();
+
+ // Override AndroidVibratorWrapper API to record the calling.
+ private static class FakeAndroidVibratorWrapper
+ extends VibrationManagerImpl.AndroidVibratorWrapper {
+ // Record the parameters of vibrate() and cancel().
+ public long mMilliSeconds;
+ public boolean mCancelled;
+
+ protected FakeAndroidVibratorWrapper() {
+ // No need to provide real system Vibrator for testing, just pass null.
+ super(null);
+ mMilliSeconds = -1;
+ mCancelled = false;
+ }
+
+ @Override
+ public void vibrate(long milliseconds) {
+ mMilliSeconds = milliseconds;
+ }
+
+ @Override
+ public void cancel() {
+ mCancelled = true;
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ launchContentShellWithUrl("about:blank");
+ assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
+
+ VibrationManagerImpl.setVibratorWrapperForTesting(mFakeWrapper);
timvolodine 2015/10/22 11:26:13 hmm does that actually work? probably better to cr
leonhsl(Using Gerrit) 2015/10/25 05:55:49 Done.
+ assertEquals(-1, mFakeWrapper.mMilliSeconds);
+ assertFalse(mFakeWrapper.mCancelled);
+ }
+
+ /**
+ * Inject our fake wrapper into VibrationManagerImpl,
+ * load the webpage which will request vibrate for 3000 milliseconds,
+ * the fake wrapper vibrate() should be called and 3000 milliseconds should be recorded
+ * correctly.
+ */
+ @MediumTest
+ @Feature({"Vibration"})
+ public void testVibrate() throws Throwable {
+ loadNewShell(URL_VIBRATOR_VIBRATE);
+
+ // Waits until VibrationManagerImpl.Vibrate() got called.
+ assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return mFakeWrapper.mMilliSeconds != -1;
+ }
+ }));
+
+ assertEquals(
+ "Did not get vibrate mMilliSeconds correctly", 3000, mFakeWrapper.mMilliSeconds);
+ }
+
+ /**
+ * Inject our fake wrapper into VibrationManagerImpl,
+ * load the webpage which will request vibrate and then request cancel,
+ * the fake wrapper cancel() should be called.
+ */
+ @MediumTest
+ @Feature({"Vibration"})
+ public void testCancel() throws Throwable {
+ loadNewShell(URL_VIBRATOR_CANCEL);
+
+ // Waits until VibrationManagerImpl.Cancel() got called.
+ assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return mFakeWrapper.mCancelled;
+ }
+ }));
+
+ assertTrue("Did not get cancelled", mFakeWrapper.mCancelled);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698