PlaybackControlGlueTest.java revision 39d30689d76388f0d025a4fc751c6b4cbe54c492
1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package android.support.v17.leanback.app;
17
18import org.junit.Assert;
19import static org.junit.Assert.assertEquals;
20import static org.junit.Assert.assertFalse;
21import static org.junit.Assert.assertTrue;
22
23import org.junit.Before;
24import org.junit.Test;
25import org.junit.runner.RunWith;
26
27import android.content.Context;
28import android.graphics.drawable.Drawable;
29
30import android.support.v17.leanback.widget.PlaybackControlsRow;
31import android.support.v17.leanback.widget.SparseArrayObjectAdapter;
32
33import android.support.test.InstrumentationRegistry;
34import android.support.test.runner.AndroidJUnit4;
35import android.support.annotation.UiThread;
36
37import android.test.suitebuilder.annotation.SmallTest;
38import android.view.KeyEvent;
39
40@SmallTest
41@RunWith(AndroidJUnit4.class)
42public class PlaybackControlGlueTest {
43
44
45    static class PlayControlGlueImpl extends PlaybackControlGlue {
46        int mSpeedId = PLAYBACK_SPEED_PAUSED;
47
48        PlayControlGlueImpl(Context context, int[] seekSpeeds) {
49            super(context, seekSpeeds);
50        }
51
52        PlayControlGlueImpl(Context context, int[] ffSpeeds, int[] rwSpeeds) {
53            super(context, ffSpeeds, rwSpeeds);
54        }
55
56        @Override
57        public boolean hasValidMedia() {
58            return true;
59        }
60
61        @Override
62        public boolean isMediaPlaying() {
63            return mSpeedId == PLAYBACK_SPEED_NORMAL;
64        }
65
66        @Override
67        public CharSequence getMediaTitle() {
68            return "DUMP TITLE";
69        }
70
71        @Override
72        public CharSequence getMediaSubtitle() {
73            return "DUMP SUBTITLE";
74        }
75
76        @Override
77        public int getMediaDuration() {
78            return 50000;
79        }
80
81        @Override
82        public Drawable getMediaArt() {
83            return null;
84        }
85
86        @Override
87        public long getSupportedActions() {
88            return ACTION_REWIND | ACTION_FAST_FORWARD | ACTION_PLAY_PAUSE;
89        }
90
91        @Override
92        public int getCurrentSpeedId() {
93            return mSpeedId;
94        }
95
96        @Override
97        public int getCurrentPosition() {
98            return 5000;
99        }
100
101        @Override
102        protected void startPlayback(int speed) {
103            mSpeedId = speed;
104        }
105
106        @Override
107        protected void pausePlayback() {
108            mSpeedId = PLAYBACK_SPEED_PAUSED;
109        }
110
111        @Override
112        protected void skipToNext() {
113        }
114
115        @Override
116        protected void skipToPrevious() {
117        }
118
119        @Override
120        protected void onRowChanged(PlaybackControlsRow row) {
121        }
122    }
123
124    Context context;
125    PlaybackControlGlue glue;
126
127    @Before
128    public void setUp() {
129        context = InstrumentationRegistry.getInstrumentation().getTargetContext();
130        try {
131            InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
132                @Override
133                public void run() {
134                    glue = new PlayControlGlueImpl(context, new int[]{
135                            PlaybackControlGlue.PLAYBACK_SPEED_FAST_L0,
136                            PlaybackControlGlue.PLAYBACK_SPEED_FAST_L1,
137                            PlaybackControlGlue.PLAYBACK_SPEED_FAST_L2
138                    });
139                }
140            });
141        } catch (Throwable throwable) {
142            Assert.fail(throwable.getMessage());
143        }
144    }
145
146    @Test
147    public void testFastForwardToMaxThenReset() {
148        PlaybackControlsRow row = new PlaybackControlsRow();
149        glue.setControlsRow(row);
150        SparseArrayObjectAdapter adapter = (SparseArrayObjectAdapter)
151                row.getPrimaryActionsAdapter();
152        PlaybackControlsRow.MultiAction playPause = (PlaybackControlsRow.MultiAction) adapter
153                .lookup(PlaybackControlGlue.ACTION_PLAY_PAUSE);
154        PlaybackControlsRow.MultiAction fastForward = (PlaybackControlsRow.MultiAction) adapter
155                .lookup(PlaybackControlGlue.ACTION_FAST_FORWARD);
156        PlaybackControlsRow.MultiAction rewind = (PlaybackControlsRow.MultiAction) adapter
157                .lookup(PlaybackControlGlue.ACTION_REWIND);
158
159        assertFalse(glue.isMediaPlaying());
160        glue.onActionClicked(playPause);
161        assertTrue(glue.isMediaPlaying());
162        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
163        assertEquals(0, fastForward.getIndex());
164        assertEquals(0, rewind.getIndex());
165
166        // click multiple times to reach PLAYBACK_SPEED_FAST_L2
167        glue.onActionClicked(fastForward);
168        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_FAST_L0, glue.getCurrentSpeedId());
169        assertEquals(1, fastForward.getIndex());
170        assertEquals(0, rewind.getIndex());
171        glue.onActionClicked(fastForward);
172        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_FAST_L1, glue.getCurrentSpeedId());
173        assertEquals(2, fastForward.getIndex());
174        assertEquals(0, rewind.getIndex());
175        glue.onActionClicked(fastForward);
176        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_FAST_L2, glue.getCurrentSpeedId());
177        assertEquals(3, fastForward.getIndex());
178        assertEquals(0, rewind.getIndex());
179        glue.onActionClicked(fastForward);
180        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_FAST_L2, glue.getCurrentSpeedId());
181        assertEquals(3, fastForward.getIndex());
182        assertEquals(0, rewind.getIndex());
183
184        // press playPause again put it back to play
185        glue.onActionClicked(playPause);
186        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
187        assertEquals(0, fastForward.getIndex());
188        assertEquals(0, rewind.getIndex());
189    }
190
191    @Test
192    public void testFastRewindToMaxThenReset() {
193        PlaybackControlsRow row = new PlaybackControlsRow();
194        glue.setControlsRow(row);
195        SparseArrayObjectAdapter adapter = (SparseArrayObjectAdapter)
196                row.getPrimaryActionsAdapter();
197        PlaybackControlsRow.MultiAction playPause = (PlaybackControlsRow.MultiAction) adapter
198                .lookup(PlaybackControlGlue.ACTION_PLAY_PAUSE);
199        PlaybackControlsRow.MultiAction fastForward = (PlaybackControlsRow.MultiAction) adapter
200                .lookup(PlaybackControlGlue.ACTION_FAST_FORWARD);
201        PlaybackControlsRow.MultiAction rewind = (PlaybackControlsRow.MultiAction) adapter
202                .lookup(PlaybackControlGlue.ACTION_REWIND);
203
204        assertFalse(glue.isMediaPlaying());
205        glue.onActionClicked(playPause);
206        assertTrue(glue.isMediaPlaying());
207        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
208        assertEquals(0, fastForward.getIndex());
209        assertEquals(0, rewind.getIndex());
210
211        // click multiple times to reach PLAYBACK_SPEED_FAST_L2
212        glue.onActionClicked(rewind);
213        assertEquals(-PlaybackControlGlue.PLAYBACK_SPEED_FAST_L0, glue.getCurrentSpeedId());
214        assertEquals(0, fastForward.getIndex());
215        assertEquals(1, rewind.getIndex());
216        glue.onActionClicked(rewind);
217        assertEquals(-PlaybackControlGlue.PLAYBACK_SPEED_FAST_L1, glue.getCurrentSpeedId());
218        assertEquals(0, fastForward.getIndex());
219        assertEquals(2, rewind.getIndex());
220        glue.onActionClicked(rewind);
221        assertEquals(-PlaybackControlGlue.PLAYBACK_SPEED_FAST_L2, glue.getCurrentSpeedId());
222        assertEquals(0, fastForward.getIndex());
223        assertEquals(3, rewind.getIndex());
224        glue.onActionClicked(rewind);
225        assertEquals(-PlaybackControlGlue.PLAYBACK_SPEED_FAST_L2, glue.getCurrentSpeedId());
226        assertEquals(0, fastForward.getIndex());
227        assertEquals(3, rewind.getIndex());
228
229        // press playPause again put it back to play
230        glue.onActionClicked(playPause);
231        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
232        assertEquals(0, fastForward.getIndex());
233        assertEquals(0, rewind.getIndex());
234    }
235
236    @Test
237    public void testFastForwardAbortKeyCodes() {
238        PlaybackControlsRow row = new PlaybackControlsRow();
239        glue.setControlsRow(row);
240        SparseArrayObjectAdapter adapter = (SparseArrayObjectAdapter)
241                row.getPrimaryActionsAdapter();
242        PlaybackControlsRow.MultiAction playPause = (PlaybackControlsRow.MultiAction) adapter
243                .lookup(PlaybackControlGlue.ACTION_PLAY_PAUSE);
244        PlaybackControlsRow.MultiAction fastForward = (PlaybackControlsRow.MultiAction) adapter
245                .lookup(PlaybackControlGlue.ACTION_FAST_FORWARD);
246        PlaybackControlsRow.MultiAction rewind = (PlaybackControlsRow.MultiAction) adapter
247                .lookup(PlaybackControlGlue.ACTION_REWIND);
248
249        glue.onActionClicked(playPause);
250        assertTrue(glue.isMediaPlaying());
251        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
252        assertEquals(0, fastForward.getIndex());
253        assertEquals(0, rewind.getIndex());
254
255        // Testing keycodes that will not abort seek
256        final int[] noAbortSeekKeyCodes = new int[] {
257                KeyEvent.KEYCODE_DPAD_CENTER,
258                KeyEvent.KEYCODE_ENTER
259        };
260        for (int i = 0; i < noAbortSeekKeyCodes.length; i++) {
261            glue.onActionClicked(fastForward);
262            assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_FAST_L0, glue.getCurrentSpeedId());
263            assertEquals(1, fastForward.getIndex());
264            assertEquals(0, rewind.getIndex());
265            KeyEvent kv = new KeyEvent(KeyEvent.ACTION_DOWN, noAbortSeekKeyCodes[i]);
266            glue.onKey(null, noAbortSeekKeyCodes[i], kv);
267            assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_FAST_L0, glue.getCurrentSpeedId());
268            glue.onActionClicked(playPause);
269            assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
270        }
271
272        // Testing abortSeekKeyCodes
273        final int[] abortSeekKeyCodes = new int[] {
274            KeyEvent.KEYCODE_DPAD_UP,
275            KeyEvent.KEYCODE_DPAD_DOWN,
276            KeyEvent.KEYCODE_DPAD_RIGHT,
277            KeyEvent.KEYCODE_DPAD_LEFT,
278            KeyEvent.KEYCODE_BACK,
279            KeyEvent.KEYCODE_ESCAPE
280        };
281        for (int i = 0; i < abortSeekKeyCodes.length; i++) {
282            glue.onActionClicked(fastForward);
283            assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_FAST_L0, glue.getCurrentSpeedId());
284            assertEquals(1, fastForward.getIndex());
285            assertEquals(0, rewind.getIndex());
286            KeyEvent kv = new KeyEvent(KeyEvent.ACTION_DOWN, abortSeekKeyCodes[i]);
287            glue.onKey(null, abortSeekKeyCodes[i], kv);
288            assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
289            assertEquals(0, fastForward.getIndex());
290            assertEquals(0, rewind.getIndex());
291        }
292    }
293
294    @Test
295    public void testRewindAbortKeyCodes() {
296        PlaybackControlsRow row = new PlaybackControlsRow();
297        glue.setControlsRow(row);
298        SparseArrayObjectAdapter adapter = (SparseArrayObjectAdapter)
299                row.getPrimaryActionsAdapter();
300        PlaybackControlsRow.MultiAction playPause = (PlaybackControlsRow.MultiAction) adapter
301                .lookup(PlaybackControlGlue.ACTION_PLAY_PAUSE);
302        PlaybackControlsRow.MultiAction fastForward = (PlaybackControlsRow.MultiAction) adapter
303                .lookup(PlaybackControlGlue.ACTION_FAST_FORWARD);
304        PlaybackControlsRow.MultiAction rewind = (PlaybackControlsRow.MultiAction) adapter
305                .lookup(PlaybackControlGlue.ACTION_REWIND);
306
307        glue.onActionClicked(playPause);
308        assertTrue(glue.isMediaPlaying());
309        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
310        assertEquals(0, fastForward.getIndex());
311        assertEquals(0, rewind.getIndex());
312
313        // Testing keycodes that will not abort seek
314        final int[] noAbortSeekKeyCodes = new int[] {
315                KeyEvent.KEYCODE_DPAD_CENTER,
316                KeyEvent.KEYCODE_ENTER
317        };
318        for (int i = 0; i < noAbortSeekKeyCodes.length; i++) {
319            glue.onActionClicked(rewind);
320            assertEquals(-PlaybackControlGlue.PLAYBACK_SPEED_FAST_L0, glue.getCurrentSpeedId());
321            assertEquals(0, fastForward.getIndex());
322            assertEquals(1, rewind.getIndex());
323            KeyEvent kv = new KeyEvent(KeyEvent.ACTION_DOWN, noAbortSeekKeyCodes[i]);
324            glue.onKey(null, noAbortSeekKeyCodes[i], kv);
325            assertEquals(-PlaybackControlGlue.PLAYBACK_SPEED_FAST_L0, glue.getCurrentSpeedId());
326            glue.onActionClicked(playPause);
327            assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
328        }
329
330        // Testing abortSeekKeyCodes
331        final int[] abortSeekKeyCodes = new int[] {
332                KeyEvent.KEYCODE_DPAD_UP,
333                KeyEvent.KEYCODE_DPAD_DOWN,
334                KeyEvent.KEYCODE_DPAD_RIGHT,
335                KeyEvent.KEYCODE_DPAD_LEFT,
336                KeyEvent.KEYCODE_BACK,
337                KeyEvent.KEYCODE_ESCAPE
338        };
339        for (int i = 0; i < abortSeekKeyCodes.length; i++) {
340            glue.onActionClicked(rewind);
341            assertEquals(-PlaybackControlGlue.PLAYBACK_SPEED_FAST_L0, glue.getCurrentSpeedId());
342            assertEquals(0, fastForward.getIndex());
343            assertEquals(1, rewind.getIndex());
344            KeyEvent kv = new KeyEvent(KeyEvent.ACTION_DOWN, abortSeekKeyCodes[i]);
345            glue.onKey(null, abortSeekKeyCodes[i], kv);
346            assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
347            assertEquals(0, fastForward.getIndex());
348            assertEquals(0, rewind.getIndex());
349        }
350    }
351
352    @Test
353    public void testMediaPauseButtonOnFF() {
354        PlaybackControlsRow row = new PlaybackControlsRow();
355        glue.setControlsRow(row);
356        SparseArrayObjectAdapter adapter = (SparseArrayObjectAdapter)
357                row.getPrimaryActionsAdapter();
358        PlaybackControlsRow.MultiAction playPause = (PlaybackControlsRow.MultiAction) adapter
359                .lookup(PlaybackControlGlue.ACTION_PLAY_PAUSE);
360        PlaybackControlsRow.MultiAction fastForward = (PlaybackControlsRow.MultiAction) adapter
361                .lookup(PlaybackControlGlue.ACTION_FAST_FORWARD);
362
363        glue.onActionClicked(playPause);
364        glue.onActionClicked(fastForward);
365        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_FAST_L0, glue.getCurrentSpeedId());
366        glue.onKey(null, KeyEvent.KEYCODE_MEDIA_PAUSE, new KeyEvent(KeyEvent.ACTION_DOWN,
367                KeyEvent.KEYCODE_MEDIA_PAUSE));
368        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_PAUSED, glue.getCurrentSpeedId());
369    }
370
371    @Test
372    public void testMediaPauseButtonOnPlay() {
373        PlaybackControlsRow row = new PlaybackControlsRow();
374        glue.setControlsRow(row);
375        SparseArrayObjectAdapter adapter = (SparseArrayObjectAdapter)
376                row.getPrimaryActionsAdapter();
377        PlaybackControlsRow.MultiAction playPause = (PlaybackControlsRow.MultiAction) adapter
378                .lookup(PlaybackControlGlue.ACTION_PLAY_PAUSE);
379
380        glue.onActionClicked(playPause);
381        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
382        glue.onKey(null, KeyEvent.KEYCODE_MEDIA_PAUSE, new KeyEvent(KeyEvent.ACTION_DOWN,
383                KeyEvent.KEYCODE_MEDIA_PAUSE));
384        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_PAUSED, glue.getCurrentSpeedId());
385    }
386
387    @Test
388    public void testMediaPauseButtonOnPause() {
389        PlaybackControlsRow row = new PlaybackControlsRow();
390        glue.setControlsRow(row);
391        SparseArrayObjectAdapter adapter = (SparseArrayObjectAdapter)
392                row.getPrimaryActionsAdapter();
393        PlaybackControlsRow.MultiAction playPause = (PlaybackControlsRow.MultiAction) adapter
394                .lookup(PlaybackControlGlue.ACTION_PLAY_PAUSE);
395
396        glue.onActionClicked(playPause);
397        glue.onActionClicked(playPause);
398        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_PAUSED, glue.getCurrentSpeedId());
399        glue.onKey(null, KeyEvent.KEYCODE_MEDIA_PAUSE, new KeyEvent(KeyEvent.ACTION_DOWN,
400                KeyEvent.KEYCODE_MEDIA_PAUSE));
401        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_PAUSED, glue.getCurrentSpeedId());
402    }
403
404    @Test
405    public void testMediaPlayButtonOnFF() {
406        PlaybackControlsRow row = new PlaybackControlsRow();
407        glue.setControlsRow(row);
408        SparseArrayObjectAdapter adapter = (SparseArrayObjectAdapter)
409                row.getPrimaryActionsAdapter();
410        PlaybackControlsRow.MultiAction playPause = (PlaybackControlsRow.MultiAction) adapter
411                .lookup(PlaybackControlGlue.ACTION_PLAY_PAUSE);
412        PlaybackControlsRow.MultiAction fastForward = (PlaybackControlsRow.MultiAction) adapter
413                .lookup(PlaybackControlGlue.ACTION_FAST_FORWARD);
414
415        glue.onActionClicked(playPause);
416        glue.onActionClicked(fastForward);
417        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_FAST_L0, glue.getCurrentSpeedId());
418        glue.onKey(null, KeyEvent.KEYCODE_MEDIA_PLAY, new KeyEvent(KeyEvent.ACTION_DOWN,
419                KeyEvent.KEYCODE_MEDIA_PLAY));
420        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
421    }
422
423    @Test
424    public void testMediaPlayButtonOnPlay() {
425        PlaybackControlsRow row = new PlaybackControlsRow();
426        glue.setControlsRow(row);
427        SparseArrayObjectAdapter adapter = (SparseArrayObjectAdapter)
428                row.getPrimaryActionsAdapter();
429        PlaybackControlsRow.MultiAction playPause = (PlaybackControlsRow.MultiAction) adapter
430                .lookup(PlaybackControlGlue.ACTION_PLAY_PAUSE);
431
432        glue.onActionClicked(playPause);
433        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
434        glue.onKey(null, KeyEvent.KEYCODE_MEDIA_PLAY, new KeyEvent(KeyEvent.ACTION_DOWN,
435                KeyEvent.KEYCODE_MEDIA_PLAY));
436        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
437    }
438
439    @Test
440    public void testMediaPlayButtonOnPause() {
441        PlaybackControlsRow row = new PlaybackControlsRow();
442        glue.setControlsRow(row);
443        SparseArrayObjectAdapter adapter = (SparseArrayObjectAdapter)
444                row.getPrimaryActionsAdapter();
445        PlaybackControlsRow.MultiAction playPause = (PlaybackControlsRow.MultiAction) adapter
446                .lookup(PlaybackControlGlue.ACTION_PLAY_PAUSE);
447
448        glue.onActionClicked(playPause);
449        glue.onActionClicked(playPause);
450        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_PAUSED, glue.getCurrentSpeedId());
451        glue.onKey(null, KeyEvent.KEYCODE_MEDIA_PLAY, new KeyEvent(KeyEvent.ACTION_DOWN,
452                KeyEvent.KEYCODE_MEDIA_PLAY));
453        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
454    }
455
456    @Test
457    public void testMediaPlayPauseButtonOnFF() {
458        PlaybackControlsRow row = new PlaybackControlsRow();
459        glue.setControlsRow(row);
460        SparseArrayObjectAdapter adapter = (SparseArrayObjectAdapter)
461                row.getPrimaryActionsAdapter();
462        PlaybackControlsRow.MultiAction playPause = (PlaybackControlsRow.MultiAction) adapter
463                .lookup(PlaybackControlGlue.ACTION_PLAY_PAUSE);
464        PlaybackControlsRow.MultiAction fastForward = (PlaybackControlsRow.MultiAction) adapter
465                .lookup(PlaybackControlGlue.ACTION_FAST_FORWARD);
466
467        glue.onActionClicked(playPause);
468        glue.onActionClicked(fastForward);
469        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_FAST_L0, glue.getCurrentSpeedId());
470        glue.onKey(null, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, new KeyEvent(KeyEvent.ACTION_DOWN,
471                KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
472        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
473    }
474
475    @Test
476    public void testMediaPlayPauseButtonOnPlay() {
477        PlaybackControlsRow row = new PlaybackControlsRow();
478        glue.setControlsRow(row);
479        SparseArrayObjectAdapter adapter = (SparseArrayObjectAdapter)
480                row.getPrimaryActionsAdapter();
481        PlaybackControlsRow.MultiAction playPause = (PlaybackControlsRow.MultiAction) adapter
482                .lookup(PlaybackControlGlue.ACTION_PLAY_PAUSE);
483
484        glue.onActionClicked(playPause);
485        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
486        glue.onKey(null, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, new KeyEvent(KeyEvent.ACTION_DOWN,
487                KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
488        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_PAUSED, glue.getCurrentSpeedId());
489    }
490
491    @Test
492    public void testMediaPlayPauseButtonOnPause() {
493        PlaybackControlsRow row = new PlaybackControlsRow();
494        glue.setControlsRow(row);
495        SparseArrayObjectAdapter adapter = (SparseArrayObjectAdapter)
496                row.getPrimaryActionsAdapter();
497        PlaybackControlsRow.MultiAction playPause = (PlaybackControlsRow.MultiAction) adapter
498                .lookup(PlaybackControlGlue.ACTION_PLAY_PAUSE);
499
500        glue.onActionClicked(playPause);
501        glue.onActionClicked(playPause);
502        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_PAUSED, glue.getCurrentSpeedId());
503        glue.onKey(null, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, new KeyEvent(KeyEvent.ACTION_DOWN,
504                KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
505        assertEquals(PlaybackControlGlue.PLAYBACK_SPEED_NORMAL, glue.getCurrentSpeedId());
506    }
507
508}
509