OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.android_webview.test; | 5 package org.chromium.android_webview.test; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.test.suitebuilder.annotation.SmallTest; | 8 import android.test.suitebuilder.annotation.SmallTest; |
9 import android.view.View; | 9 import android.view.View; |
10 import android.widget.OverScroller; | 10 import android.widget.OverScroller; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 122 } |
123 @Override | 123 @Override |
124 public AwTestContainerView createAwTestContainerView(AwTestRunnerAct
ivity activity, | 124 public AwTestContainerView createAwTestContainerView(AwTestRunnerAct
ivity activity, |
125 boolean allowHardwareAcceleration) { | 125 boolean allowHardwareAcceleration) { |
126 return new ScrollTestContainerView(activity, allowHardwareAccele
ration); | 126 return new ScrollTestContainerView(activity, allowHardwareAccele
ration); |
127 } | 127 } |
128 }; | 128 }; |
129 } | 129 } |
130 | 130 |
131 private static final String TEST_PAGE_COMMON_HEADERS = | 131 private static final String TEST_PAGE_COMMON_HEADERS = |
132 "<meta name=\"viewport\" content=\"width=device-width, initial-scale
=1\"> " + | 132 "<meta name=\"viewport\" content=\"" + |
| 133 "width=device-width, initial-scale=1, minimum-scale=1\"> " + |
133 "<style type=\"text/css\"> " + | 134 "<style type=\"text/css\"> " + |
134 " body { " + | 135 " body { " + |
135 " margin: 0px; " + | 136 " margin: 0px; " + |
136 " } " + | 137 " } " + |
137 " div { " + | 138 " div { " + |
138 " width:1000px; " + | 139 " width:1000px; " + |
139 " height:10000px; " + | 140 " height:10000px; " + |
140 " background-color: blue; " + | 141 " background-color: blue; " + |
141 " } " + | 142 " } " + |
142 "</style> "; | 143 "</style> "; |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 null /* completionLatch */); | 534 null /* completionLatch */); |
534 overScrollByCallbackHelper.waitForCallback(overScrollCallCount); | 535 overScrollByCallbackHelper.waitForCallback(overScrollCallCount); |
535 assertEquals(0, overScrollByCallbackHelper.getDeltaX()); | 536 assertEquals(0, overScrollByCallbackHelper.getDeltaX()); |
536 assertTrue(0 > overScrollByCallbackHelper.getDeltaY()); | 537 assertTrue(0 > overScrollByCallbackHelper.getDeltaY()); |
537 | 538 |
538 assertScrollOnMainSync(testContainerView, 0, 0); | 539 assertScrollOnMainSync(testContainerView, 0, 0); |
539 } | 540 } |
540 | 541 |
541 @SmallTest | 542 @SmallTest |
542 @Feature({"AndroidWebView"}) | 543 @Feature({"AndroidWebView"}) |
543 public void testScrollToBottomAtPageScaleX0dot5() throws Throwable { | |
544 // The idea behind this test is to check that scrolling to the bottom on
ther renderer side | |
545 // results in the view also reporting as being scrolled to the bottom. | |
546 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | |
547 final ScrollTestContainerView testContainerView = | |
548 (ScrollTestContainerView) createAwTestContainerViewOnMainSync(co
ntentsClient); | |
549 enableJavaScriptOnUiThread(testContainerView.getAwContents()); | |
550 | |
551 final int targetScrollXCss = 1000; | |
552 final int targetScrollYCss = 10000; | |
553 | |
554 final String pageHeaders = | |
555 "<meta name=\"viewport\" content=\"width=device-width, initial-s
cale=0.6\"> " + | |
556 "<style type=\"text/css\"> " + | |
557 " div { " + | |
558 " width:1000px; " + | |
559 " height:10000px; " + | |
560 " background-color: blue; " + | |
561 " } " + | |
562 " body { " + | |
563 " margin: 0px; " + | |
564 " padding: 0px; " + | |
565 " } " + | |
566 "</style> "; | |
567 | |
568 loadDataSync(testContainerView.getAwContents(), contentsClient.getOnPage
FinishedHelper(), | |
569 CommonResources.makeHtmlPageFrom(pageHeaders, TEST_PAGE_COMMON_C
ONTENT), | |
570 "text/html", false); | |
571 | |
572 final double deviceDIPScale = | |
573 DeviceDisplayInfo.create(testContainerView.getContext()).getDIPS
cale(); | |
574 | |
575 final CallbackHelper onScrollToCallbackHelper = | |
576 testContainerView.getOnScrollToCallbackHelper(); | |
577 int scrollToCallCount = onScrollToCallbackHelper.getCallCount(); | |
578 executeJavaScriptAndWaitForResult(testContainerView.getAwContents(), con
tentsClient, | |
579 "window.scrollTo(" + targetScrollXCss + "," + targetScrollYCss +
")"); | |
580 onScrollToCallbackHelper.waitForCallback(scrollToCallCount); | |
581 | |
582 getInstrumentation().runOnMainSync(new Runnable() { | |
583 @Override | |
584 public void run() { | |
585 AwContents awContents = testContainerView.getAwContents(); | |
586 int maxHorizontal = awContents.computeHorizontalScrollRange() - | |
587 testContainerView.getWidth(); | |
588 int maxVertical = awContents.computeVerticalScrollRange() - | |
589 testContainerView.getHeight(); | |
590 // Due to rounding going from CSS -> physical pixels it is possi
ble that more than | |
591 // one physical pixels corespond to one CSS pixel, which is why
we can't do a | |
592 // simple equality test here. | |
593 assertTrue(maxHorizontal - awContents.computeHorizontalScrollOff
set() < 3); | |
594 assertTrue(maxVertical - awContents.computeVerticalScrollOffset(
) < 3); | |
595 } | |
596 }); | |
597 | |
598 scrollToCallCount = onScrollToCallbackHelper.getCallCount(); | |
599 executeJavaScriptAndWaitForResult(testContainerView.getAwContents(), con
tentsClient, | |
600 "window.scrollTo(0, 0)"); | |
601 onScrollToCallbackHelper.waitForCallback(scrollToCallCount); | |
602 | |
603 getInstrumentation().runOnMainSync(new Runnable() { | |
604 @Override | |
605 public void run() { | |
606 AwContents awContents = testContainerView.getAwContents(); | |
607 int maxHorizontal = awContents.computeHorizontalScrollRange() - | |
608 testContainerView.getWidth(); | |
609 int maxVertical = awContents.computeVerticalScrollRange() - | |
610 testContainerView.getHeight(); | |
611 testContainerView.scrollTo(maxHorizontal, maxVertical); | |
612 } | |
613 }); | |
614 assertScrolledToBottomInJs(testContainerView.getAwContents(), contentsCl
ient); | |
615 } | |
616 | |
617 @SmallTest | |
618 @Feature({"AndroidWebView"}) | |
619 public void testFlingScroll() throws Throwable { | 544 public void testFlingScroll() throws Throwable { |
620 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 545 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
621 final ScrollTestContainerView testContainerView = | 546 final ScrollTestContainerView testContainerView = |
622 (ScrollTestContainerView) createAwTestContainerViewOnMainSync(co
ntentsClient); | 547 (ScrollTestContainerView) createAwTestContainerViewOnMainSync(co
ntentsClient); |
623 enableJavaScriptOnUiThread(testContainerView.getAwContents()); | 548 enableJavaScriptOnUiThread(testContainerView.getAwContents()); |
624 | 549 |
625 loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, null
, ""); | 550 loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, null
, ""); |
626 | 551 |
627 assertScrollOnMainSync(testContainerView, 0, 0); | 552 assertScrollOnMainSync(testContainerView, 0, 0); |
628 | 553 |
(...skipping 12 matching lines...) Expand all Loading... |
641 | 566 |
642 getInstrumentation().runOnMainSync(new Runnable() { | 567 getInstrumentation().runOnMainSync(new Runnable() { |
643 @Override | 568 @Override |
644 public void run() { | 569 public void run() { |
645 assertTrue(testContainerView.getScrollX() > 0); | 570 assertTrue(testContainerView.getScrollX() > 0); |
646 assertTrue(testContainerView.getScrollY() > 0); | 571 assertTrue(testContainerView.getScrollY() > 0); |
647 } | 572 } |
648 }); | 573 }); |
649 } | 574 } |
650 | 575 |
| 576 @DisableHardwareAccelerationForTest |
651 @SmallTest | 577 @SmallTest |
652 @Feature({"AndroidWebView"}) | 578 @Feature({"AndroidWebView"}) |
653 public void testPageDown() throws Throwable { | 579 public void testPageDown() throws Throwable { |
654 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 580 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
655 final ScrollTestContainerView testContainerView = | 581 final ScrollTestContainerView testContainerView = |
656 (ScrollTestContainerView) createAwTestContainerViewOnMainSync(co
ntentsClient); | 582 (ScrollTestContainerView) createAwTestContainerViewOnMainSync(co
ntentsClient); |
657 enableJavaScriptOnUiThread(testContainerView.getAwContents()); | 583 enableJavaScriptOnUiThread(testContainerView.getAwContents()); |
658 | 584 |
659 loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, null
, ""); | 585 loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, null
, ""); |
660 | 586 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 assertTrue(String.format(Locale.ENGLISH, | 761 assertTrue(String.format(Locale.ENGLISH, |
836 "Scroll range should increase after zoom (%d) > (%d)", | 762 "Scroll range should increase after zoom (%d) > (%d)", |
837 newScrollRange, oldScrollRange), newScrollRange > oldScr
ollRange); | 763 newScrollRange, oldScrollRange), newScrollRange > oldScr
ollRange); |
838 assertEquals(awContents.getContentHeightCss(), oldContentHeightA
pproximation); | 764 assertEquals(awContents.getContentHeightCss(), oldContentHeightA
pproximation); |
839 assertEquals(awContents.getContentHeightCss(), newContentHeightA
pproximation); | 765 assertEquals(awContents.getContentHeightCss(), newContentHeightA
pproximation); |
840 } | 766 } |
841 }); | 767 }); |
842 | 768 |
843 } | 769 } |
844 } | 770 } |
OLD | NEW |