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 package android.transition.cts; 17 18 import static org.junit.Assert.assertEquals; 19 import static org.junit.Assert.assertTrue; 20 21 import android.transition.ChangeScroll; 22 import android.transition.TransitionManager; 23 import android.view.View; 24 25 import androidx.test.filters.MediumTest; 26 import androidx.test.runner.AndroidJUnit4; 27 28 import org.junit.Before; 29 import org.junit.Test; 30 import org.junit.runner.RunWith; 31 32 import java.util.concurrent.CountDownLatch; 33 import java.util.concurrent.TimeUnit; 34 35 @MediumTest 36 @RunWith(AndroidJUnit4.class) 37 public class ChangeScrollTest extends BaseTransitionTest { 38 ChangeScroll mChangeScroll; 39 40 @Override 41 @Before setup()42 public void setup() { 43 super.setup(); 44 mChangeScroll = new ChangeScroll(); 45 mTransition = mChangeScroll; 46 resetListener(); 47 } 48 49 @Test testChangeScroll()50 public void testChangeScroll() throws Throwable { 51 enterScene(R.layout.scene5); 52 final CountDownLatch scrollChanged = new CountDownLatch(1); 53 final View.OnScrollChangeListener listener = (v, newX, newY, oldX, oldY) -> { 54 if (newX != 0 && newY != 0) { 55 scrollChanged.countDown(); 56 } 57 }; 58 mActivityRule.runOnUiThread(() -> { 59 final View view = mActivity.findViewById(R.id.text); 60 assertEquals(0, view.getScrollX()); 61 assertEquals(0, view.getScrollY()); 62 TransitionManager.beginDelayedTransition(mSceneRoot, mChangeScroll); 63 view.scrollTo(150, 300); 64 view.setOnScrollChangeListener(listener); 65 }); 66 waitForStart(); 67 assertTrue(scrollChanged.await(1, TimeUnit.SECONDS)); 68 mActivityRule.runOnUiThread(() -> { 69 final View view = mActivity.findViewById(R.id.text); 70 final int scrollX = view.getScrollX(); 71 final int scrollY = view.getScrollY(); 72 assertTrue(scrollX > 0); 73 assertTrue(scrollX < 150); 74 assertTrue(scrollY > 0); 75 assertTrue(scrollY < 300); 76 }); 77 waitForEnd(800); 78 mActivityRule.runOnUiThread(() -> { 79 final View view = mActivity.findViewById(R.id.text); 80 assertEquals(150, view.getScrollX()); 81 assertEquals(300, view.getScrollY()); 82 }); 83 } 84 } 85 86