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