Home | History | Annotate | Download | only in transition
      1 /*
      2  * Copyright (C) 2017 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 androidx.transition;
     18 
     19 import static org.hamcrest.CoreMatchers.both;
     20 import static org.hamcrest.Matchers.greaterThan;
     21 import static org.hamcrest.Matchers.lessThan;
     22 import static org.hamcrest.core.Is.is;
     23 import static org.junit.Assert.assertEquals;
     24 import static org.junit.Assert.assertThat;
     25 
     26 import android.support.test.filters.MediumTest;
     27 import android.view.View;
     28 
     29 import androidx.transition.test.R;
     30 
     31 import org.junit.Test;
     32 
     33 @MediumTest
     34 public class ChangeScrollTest extends BaseTransitionTest {
     35 
     36     @Override
     37     Transition createTransition() {
     38         return new ChangeScroll();
     39     }
     40 
     41     @Test
     42     public void testChangeScroll() throws Throwable {
     43         enterScene(R.layout.scene5);
     44         rule.runOnUiThread(new Runnable() {
     45             @Override
     46             public void run() {
     47                 final View view = rule.getActivity().findViewById(R.id.text);
     48                 assertEquals(0, view.getScrollX());
     49                 assertEquals(0, view.getScrollY());
     50                 TransitionManager.beginDelayedTransition(mRoot, mTransition);
     51                 view.scrollTo(150, 300);
     52             }
     53         });
     54         waitForStart();
     55         Thread.sleep(150);
     56         rule.runOnUiThread(new Runnable() {
     57             @Override
     58             public void run() {
     59                 final View view = rule.getActivity().findViewById(R.id.text);
     60                 final int scrollX = view.getScrollX();
     61                 final int scrollY = view.getScrollY();
     62                 assertThat(scrollX, is(both(greaterThan(0)).and(lessThan(150))));
     63                 assertThat(scrollY, is(both(greaterThan(0)).and(lessThan(300))));
     64             }
     65         });
     66         waitForEnd();
     67         rule.runOnUiThread(new Runnable() {
     68             @Override
     69             public void run() {
     70                 final View view = rule.getActivity().findViewById(R.id.text);
     71                 assertEquals(150, view.getScrollX());
     72                 assertEquals(300, view.getScrollY());
     73             }
     74         });
     75     }
     76 
     77 }
     78