| 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.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.test.suitebuilder.annotation.SmallTest; | 9 import android.test.suitebuilder.annotation.SmallTest; |
| 10 import android.view.View; | 10 import android.view.View; |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 | 315 |
| 316 @SmallTest | 316 @SmallTest |
| 317 @Feature({"AndroidWebView"}) | 317 @Feature({"AndroidWebView"}) |
| 318 public void testUiScrollReflectedInJs() throws Throwable { | 318 public void testUiScrollReflectedInJs() throws Throwable { |
| 319 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 319 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
| 320 final ScrollTestContainerView testContainerView = | 320 final ScrollTestContainerView testContainerView = |
| 321 (ScrollTestContainerView) createAwTestContainerViewOnMainSync(co
ntentsClient); | 321 (ScrollTestContainerView) createAwTestContainerViewOnMainSync(co
ntentsClient); |
| 322 enableJavaScriptOnUiThread(testContainerView.getAwContents()); | 322 enableJavaScriptOnUiThread(testContainerView.getAwContents()); |
| 323 | 323 |
| 324 final double deviceDIPScale = | 324 final double deviceDIPScale = |
| 325 DisplayAndroid.getNonMultiDisplay(testContainerView.getContext()
).getDIPScale(); | 325 DisplayAndroid.getNonMultiDisplay(testContainerView.getContext()
).getDipScale(); |
| 326 final int targetScrollXCss = 233; | 326 final int targetScrollXCss = 233; |
| 327 final int targetScrollYCss = 322; | 327 final int targetScrollYCss = 322; |
| 328 final int targetScrollXPix = (int) Math.ceil(targetScrollXCss * deviceDI
PScale); | 328 final int targetScrollXPix = (int) Math.ceil(targetScrollXCss * deviceDI
PScale); |
| 329 final int targetScrollYPix = (int) Math.ceil(targetScrollYCss * deviceDI
PScale); | 329 final int targetScrollYPix = (int) Math.ceil(targetScrollYCss * deviceDI
PScale); |
| 330 final JavascriptEventObserver onscrollObserver = new JavascriptEventObse
rver(); | 330 final JavascriptEventObserver onscrollObserver = new JavascriptEventObse
rver(); |
| 331 | 331 |
| 332 getInstrumentation().runOnMainSync(new Runnable() { | 332 getInstrumentation().runOnMainSync(new Runnable() { |
| 333 @Override | 333 @Override |
| 334 public void run() { | 334 public void run() { |
| 335 onscrollObserver.register(testContainerView.getContentViewCore()
, | 335 onscrollObserver.register(testContainerView.getContentViewCore()
, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 349 @SmallTest | 349 @SmallTest |
| 350 @Feature({"AndroidWebView"}) | 350 @Feature({"AndroidWebView"}) |
| 351 @SuppressLint("DefaultLocale") | 351 @SuppressLint("DefaultLocale") |
| 352 public void testJsScrollReflectedInUi() throws Throwable { | 352 public void testJsScrollReflectedInUi() throws Throwable { |
| 353 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 353 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
| 354 final ScrollTestContainerView testContainerView = | 354 final ScrollTestContainerView testContainerView = |
| 355 (ScrollTestContainerView) createAwTestContainerViewOnMainSync(co
ntentsClient); | 355 (ScrollTestContainerView) createAwTestContainerViewOnMainSync(co
ntentsClient); |
| 356 enableJavaScriptOnUiThread(testContainerView.getAwContents()); | 356 enableJavaScriptOnUiThread(testContainerView.getAwContents()); |
| 357 | 357 |
| 358 final double deviceDIPScale = | 358 final double deviceDIPScale = |
| 359 DisplayAndroid.getNonMultiDisplay(testContainerView.getContext()
).getDIPScale(); | 359 DisplayAndroid.getNonMultiDisplay(testContainerView.getContext()
).getDipScale(); |
| 360 final int targetScrollXCss = 132; | 360 final int targetScrollXCss = 132; |
| 361 final int targetScrollYCss = 243; | 361 final int targetScrollYCss = 243; |
| 362 final int targetScrollXPix = (int) Math.floor(targetScrollXCss * deviceD
IPScale); | 362 final int targetScrollXPix = (int) Math.floor(targetScrollXCss * deviceD
IPScale); |
| 363 final int targetScrollYPix = (int) Math.floor(targetScrollYCss * deviceD
IPScale); | 363 final int targetScrollYPix = (int) Math.floor(targetScrollYCss * deviceD
IPScale); |
| 364 | 364 |
| 365 loadDataSync(testContainerView.getAwContents(), contentsClient.getOnPage
FinishedHelper(), | 365 loadDataSync(testContainerView.getAwContents(), contentsClient.getOnPage
FinishedHelper(), |
| 366 makeTestPage(null, null, ""), "text/html", false); | 366 makeTestPage(null, null, ""), "text/html", false); |
| 367 | 367 |
| 368 final CallbackHelper onScrollToCallbackHelper = | 368 final CallbackHelper onScrollToCallbackHelper = |
| 369 testContainerView.getOnScrollToCallbackHelper(); | 369 testContainerView.getOnScrollToCallbackHelper(); |
| 370 final int scrollToCallCount = onScrollToCallbackHelper.getCallCount(); | 370 final int scrollToCallCount = onScrollToCallbackHelper.getCallCount(); |
| 371 executeJavaScriptAndWaitForResult(testContainerView.getAwContents(), con
tentsClient, | 371 executeJavaScriptAndWaitForResult(testContainerView.getAwContents(), con
tentsClient, |
| 372 String.format("window.scrollTo(%d, %d);", targetScrollXCss, targ
etScrollYCss)); | 372 String.format("window.scrollTo(%d, %d);", targetScrollXCss, targ
etScrollYCss)); |
| 373 onScrollToCallbackHelper.waitForCallback(scrollToCallCount); | 373 onScrollToCallbackHelper.waitForCallback(scrollToCallCount); |
| 374 | 374 |
| 375 assertScrollOnMainSync(testContainerView, targetScrollXPix, targetScroll
YPix); | 375 assertScrollOnMainSync(testContainerView, targetScrollXPix, targetScroll
YPix); |
| 376 } | 376 } |
| 377 | 377 |
| 378 @SmallTest | 378 @SmallTest |
| 379 @Feature({"AndroidWebView"}) | 379 @Feature({"AndroidWebView"}) |
| 380 public void testJsScrollFromBody() throws Throwable { | 380 public void testJsScrollFromBody() throws Throwable { |
| 381 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 381 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
| 382 final ScrollTestContainerView testContainerView = | 382 final ScrollTestContainerView testContainerView = |
| 383 (ScrollTestContainerView) createAwTestContainerViewOnMainSync(co
ntentsClient); | 383 (ScrollTestContainerView) createAwTestContainerViewOnMainSync(co
ntentsClient); |
| 384 enableJavaScriptOnUiThread(testContainerView.getAwContents()); | 384 enableJavaScriptOnUiThread(testContainerView.getAwContents()); |
| 385 | 385 |
| 386 final double deviceDIPScale = | 386 final double deviceDIPScale = |
| 387 DisplayAndroid.getNonMultiDisplay(testContainerView.getContext()
).getDIPScale(); | 387 DisplayAndroid.getNonMultiDisplay(testContainerView.getContext()
).getDipScale(); |
| 388 final int targetScrollXCss = 132; | 388 final int targetScrollXCss = 132; |
| 389 final int targetScrollYCss = 243; | 389 final int targetScrollYCss = 243; |
| 390 final int targetScrollXPix = (int) Math.floor(targetScrollXCss * deviceD
IPScale); | 390 final int targetScrollXPix = (int) Math.floor(targetScrollXCss * deviceD
IPScale); |
| 391 final int targetScrollYPix = (int) Math.floor(targetScrollYCss * deviceD
IPScale); | 391 final int targetScrollYPix = (int) Math.floor(targetScrollYCss * deviceD
IPScale); |
| 392 | 392 |
| 393 final String scrollFromBodyScript = | 393 final String scrollFromBodyScript = |
| 394 "<script> " | 394 "<script> " |
| 395 + " window.scrollTo(" + targetScrollXCss + ", " + targetScrollY
Css + "); " | 395 + " window.scrollTo(" + targetScrollXCss + ", " + targetScrollY
Css + "); " |
| 396 + "</script> "; | 396 + "</script> "; |
| 397 | 397 |
| 398 final CallbackHelper onScrollToCallbackHelper = | 398 final CallbackHelper onScrollToCallbackHelper = |
| 399 testContainerView.getOnScrollToCallbackHelper(); | 399 testContainerView.getOnScrollToCallbackHelper(); |
| 400 final int scrollToCallCount = onScrollToCallbackHelper.getCallCount(); | 400 final int scrollToCallCount = onScrollToCallbackHelper.getCallCount(); |
| 401 loadDataAsync(testContainerView.getAwContents(), | 401 loadDataAsync(testContainerView.getAwContents(), |
| 402 makeTestPage(null, null, scrollFromBodyScript), "text/html", fal
se); | 402 makeTestPage(null, null, scrollFromBodyScript), "text/html", fal
se); |
| 403 onScrollToCallbackHelper.waitForCallback(scrollToCallCount); | 403 onScrollToCallbackHelper.waitForCallback(scrollToCallCount); |
| 404 | 404 |
| 405 assertScrollOnMainSync(testContainerView, targetScrollXPix, targetScroll
YPix); | 405 assertScrollOnMainSync(testContainerView, targetScrollXPix, targetScroll
YPix); |
| 406 } | 406 } |
| 407 | 407 |
| 408 @SmallTest | 408 @SmallTest |
| 409 @Feature({"AndroidWebView"}) | 409 @Feature({"AndroidWebView"}) |
| 410 public void testJsScrollCanBeAlteredByUi() throws Throwable { | 410 public void testJsScrollCanBeAlteredByUi() throws Throwable { |
| 411 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 411 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
| 412 final ScrollTestContainerView testContainerView = | 412 final ScrollTestContainerView testContainerView = |
| 413 (ScrollTestContainerView) createAwTestContainerViewOnMainSync(co
ntentsClient); | 413 (ScrollTestContainerView) createAwTestContainerViewOnMainSync(co
ntentsClient); |
| 414 enableJavaScriptOnUiThread(testContainerView.getAwContents()); | 414 enableJavaScriptOnUiThread(testContainerView.getAwContents()); |
| 415 | 415 |
| 416 final double deviceDIPScale = | 416 final double deviceDIPScale = |
| 417 DisplayAndroid.getNonMultiDisplay(testContainerView.getContext()
).getDIPScale(); | 417 DisplayAndroid.getNonMultiDisplay(testContainerView.getContext()
).getDipScale(); |
| 418 final int targetScrollXCss = 132; | 418 final int targetScrollXCss = 132; |
| 419 final int targetScrollYCss = 243; | 419 final int targetScrollYCss = 243; |
| 420 final int targetScrollXPix = (int) Math.floor(targetScrollXCss * deviceD
IPScale); | 420 final int targetScrollXPix = (int) Math.floor(targetScrollXCss * deviceD
IPScale); |
| 421 final int targetScrollYPix = (int) Math.floor(targetScrollYCss * deviceD
IPScale); | 421 final int targetScrollYPix = (int) Math.floor(targetScrollYCss * deviceD
IPScale); |
| 422 | 422 |
| 423 final int maxScrollXCss = 101; | 423 final int maxScrollXCss = 101; |
| 424 final int maxScrollYCss = 201; | 424 final int maxScrollYCss = 201; |
| 425 final int maxScrollXPix = (int) Math.floor(maxScrollXCss * deviceDIPScal
e); | 425 final int maxScrollXPix = (int) Math.floor(maxScrollXCss * deviceDIPScal
e); |
| 426 final int maxScrollYPix = (int) Math.floor(maxScrollYCss * deviceDIPScal
e); | 426 final int maxScrollYPix = (int) Math.floor(maxScrollYCss * deviceDIPScal
e); |
| 427 | 427 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 451 enableJavaScriptOnUiThread(testContainerView.getAwContents()); | 451 enableJavaScriptOnUiThread(testContainerView.getAwContents()); |
| 452 | 452 |
| 453 final int dragSteps = 10; | 453 final int dragSteps = 10; |
| 454 final int dragStepSize = 24; | 454 final int dragStepSize = 24; |
| 455 // Watch out when modifying - if the y or x delta aren't big enough vert
ical or horizontal | 455 // Watch out when modifying - if the y or x delta aren't big enough vert
ical or horizontal |
| 456 // scroll snapping will kick in. | 456 // scroll snapping will kick in. |
| 457 final int targetScrollXPix = dragStepSize * dragSteps; | 457 final int targetScrollXPix = dragStepSize * dragSteps; |
| 458 final int targetScrollYPix = dragStepSize * dragSteps; | 458 final int targetScrollYPix = dragStepSize * dragSteps; |
| 459 | 459 |
| 460 final double deviceDIPScale = | 460 final double deviceDIPScale = |
| 461 DisplayAndroid.getNonMultiDisplay(testContainerView.getContext()
).getDIPScale(); | 461 DisplayAndroid.getNonMultiDisplay(testContainerView.getContext()
).getDipScale(); |
| 462 final int maxScrollXPix = 101; | 462 final int maxScrollXPix = 101; |
| 463 final int maxScrollYPix = 211; | 463 final int maxScrollYPix = 211; |
| 464 // Make sure we can't hit these values simply as a result of scrolling. | 464 // Make sure we can't hit these values simply as a result of scrolling. |
| 465 assert (maxScrollXPix % dragStepSize) != 0; | 465 assert (maxScrollXPix % dragStepSize) != 0; |
| 466 assert (maxScrollYPix % dragStepSize) != 0; | 466 assert (maxScrollYPix % dragStepSize) != 0; |
| 467 final int maxScrollXCss = (int) Math.floor(maxScrollXPix / deviceDIPScal
e); | 467 final int maxScrollXCss = (int) Math.floor(maxScrollXPix / deviceDIPScal
e); |
| 468 final int maxScrollYCss = (int) Math.floor(maxScrollYPix / deviceDIPScal
e); | 468 final int maxScrollYCss = (int) Math.floor(maxScrollYPix / deviceDIPScal
e); |
| 469 | 469 |
| 470 setMaxScrollOnMainSync(testContainerView, maxScrollXPix, maxScrollYPix); | 470 setMaxScrollOnMainSync(testContainerView, maxScrollXPix, maxScrollYPix); |
| 471 | 471 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 | 676 |
| 677 @SmallTest | 677 @SmallTest |
| 678 @Feature({"AndroidWebView"}) | 678 @Feature({"AndroidWebView"}) |
| 679 public void testPageUp() throws Throwable { | 679 public void testPageUp() throws Throwable { |
| 680 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | 680 final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
| 681 final ScrollTestContainerView testContainerView = | 681 final ScrollTestContainerView testContainerView = |
| 682 (ScrollTestContainerView) createAwTestContainerViewOnMainSync(co
ntentsClient); | 682 (ScrollTestContainerView) createAwTestContainerViewOnMainSync(co
ntentsClient); |
| 683 enableJavaScriptOnUiThread(testContainerView.getAwContents()); | 683 enableJavaScriptOnUiThread(testContainerView.getAwContents()); |
| 684 | 684 |
| 685 final double deviceDIPScale = | 685 final double deviceDIPScale = |
| 686 DisplayAndroid.getNonMultiDisplay(testContainerView.getContext()
).getDIPScale(); | 686 DisplayAndroid.getNonMultiDisplay(testContainerView.getContext()
).getDipScale(); |
| 687 final int targetScrollYCss = 243; | 687 final int targetScrollYCss = 243; |
| 688 final int targetScrollYPix = (int) Math.ceil(targetScrollYCss * deviceDI
PScale); | 688 final int targetScrollYPix = (int) Math.ceil(targetScrollYCss * deviceDI
PScale); |
| 689 | 689 |
| 690 loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, null
, ""); | 690 loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, null
, ""); |
| 691 | 691 |
| 692 assertScrollOnMainSync(testContainerView, 0, 0); | 692 assertScrollOnMainSync(testContainerView, 0, 0); |
| 693 | 693 |
| 694 scrollToOnMainSync(testContainerView, 0, targetScrollYPix); | 694 scrollToOnMainSync(testContainerView, 0, targetScrollYPix); |
| 695 | 695 |
| 696 final CallbackHelper onScrollToCallbackHelper = | 696 final CallbackHelper onScrollToCallbackHelper = |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 }); | 874 }); |
| 875 | 875 |
| 876 getInstrumentation().runOnMainSync(new Runnable() { | 876 getInstrumentation().runOnMainSync(new Runnable() { |
| 877 @Override | 877 @Override |
| 878 public void run() { | 878 public void run() { |
| 879 assertEquals(testContainerView.getScrollY(), scrolledYPix); | 879 assertEquals(testContainerView.getScrollY(), scrolledYPix); |
| 880 } | 880 } |
| 881 }); | 881 }); |
| 882 } | 882 } |
| 883 } | 883 } |
| OLD | NEW |