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
17package androidx.transition;
18
19import static org.hamcrest.CoreMatchers.both;
20import static org.hamcrest.Matchers.greaterThan;
21import static org.hamcrest.Matchers.lessThan;
22import static org.hamcrest.core.Is.is;
23import static org.junit.Assert.assertEquals;
24import static org.junit.Assert.assertThat;
25
26import android.support.test.filters.MediumTest;
27import android.view.View;
28
29import androidx.transition.test.R;
30
31import org.junit.Test;
32
33@MediumTest
34public 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