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 com.android.cts.transition.R;
19 
20 import android.transition.ChangeScroll;
21 import android.transition.Transition;
22 import android.transition.TransitionManager;
23 import android.view.View;
24 
25 public class ChangeScrollTest extends BaseTransitionTest {
26 
ChangeScrollTest()27     public ChangeScrollTest() {
28     }
29 
testChangeScroll()30     public void testChangeScroll() throws Throwable {
31         enterScene(R.layout.scene5);
32         final Transition transition = new ChangeScroll();
33         transition.setDuration(100);
34         SimpleTransitionListener listener = new SimpleTransitionListener();
35         transition.addListener(listener);
36         runTestOnUiThread(new Runnable() {
37             @Override
38             public void run() {
39                 final View view = mActivity.findViewById(R.id.text);
40                 final int scrollX = view.getScrollX();
41                 final int scrollY = view.getScrollY();
42                 assertEquals(0, scrollX);
43                 assertEquals(0, scrollY);
44                 TransitionManager.beginDelayedTransition(mSceneRoot, transition);
45                 view.scrollTo(150, 300);
46             }
47         });
48         waitForStart(listener);
49         waitForAnimationFrame();
50         runTestOnUiThread(new Runnable() {
51             @Override
52             public void run() {
53                 final View view = mActivity.findViewById(R.id.text);
54                 final int scrollX = view.getScrollX();
55                 final int scrollY = view.getScrollY();
56                 assertTrue(scrollX > 0);
57                 assertTrue(scrollX < 150);
58                 assertTrue(scrollY > 0);
59                 assertTrue(scrollY < 300);
60             }
61         });
62         waitForEnd(listener, 100);
63         runTestOnUiThread(new Runnable() {
64             @Override
65             public void run() {
66                 final View view = mActivity.findViewById(R.id.text);
67                 final int scrollX = view.getScrollX();
68                 final int scrollY = view.getScrollY();
69                 assertEquals(150, scrollX);
70                 assertEquals(300, scrollY);
71             }
72         });
73     }
74 }
75 
76