1 /* 2 * Copyright (C) 2015 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 */ 16 17 package com.android.tv; 18 19 import static com.android.tv.TimeShiftManager.INVALID_TIME; 20 import static com.android.tv.TimeShiftManager.REQUEST_TIMEOUT_MS; 21 22 import android.test.UiThreadTest; 23 import android.test.suitebuilder.annotation.MediumTest; 24 25 @MediumTest 26 public class CurrentPositionMediatorTest extends BaseMainActivityTestCase { 27 private TimeShiftManager.CurrentPositionMediator mMediator; 28 CurrentPositionMediatorTest()29 public CurrentPositionMediatorTest() { 30 super(MainActivity.class); 31 } 32 33 @Override setUp()34 protected void setUp() throws Exception { 35 super.setUp(); 36 mMediator = mActivity.getTimeShiftManager().mCurrentPositionMediator; 37 } 38 39 @UiThreadTest testInitialize()40 public void testInitialize() throws Throwable { 41 long currentTimeMs = System.currentTimeMillis(); 42 mMediator.initialize(currentTimeMs); 43 assertCurrentPositionMediator(INVALID_TIME, currentTimeMs); 44 } 45 46 @UiThreadTest testOnSeekRequested()47 public void testOnSeekRequested() throws Throwable { 48 long seekToTimeMs = System.currentTimeMillis() - REQUEST_TIMEOUT_MS * 3; 49 mMediator.onSeekRequested(seekToTimeMs); 50 assertNotSame("Seek request time", INVALID_TIME, mMediator.mSeekRequestTimeMs); 51 assertEquals("Current position", seekToTimeMs, mMediator.mCurrentPositionMs); 52 } 53 54 @UiThreadTest testOnCurrentPositionChangedInvalidInput()55 public void testOnCurrentPositionChangedInvalidInput() throws Throwable { 56 long seekToTimeMs = System.currentTimeMillis() - REQUEST_TIMEOUT_MS * 3; 57 long newCurrentTimeMs = seekToTimeMs + REQUEST_TIMEOUT_MS; 58 mMediator.onSeekRequested(seekToTimeMs); 59 mMediator.onCurrentPositionChanged(newCurrentTimeMs); 60 assertNotSame("Seek request time", INVALID_TIME, mMediator.mSeekRequestTimeMs); 61 assertNotSame("Current position", seekToTimeMs, mMediator.mCurrentPositionMs); 62 assertNotSame("Current position", newCurrentTimeMs, mMediator.mCurrentPositionMs); 63 } 64 65 @UiThreadTest testOnCurrentPositionChangedValidInput()66 public void testOnCurrentPositionChangedValidInput() throws Throwable { 67 long seekToTimeMs = System.currentTimeMillis() - REQUEST_TIMEOUT_MS * 3; 68 long newCurrentTimeMs = seekToTimeMs + REQUEST_TIMEOUT_MS - 1; 69 mMediator.onSeekRequested(seekToTimeMs); 70 mMediator.onCurrentPositionChanged(newCurrentTimeMs); 71 assertCurrentPositionMediator(INVALID_TIME, newCurrentTimeMs); 72 } 73 assertCurrentPositionMediator(long expectedSeekRequestTimeMs, long expectedCurrentPositionMs)74 private void assertCurrentPositionMediator(long expectedSeekRequestTimeMs, 75 long expectedCurrentPositionMs) { 76 assertEquals("Seek request time", expectedSeekRequestTimeMs, mMediator.mSeekRequestTimeMs); 77 assertEquals("Current position", expectedCurrentPositionMs, mMediator.mCurrentPositionMs); 78 } 79 } 80