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

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: Fix trybot failure... 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 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 // Override AndroidVibratorWrapper API to record the calling.
33 private static class FakeAndroidVibratorWrapper
34 extends VibrationManagerImpl.AndroidVibratorWrapper {
35 // Record the parameters of vibrate() and cancel().
36 public long mMilliSeconds;
37 public boolean mCancelled;
38
39 protected FakeAndroidVibratorWrapper() {
40 // No need to provide real system Vibrator for testing, just pass nu ll.
41 super(null);
42 mMilliSeconds = -1;
43 mCancelled = false;
44 }
45
46 @Override
47 public void vibrate(long milliseconds) {
48 mMilliSeconds = milliseconds;
49 }
50
51 @Override
52 public void cancel() {
53 mCancelled = true;
54 }
55 }
56
57 @Override
58 protected void setUp() throws Exception {
59 super.setUp();
60 launchContentShellWithUrl("about:blank");
61 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
62 }
63
64 /**
65 * Inject our fake wrapper into VibrationManagerImpl,
66 * load the webpage which will request vibrate for 3000 milliseconds,
67 * the fake wrapper vibrate() should be called and 3000 milliseconds should be recorded
68 * correctly.
69 */
70 @MediumTest
71 @Feature({"Vibration"})
72 public void testVibrate() throws Throwable {
73 final FakeAndroidVibratorWrapper fakeWrapper = new FakeAndroidVibratorWr apper();
74 VibrationManagerImpl.setVibratorWrapperForTesting(fakeWrapper);
timvolodine 2015/10/20 13:16:22 put these 2 lines in setUp()? applies to the secon
leonhsl(Using Gerrit) 2015/10/22 10:47:58 Done.
75
76 assertEquals(-1, fakeWrapper.mMilliSeconds);
77 assertFalse(fakeWrapper.mCancelled);
timvolodine 2015/10/20 13:16:22 maybe also these two lines as well
leonhsl(Using Gerrit) 2015/10/22 10:47:58 Done.
78
79 loadNewShell(URL_VIBRATOR_VIBRATE);
timvolodine 2015/10/20 13:16:22 nit: empty line after for readability
leonhsl(Using Gerrit) 2015/10/22 10:47:58 Done.
80 // Waits until VibrationManagerImpl.Vibrate() got called.
81 assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
82 @Override
83 public boolean isSatisfied() {
84 return fakeWrapper.mMilliSeconds != -1;
85 }
86 }));
87
88 assertEquals(
89 "Did not get vibrate mMilliSeconds correctly", 3000, fakeWrapper .mMilliSeconds);
90 }
91
92 /**
93 * Inject our fake wrapper into VibrationManagerImpl,
94 * load the webpage which will request vibrate and then request cancel,
95 * the fake wrapper cancel() should be called.
96 */
97 @MediumTest
98 @Feature({"Vibration"})
99 public void testCancel() throws Throwable {
100 final FakeAndroidVibratorWrapper fakeWrapper = new FakeAndroidVibratorWr apper();
101 VibrationManagerImpl.setVibratorWrapperForTesting(fakeWrapper);
timvolodine 2015/10/20 13:16:22 same here
leonhsl(Using Gerrit) 2015/10/22 10:47:57 Done.
102
103 assertEquals(-1, fakeWrapper.mMilliSeconds);
104 assertFalse(fakeWrapper.mCancelled);
timvolodine 2015/10/20 13:16:22 and here
leonhsl(Using Gerrit) 2015/10/22 10:47:58 Done.
105
106 loadNewShell(URL_VIBRATOR_CANCEL);
107 // Waits until VibrationManagerImpl.Cancel() got called.
108 assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
109 @Override
110 public boolean isSatisfied() {
111 return fakeWrapper.mCancelled;
112 }
113 }));
114
115 assertTrue("Did not get cancelled", fakeWrapper.mCancelled);
116 }
117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698