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

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: Address comments 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.test.suitebuilder.annotation.MediumTest;
8
9 import org.chromium.base.test.util.Feature;
10 import org.chromium.base.test.util.UrlUtils;
11 import org.chromium.content.browser.test.util.Criteria;
12 import org.chromium.content.browser.test.util.CriteriaHelper;
13 import org.chromium.content_shell_apk.ContentShellTestBase;
14 import org.chromium.device.vibration.VibrationManagerImpl;
15
16 /**
17 * Tests java implementation of VibrationManager mojo service on android.
18 */
19 public class VibrationManagerImplTest extends ContentShellTestBase {
20 private static final String URL_VIBRATOR_VIBRATE = UrlUtils.encodeHtmlDataUr i("<html><body>"
21 + " <script type=\"text/javascript\">"
22 + " navigator.vibrate(3000);"
23 + " </script>"
24 + "</body></html>");
25 private static final String URL_VIBRATOR_CANCEL = UrlUtils.encodeHtmlDataUri ("<html><body>"
26 + " <script type=\"text/javascript\">"
27 + " navigator.vibrate(10000);"
28 + " navigator.vibrate(0);"
29 + " </script>"
30 + "</body></html>");
31
32 private FakeAndroidVibratorWrapper mFakeWrapper;
33
34 // Override AndroidVibratorWrapper API to record the calling.
35 private static class FakeAndroidVibratorWrapper
36 extends VibrationManagerImpl.AndroidVibratorWrapper {
37 // Record the parameters of vibrate() and cancel().
38 public long mMilliSeconds;
39 public boolean mCancelled;
40
41 protected FakeAndroidVibratorWrapper() {
42 // No need to provide real system Vibrator for testing, just pass nu ll.
43 super(null);
44 mMilliSeconds = -1;
45 mCancelled = false;
46 }
47
48 @Override
49 public void vibrate(long milliseconds) {
50 mMilliSeconds = milliseconds;
51 }
52
53 @Override
54 public void cancel() {
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