ContentViewScrollingTest.java revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package org.chromium.content.browser;
6
7import android.test.suitebuilder.annotation.SmallTest;
8
9import org.chromium.base.test.util.Feature;
10import org.chromium.content_shell.ContentShellTestBase;
11
12/*
13 * Tests that we can scroll and fling a ContentView running inside ContentShell.
14 */
15public class ContentViewScrollingTest extends ContentShellTestBase {
16
17    private static final String LARGE_PAGE = "data:text/html;utf-8,"
18        + "<html>"
19        + "<head><style>body { width: 5000px; height: 5000px; }</style></head>"
20        + "<body>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</body>"
21        + "</html>";
22
23    @SmallTest
24    @Feature({"Android-WebView"})
25    public void testFling() throws Throwable {
26        launchContentShellWithUrl(LARGE_PAGE);
27        waitForActiveShellToBeDoneLoading();
28        final ContentView view = getActivity().getActiveContentView();
29
30        assertEquals(0, view.getContentViewCore().getNativeScrollXForTest());
31        assertEquals(0, view.getContentViewCore().getNativeScrollYForTest());
32
33        // Vertical fling
34        runTestOnUiThread(new Runnable() {
35            @Override
36            public void run() {
37                view.fling(System.currentTimeMillis(), 0, 0, 0, -1000);
38            }
39        });
40
41        // There's no end-of-fling notification so we need to busy-wait.
42        for (int i = 0; i < 500; ++i) {
43          if (view.getContentViewCore().getNativeScrollYForTest() > 100) {
44            break;
45          }
46          Thread.sleep(10);
47        }
48
49        assertEquals(0, view.getContentViewCore().getNativeScrollXForTest());
50        assertTrue(view.getContentViewCore().getNativeScrollYForTest() > 100);
51
52        // Horizontal fling
53        runTestOnUiThread(new Runnable() {
54            @Override
55            public void run() {
56                view.fling(System.currentTimeMillis(), 0, 0, -1000, 0);
57            }
58        });
59
60        // There's no end-of-fling notification so we need to busy-wait.
61        for (int i = 0; i < 500; ++i) {
62          if (view.getContentViewCore().getNativeScrollXForTest() > 100) {
63            break;
64          }
65          Thread.sleep(10);
66        }
67
68        assertTrue(view.getContentViewCore().getNativeScrollXForTest() > 100);
69        assertTrue(view.getContentViewCore().getNativeScrollYForTest() > 100);
70    }
71}
72