forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert of [DeviceService] Add service tests for VibrationManager. (pa…
…tchset #7 id:410001 of https://codereview.chromium.org/2774783003/ ) Reason for revert: Appears to have broken service_unittests on Nexus 5X. Original issue's description: > [DeviceService] Add service tests for VibrationManager. > > VibrationManagerImpl.java is in //device/vibration while the > VibrationManagerImplTest.java is still in //content, > to be able to hide all //device/vibration impl inside Device Service, > we must eliminate this concrete dependency on //device/vibration from > content layer. > > As VibrationManagerImplTest.java is an integration test based on > content shell test infra, we can't move it outside of //content. > So we consider to use other tests to replace it, while the renderer-side > testing has already been covered by layout tests created at > https://codereview.chromium.org/2731953003/, so we create this CL to > cover the VibrationManager interface impl testing: > - creates an infra for Device Service service tests. > - adds a new service test for VibrationManager interface. > > Then after this CL we'll be able to hide all vibration impl inside > Device Service with a follow-up CL. > > BUG=689379 > TEST=service_unittests > > Review-Url: https://codereview.chromium.org/2774783003 > Cr-Commit-Position: refs/heads/master@{#463612} > Committed: https://chromium.googlesource.com/chromium/src/+/9c17bee62f1e16224fabb7c83bbeaab719015761 TBR=rockot@chromium.org,avi@chromium.org,blundell@chromium.org,jam@chromium.org,timvolodine@chromium.org,leon.han@intel.com # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=689379 Review-Url: https://codereview.chromium.org/2815623003 Cr-Commit-Position: refs/heads/master@{#463629}
- Loading branch information
1 parent
4d28782
commit 1a5a2cd
Showing
14 changed files
with
166 additions
and
335 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
...t/public/android/javatests/src/org/chromium/content/browser/VibrationManagerImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// 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.os.Vibrator; | ||
import android.support.test.filters.MediumTest; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import org.chromium.base.test.BaseJUnit4ClassRunner; | ||
import org.chromium.base.test.util.DisabledTest; | ||
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.ContentShellActivityTestRule; | ||
import org.chromium.device.vibration.VibrationManagerImpl; | ||
|
||
/** | ||
* Tests java implementation of VibrationManager mojo service on android. | ||
*/ | ||
@RunWith(BaseJUnit4ClassRunner.class) | ||
public class VibrationManagerImplTest { | ||
@Rule | ||
public ContentShellActivityTestRule mActivityTestRule = new ContentShellActivityTestRule(); | ||
|
||
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 FakeAndroidVibratorWrapper mFakeWrapper; | ||
|
||
// 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() { | ||
super(); | ||
mMilliSeconds = -1; | ||
mCancelled = false; | ||
} | ||
|
||
@Override | ||
public void vibrate(Vibrator vibrator, long milliseconds) { | ||
mMilliSeconds = milliseconds; | ||
} | ||
|
||
@Override | ||
public void cancel(Vibrator vibrator) { | ||
mCancelled = true; | ||
} | ||
} | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
mActivityTestRule.launchContentShellWithUrl("about:blank"); | ||
mActivityTestRule.waitForActiveShellToBeDoneLoading(); | ||
|
||
mFakeWrapper = new FakeAndroidVibratorWrapper(); | ||
VibrationManagerImpl.setVibratorWrapperForTesting(mFakeWrapper); | ||
Assert.assertEquals(-1, mFakeWrapper.mMilliSeconds); | ||
Assert.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"}) | ||
@Test | ||
@DisabledTest | ||
public void testVibrate() throws Throwable { | ||
mActivityTestRule.loadNewShell(URL_VIBRATOR_VIBRATE); | ||
|
||
// Waits until VibrationManagerImpl.Vibrate() got called. | ||
CriteriaHelper.pollUiThread(new Criteria() { | ||
@Override | ||
public boolean isSatisfied() { | ||
return mFakeWrapper.mMilliSeconds != -1; | ||
} | ||
}); | ||
|
||
Assert.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. | ||
*/ | ||
@Test | ||
@MediumTest | ||
@Feature({"Vibration"}) | ||
public void testCancel() throws Throwable { | ||
mActivityTestRule.loadNewShell(URL_VIBRATOR_CANCEL); | ||
|
||
// Waits until VibrationManagerImpl.Cancel() got called. | ||
CriteriaHelper.pollUiThread(new Criteria() { | ||
@Override | ||
public boolean isSatisfied() { | ||
return mFakeWrapper.mCancelled; | ||
} | ||
}); | ||
|
||
Assert.assertTrue("Did not get cancelled", mFakeWrapper.mCancelled); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.