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

Side by Side 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: Avoid static ref to android service Created 5 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright 2015 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 package org.chromium.content.browser;
6
7 import android.os.Vibrator;
8 import android.test.suitebuilder.annotation.MediumTest;
9
10 import org.chromium.base.test.util.Feature;
11 import org.chromium.base.test.util.UrlUtils;
12 import org.chromium.content.browser.test.util.Criteria;
13 import org.chromium.content.browser.test.util.CriteriaHelper;
14 import org.chromium.content_shell_apk.ContentShellTestBase;
15 import org.chromium.device.vibration.VibrationManagerImpl;
16
17 /**
18 * Tests java implementation of VibrationManager mojo service on android.
19 */
20 public class VibrationManagerImplTest extends ContentShellTestBase {
21 private static final String URL_VIBRATOR_VIBRATE = UrlUtils.encodeHtmlDataUr i("<html><body>"
22 + " <script type=\"text/javascript\">"
23 + " navigator.vibrate(3000);"
24 + " </script>"
25 + "</body></html>");
26 private static final String URL_VIBRATOR_CANCEL = UrlUtils.encodeHtmlDataUri ("<html><body>"
27 + " <script type=\"text/javascript\">"
28 + " navigator.vibrate(10000);"
29 + " navigator.vibrate(0);"
30 + " </script>"
31 + "</body></html>");
32
33 private FakeAndroidVibratorWrapper mFakeWrapper;
34
35 // Override AndroidVibratorWrapper API to record the calling.
36 private static class FakeAndroidVibratorWrapper
37 extends VibrationManagerImpl.AndroidVibratorWrapper {
38 // Record the parameters of vibrate() and cancel().
39 public long mMilliSeconds;
40 public boolean mCancelled;
41
42 protected FakeAndroidVibratorWrapper() {
43 super();
44 mMilliSeconds = -1;
45 mCancelled = false;
46 }
47
48 @Override
49 public void vibrate(Vibrator vibrator, long milliseconds) {
50 mMilliSeconds = milliseconds;
51 }
52
53 @Override
54 public void cancel(Vibrator vibrator) {
55 mCancelled = true;
56 }
57 }
58
59 @Override
60 protected void setUp() throws Exception {
61 super.setUp();
62 launchContentShellWithUrl("about:blank");
63 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
64
65 mFakeWrapper = new FakeAndroidVibratorWrapper();
66 VibrationManagerImpl.setVibratorWrapperForTesting(mFakeWrapper);
67 assertEquals(-1, mFakeWrapper.mMilliSeconds);
68 assertFalse(mFakeWrapper.mCancelled);
69 }
70
71 /**
72 * Inject our fake wrapper into VibrationManagerImpl,
73 * load the webpage which will request vibrate for 3000 milliseconds,
74 * the fake wrapper vibrate() should be called and 3000 milliseconds should be recorded
75 * correctly.
76 */
77 @MediumTest
78 @Feature({"Vibration"})
79 public void testVibrate() throws Throwable {
80 loadNewShell(URL_VIBRATOR_VIBRATE);
81
82 // Waits until VibrationManagerImpl.Vibrate() got called.
83 assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
84 @Override
85 public boolean isSatisfied() {
86 return mFakeWrapper.mMilliSeconds != -1;
87 }
88 }));
89
90 assertEquals(
91 "Did not get vibrate mMilliSeconds correctly", 3000, mFakeWrappe r.mMilliSeconds);
92 }
93
94 /**
95 * Inject our fake wrapper into VibrationManagerImpl,
96 * load the webpage which will request vibrate and then request cancel,
97 * the fake wrapper cancel() should be called.
98 */
99 @MediumTest
100 @Feature({"Vibration"})
101 public void testCancel() throws Throwable {
102 loadNewShell(URL_VIBRATOR_CANCEL);
103
104 // Waits until VibrationManagerImpl.Cancel() got called.
105 assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
106 @Override
107 public boolean isSatisfied() {
108 return mFakeWrapper.mCancelled;
109 }
110 }));
111
112 assertTrue("Did not get cancelled", mFakeWrapper.mCancelled);
113 }
114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698