| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import android.os.Vibrator; | 7 import android.os.Vibrator; |
| 8 import android.support.test.filters.MediumTest; | 8 import android.support.test.filters.MediumTest; |
| 9 | 9 |
| 10 import org.junit.Assert; |
| 11 import org.junit.Before; |
| 12 import org.junit.Rule; |
| 13 import org.junit.Test; |
| 14 import org.junit.runner.RunWith; |
| 15 |
| 16 import org.chromium.base.test.BaseJUnit4ClassRunner; |
| 10 import org.chromium.base.test.util.DisabledTest; | 17 import org.chromium.base.test.util.DisabledTest; |
| 11 import org.chromium.base.test.util.Feature; | 18 import org.chromium.base.test.util.Feature; |
| 12 import org.chromium.base.test.util.UrlUtils; | 19 import org.chromium.base.test.util.UrlUtils; |
| 13 import org.chromium.content.browser.test.util.Criteria; | 20 import org.chromium.content.browser.test.util.Criteria; |
| 14 import org.chromium.content.browser.test.util.CriteriaHelper; | 21 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 15 import org.chromium.content_shell_apk.ContentShellTestBase; | 22 import org.chromium.content_shell_apk.ContentShellActivityTestRule; |
| 16 import org.chromium.device.vibration.VibrationManagerImpl; | 23 import org.chromium.device.vibration.VibrationManagerImpl; |
| 17 | 24 |
| 18 /** | 25 /** |
| 19 * Tests java implementation of VibrationManager mojo service on android. | 26 * Tests java implementation of VibrationManager mojo service on android. |
| 20 */ | 27 */ |
| 21 public class VibrationManagerImplTest extends ContentShellTestBase { | 28 @RunWith(BaseJUnit4ClassRunner.class) |
| 29 public class VibrationManagerImplTest { |
| 30 @Rule |
| 31 public ContentShellActivityTestRule mActivityTestRule = new ContentShellActi
vityTestRule(); |
| 32 |
| 22 private static final String URL_VIBRATOR_VIBRATE = UrlUtils.encodeHtmlDataUr
i("<html><body>" | 33 private static final String URL_VIBRATOR_VIBRATE = UrlUtils.encodeHtmlDataUr
i("<html><body>" |
| 23 + " <script type=\"text/javascript\">" | 34 + " <script type=\"text/javascript\">" |
| 24 + " navigator.vibrate(3000);" | 35 + " navigator.vibrate(3000);" |
| 25 + " </script>" | 36 + " </script>" |
| 26 + "</body></html>"); | 37 + "</body></html>"); |
| 27 private static final String URL_VIBRATOR_CANCEL = UrlUtils.encodeHtmlDataUri
("<html><body>" | 38 private static final String URL_VIBRATOR_CANCEL = UrlUtils.encodeHtmlDataUri
("<html><body>" |
| 28 + " <script type=\"text/javascript\">" | 39 + " <script type=\"text/javascript\">" |
| 29 + " navigator.vibrate(10000);" | 40 + " navigator.vibrate(10000);" |
| 30 + " navigator.vibrate(0);" | 41 + " navigator.vibrate(0);" |
| 31 + " </script>" | 42 + " </script>" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 50 public void vibrate(Vibrator vibrator, long milliseconds) { | 61 public void vibrate(Vibrator vibrator, long milliseconds) { |
| 51 mMilliSeconds = milliseconds; | 62 mMilliSeconds = milliseconds; |
| 52 } | 63 } |
| 53 | 64 |
| 54 @Override | 65 @Override |
| 55 public void cancel(Vibrator vibrator) { | 66 public void cancel(Vibrator vibrator) { |
| 56 mCancelled = true; | 67 mCancelled = true; |
| 57 } | 68 } |
| 58 } | 69 } |
| 59 | 70 |
| 60 @Override | 71 @Before |
| 61 protected void setUp() throws Exception { | 72 public void setUp() throws Exception { |
| 62 super.setUp(); | 73 mActivityTestRule.launchContentShellWithUrl("about:blank"); |
| 63 launchContentShellWithUrl("about:blank"); | 74 mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
| 64 waitForActiveShellToBeDoneLoading(); | |
| 65 | 75 |
| 66 mFakeWrapper = new FakeAndroidVibratorWrapper(); | 76 mFakeWrapper = new FakeAndroidVibratorWrapper(); |
| 67 VibrationManagerImpl.setVibratorWrapperForTesting(mFakeWrapper); | 77 VibrationManagerImpl.setVibratorWrapperForTesting(mFakeWrapper); |
| 68 assertEquals(-1, mFakeWrapper.mMilliSeconds); | 78 Assert.assertEquals(-1, mFakeWrapper.mMilliSeconds); |
| 69 assertFalse(mFakeWrapper.mCancelled); | 79 Assert.assertFalse(mFakeWrapper.mCancelled); |
| 70 } | 80 } |
| 71 | 81 |
| 72 /** | 82 /** |
| 73 * Inject our fake wrapper into VibrationManagerImpl, | 83 * Inject our fake wrapper into VibrationManagerImpl, |
| 74 * load the webpage which will request vibrate for 3000 milliseconds, | 84 * load the webpage which will request vibrate for 3000 milliseconds, |
| 75 * the fake wrapper vibrate() should be called and 3000 milliseconds should
be recorded | 85 * the fake wrapper vibrate() should be called and 3000 milliseconds should
be recorded |
| 76 * correctly. | 86 * correctly. |
| 77 */ | 87 */ |
| 78 // @MediumTest | 88 // @MediumTest |
| 79 // @Feature({"Vibration"}) | 89 // @Feature({"Vibration"}) |
| 90 @Test |
| 80 @DisabledTest | 91 @DisabledTest |
| 81 public void testVibrate() throws Throwable { | 92 public void testVibrate() throws Throwable { |
| 82 loadNewShell(URL_VIBRATOR_VIBRATE); | 93 mActivityTestRule.loadNewShell(URL_VIBRATOR_VIBRATE); |
| 83 | 94 |
| 84 // Waits until VibrationManagerImpl.Vibrate() got called. | 95 // Waits until VibrationManagerImpl.Vibrate() got called. |
| 85 CriteriaHelper.pollUiThread(new Criteria() { | 96 CriteriaHelper.pollUiThread(new Criteria() { |
| 86 @Override | 97 @Override |
| 87 public boolean isSatisfied() { | 98 public boolean isSatisfied() { |
| 88 return mFakeWrapper.mMilliSeconds != -1; | 99 return mFakeWrapper.mMilliSeconds != -1; |
| 89 } | 100 } |
| 90 }); | 101 }); |
| 91 | 102 |
| 92 assertEquals( | 103 Assert.assertEquals( |
| 93 "Did not get vibrate mMilliSeconds correctly", 3000, mFakeWrappe
r.mMilliSeconds); | 104 "Did not get vibrate mMilliSeconds correctly", 3000, mFakeWrappe
r.mMilliSeconds); |
| 94 } | 105 } |
| 95 | 106 |
| 96 /** | 107 /** |
| 97 * Inject our fake wrapper into VibrationManagerImpl, | 108 * Inject our fake wrapper into VibrationManagerImpl, |
| 98 * load the webpage which will request vibrate and then request cancel, | 109 * load the webpage which will request vibrate and then request cancel, |
| 99 * the fake wrapper cancel() should be called. | 110 * the fake wrapper cancel() should be called. |
| 100 */ | 111 */ |
| 112 @Test |
| 101 @MediumTest | 113 @MediumTest |
| 102 @Feature({"Vibration"}) | 114 @Feature({"Vibration"}) |
| 103 public void testCancel() throws Throwable { | 115 public void testCancel() throws Throwable { |
| 104 loadNewShell(URL_VIBRATOR_CANCEL); | 116 mActivityTestRule.loadNewShell(URL_VIBRATOR_CANCEL); |
| 105 | 117 |
| 106 // Waits until VibrationManagerImpl.Cancel() got called. | 118 // Waits until VibrationManagerImpl.Cancel() got called. |
| 107 CriteriaHelper.pollUiThread(new Criteria() { | 119 CriteriaHelper.pollUiThread(new Criteria() { |
| 108 @Override | 120 @Override |
| 109 public boolean isSatisfied() { | 121 public boolean isSatisfied() { |
| 110 return mFakeWrapper.mCancelled; | 122 return mFakeWrapper.mCancelled; |
| 111 } | 123 } |
| 112 }); | 124 }); |
| 113 | 125 |
| 114 assertTrue("Did not get cancelled", mFakeWrapper.mCancelled); | 126 Assert.assertTrue("Did not get cancelled", mFakeWrapper.mCancelled); |
| 115 } | 127 } |
| 116 } | 128 } |
| OLD | NEW |