Chromium Code Reviews| Index: chrome/android/junit/src/org/chromium/chrome/browser/media/ui/MediaNotificationButtonComputationTest.java |
| diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/media/ui/MediaNotificationButtonComputationTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/media/ui/MediaNotificationButtonComputationTest.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..656aa20cb290988bc6cb1692e400e004a96aac49 |
| --- /dev/null |
| +++ b/chrome/android/junit/src/org/chromium/chrome/browser/media/ui/MediaNotificationButtonComputationTest.java |
| @@ -0,0 +1,96 @@ |
| +// Copyright 2016 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.chrome.browser.media.ui; |
| + |
| +import static org.junit.Assert.assertEquals; |
| + |
| +import org.junit.Test; |
| +import org.junit.runner.RunWith; |
| +import org.robolectric.annotation.Config; |
| + |
| +import org.chromium.base.test.util.Feature; |
| +import org.chromium.blink.mojom.MediaSessionAction; |
| +import org.chromium.testing.local.LocalRobolectricTestRunner; |
| + |
| +import java.util.ArrayList; |
| + |
| +/** |
| + * Robolectric tests for compact view button computation in {@link MediaNotificationManager}. |
| + */ |
| +@RunWith(LocalRobolectricTestRunner.class) |
| +@Config |
| +public class MediaNotificationButtonComputationTest { |
| + @Test |
| + @Feature({"MediaNotification"}) |
| + public void testLessThanThreeActionsWillBeAllShownInCompactView() { |
| + ArrayList<Integer> actions = new ArrayList<Integer>(); |
|
gone
2016/11/28 19:23:21
new ArrayList<>();
Zhiqiang Zhang (Slow)
2016/11/29 16:45:40
Done.
|
| + actions.add(MediaSessionAction.NEXT_TRACK); |
| + actions.add(MediaSessionAction.SEEK_FORWARD); |
| + actions.add(MediaSessionAction.PLAY); |
| + |
| + int[] compactViewActions = |
| + MediaNotificationManager.computeCompactViewActionIndices(actions); |
| + |
| + assertEquals(3, compactViewActions.length); |
| + assertEquals(0, compactViewActions[0]); |
| + assertEquals(1, compactViewActions[1]); |
| + assertEquals(2, compactViewActions[2]); |
| + } |
| + |
| + @Test |
| + @Feature({"MediaNotification"}) |
| + public void testCompactViewPrefersActionPairs_SwitchTrack() { |
| + ArrayList<Integer> actions = new ArrayList<Integer>(); |
| + actions.add(MediaSessionAction.PREVIOUS_TRACK); |
| + actions.add(MediaSessionAction.NEXT_TRACK); |
| + actions.add(MediaSessionAction.SEEK_FORWARD); |
| + actions.add(MediaSessionAction.PLAY); |
| + |
| + int[] compactViewActions = |
| + MediaNotificationManager.computeCompactViewActionIndices(actions); |
| + |
| + assertEquals(3, compactViewActions.length); |
| + assertEquals(0, compactViewActions[0]); |
| + assertEquals(3, compactViewActions[1]); |
| + assertEquals(1, compactViewActions[2]); |
| + } |
| + |
| + @Test |
| + @Feature({"MediaNotification"}) |
| + public void testCompactViewPrefersActionPairs_Seek() { |
| + ArrayList<Integer> actions = new ArrayList<Integer>(); |
| + actions.add(MediaSessionAction.NEXT_TRACK); |
| + actions.add(MediaSessionAction.SEEK_BACKWARD); |
| + actions.add(MediaSessionAction.SEEK_FORWARD); |
| + actions.add(MediaSessionAction.PLAY); |
| + |
| + int[] compactViewActions = |
| + MediaNotificationManager.computeCompactViewActionIndices(actions); |
| + |
| + assertEquals(3, compactViewActions.length); |
| + assertEquals(1, compactViewActions[0]); |
| + assertEquals(3, compactViewActions[1]); |
| + assertEquals(2, compactViewActions[2]); |
| + } |
| + |
| + @Test |
| + @Feature({"MediaNotification"}) |
| + public void testCompactViewPreferSwitchTrackWhenBothPairsExist() { |
| + ArrayList<Integer> actions = new ArrayList<Integer>(); |
| + actions.add(MediaSessionAction.PREVIOUS_TRACK); |
| + actions.add(MediaSessionAction.NEXT_TRACK); |
| + actions.add(MediaSessionAction.SEEK_BACKWARD); |
| + actions.add(MediaSessionAction.SEEK_FORWARD); |
| + actions.add(MediaSessionAction.PLAY); |
| + |
| + int[] compactViewActions = |
| + MediaNotificationManager.computeCompactViewActionIndices(actions); |
| + |
| + assertEquals(3, compactViewActions.length); |
| + assertEquals(0, compactViewActions[0]); |
| + assertEquals(4, compactViewActions[1]); |
| + assertEquals(1, compactViewActions[2]); |
| + } |
| +} |