| Index: chrome/android/javatests/src/org/chromium/chrome/browser/media/ui/PauseOnHeadsetUnplugTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/media/ui/PauseOnHeadsetUnplugTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/media/ui/PauseOnHeadsetUnplugTest.java
|
| index ab6d317b1eb810d15dc50275f82d36ef99901c7a..b38c83385b9242b1b37bf91abfb47cd47e28602f 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/media/ui/PauseOnHeadsetUnplugTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/media/ui/PauseOnHeadsetUnplugTest.java
|
| @@ -6,14 +6,24 @@ package org.chromium.chrome.browser.media.ui;
|
|
|
| import android.content.Intent;
|
| import android.media.AudioManager;
|
| +import android.support.test.InstrumentationRegistry;
|
| import android.support.test.filters.SmallTest;
|
|
|
| +import org.junit.After;
|
| +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.util.CommandLineFlags;
|
| import org.chromium.base.test.util.RetryOnFailure;
|
| import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.ChromeActivity;
|
| +import org.chromium.chrome.browser.ChromeSwitches;
|
| import org.chromium.chrome.browser.tab.Tab;
|
| -import org.chromium.chrome.test.ChromeActivityTestCaseBase;
|
| +import org.chromium.chrome.test.ChromeActivityTestRule;
|
| +import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
|
| import org.chromium.content.browser.test.util.Criteria;
|
| import org.chromium.content.browser.test.util.CriteriaHelper;
|
| import org.chromium.content.browser.test.util.DOMUtils;
|
| @@ -25,25 +35,29 @@ import java.util.concurrent.TimeoutException;
|
| /**
|
| * Tests for checking whether the media are paused when unplugging the headset
|
| */
|
| -@CommandLineFlags.Add(ContentSwitches.DISABLE_GESTURE_REQUIREMENT_FOR_MEDIA_PLAYBACK)
|
| -public class PauseOnHeadsetUnplugTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| +@RunWith(ChromeJUnit4ClassRunner.class)
|
| +@CommandLineFlags.Add({ContentSwitches.DISABLE_GESTURE_REQUIREMENT_FOR_MEDIA_PLAYBACK,
|
| + ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
|
| + ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
|
| +public class PauseOnHeadsetUnplugTest {
|
| + @Rule
|
| + public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
|
| + new ChromeActivityTestRule<>(ChromeActivity.class);
|
| +
|
| private static final String TEST_PATH =
|
| "/content/test/data/media/session/media-session.html";
|
| private static final String VIDEO_ID = "long-video";
|
|
|
| private EmbeddedTestServer mTestServer;
|
|
|
| - public PauseOnHeadsetUnplugTest() {
|
| - super(ChromeActivity.class);
|
| - }
|
| -
|
| + @Test
|
| @SmallTest
|
| @RetryOnFailure
|
| public void testPause()
|
| throws IllegalArgumentException, InterruptedException, TimeoutException {
|
| - Tab tab = getActivity().getActivityTab();
|
| + Tab tab = mActivityTestRule.getActivity().getActivityTab();
|
|
|
| - assertTrue(DOMUtils.isMediaPaused(tab.getWebContents(), VIDEO_ID));
|
| + Assert.assertTrue(DOMUtils.isMediaPaused(tab.getWebContents(), VIDEO_ID));
|
| DOMUtils.playMedia(tab.getWebContents(), VIDEO_ID);
|
| DOMUtils.waitForMediaPlay(tab.getWebContents(), VIDEO_ID);
|
| waitForNotificationReady();
|
| @@ -52,21 +66,16 @@ public class PauseOnHeadsetUnplugTest extends ChromeActivityTestCaseBase<ChromeA
|
| DOMUtils.waitForMediaPauseBeforeEnd(tab.getWebContents(), VIDEO_ID);
|
| }
|
|
|
| - @Override
|
| - public void startMainActivity() throws InterruptedException {
|
| - startMainActivityWithURL(mTestServer.getURL(TEST_PATH));
|
| - }
|
| -
|
| - @Override
|
| - protected void setUp() throws Exception {
|
| - mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
|
| - super.setUp();
|
| + @Before
|
| + public void setUp() throws Exception {
|
| + mTestServer = EmbeddedTestServer.createAndStartServer(
|
| + InstrumentationRegistry.getInstrumentation().getContext());
|
| + mActivityTestRule.startMainActivityWithURL(mTestServer.getURL(TEST_PATH));
|
| }
|
|
|
| - @Override
|
| - protected void tearDown() throws Exception {
|
| + @After
|
| + public void tearDown() throws Exception {
|
| mTestServer.stopAndDestroyServer();
|
| - super.tearDown();
|
| }
|
|
|
| private void waitForNotificationReady() {
|
| @@ -80,10 +89,10 @@ public class PauseOnHeadsetUnplugTest extends ChromeActivityTestCaseBase<ChromeA
|
| }
|
|
|
| private void simulateHeadsetUnplug() {
|
| - Intent i = new Intent(getInstrumentation().getTargetContext(),
|
| - MediaNotificationManager.PlaybackListenerService.class);
|
| + Intent i = new Intent(InstrumentationRegistry.getInstrumentation().getTargetContext(),
|
| + MediaNotificationManager.PlaybackListenerService.class);
|
| i.setAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
|
|
|
| - getInstrumentation().getContext().startService(i);
|
| + InstrumentationRegistry.getInstrumentation().getContext().startService(i);
|
| }
|
| }
|
|
|