@SmallTest
  @Feature({"AndroidWebView"})
  public void testOverScrollX() throws Throwable {
    final TestAwContentsClient contentsClient = new TestAwContentsClient();
    final ScrollTestContainerView testContainerView =
        (ScrollTestContainerView) createAwTestContainerViewOnMainSync(contentsClient);
    final OverScrollByCallbackHelper overScrollByCallbackHelper =
        testContainerView.getOverScrollByCallbackHelper();
    enableJavaScriptOnUiThread(testContainerView.getAwContents());

    final int overScrollDeltaX = 30;
    final int oneStep = 1;

    loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, null, "");

    // Scroll separately in different dimensions because of vertical/horizontal scroll
    // snap.
    final int overScrollCallCount = overScrollByCallbackHelper.getCallCount();
    AwTestTouchUtils.dragCompleteView(
        testContainerView, 0, overScrollDeltaX, 0, 0, oneStep, null /* completionLatch */);
    overScrollByCallbackHelper.waitForCallback(overScrollCallCount);
    // Unfortunately the gesture detector seems to 'eat' some number of pixels. For now
    // checking that the value is < 0 (overscroll is reported as negative values) will have to
    // do.
    assertTrue(0 > overScrollByCallbackHelper.getDeltaX());
    assertEquals(0, overScrollByCallbackHelper.getDeltaY());

    assertScrollOnMainSync(testContainerView, 0, 0);
  }
Ejemplo n.º 2
0
  @SmallTest
  @Feature({"AndroidWebView", "WebKitHitTest"})
  public void testUnknownTypeUnrecognizedNode() throws Throwable {
    // Since UNKNOWN_TYPE is the default, hit test another type first for
    // this test to be valid.
    testSrcAnchorType();

    final String title = "UNKNOWN_TYPE title";

    String page =
        CommonResources.makeHtmlPageFrom(
            "<title>" + title + "</title>", "<div class=\"full_view\">div text</div>");
    setServerResponseAndLoad(page);

    // Wait for the new page to be loaded before trying hit test.
    pollUiThread(
        new Callable<Boolean>() {
          @Override
          public Boolean call() {
            return mAwContents.getTitle().equals(title);
          }
        });
    AwTestTouchUtils.simulateTouchCenterOfView(mTestView);
    pollForHitTestDataOnUiThread(HitTestResult.UNKNOWN_TYPE, null);
  }
  @SmallTest
  @Feature({"AndroidWebView"})
  public void testNoSpuriousOverScrolls() throws Throwable {
    final TestAwContentsClient contentsClient = new TestAwContentsClient();
    final ScrollTestContainerView testContainerView =
        (ScrollTestContainerView) createAwTestContainerViewOnMainSync(contentsClient);
    enableJavaScriptOnUiThread(testContainerView.getAwContents());

    final int dragSteps = 1;
    final int targetScrollYPix = 40;

    setMaxScrollOnMainSync(testContainerView, 0, 0);

    loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, null, "");

    final CallbackHelper onScrollToCallbackHelper = testContainerView.getOnScrollToCallbackHelper();
    final int scrollToCallCount = onScrollToCallbackHelper.getCallCount();
    CountDownLatch scrollingCompleteLatch = new CountDownLatch(1);
    AwTestTouchUtils.dragCompleteView(
        testContainerView,
        0,
        0, // these need to be negative as we're scrolling down.
        0,
        -targetScrollYPix,
        dragSteps,
        scrollingCompleteLatch);
    try {
      scrollingCompleteLatch.await();
    } catch (InterruptedException ex) {
      // ignore
    }
    assertEquals(scrollToCallCount + 1, onScrollToCallbackHelper.getCallCount());
  }
Ejemplo n.º 4
0
 private void simulateInput(boolean byTouch) throws Throwable {
   // Send a touch click event if byTouch is true. Otherwise, send a TAB
   // key event to change the focused element of the page.
   if (byTouch) {
     AwTestTouchUtils.simulateTouchCenterOfView(mTestView);
   } else {
     simulateTabDownUpOnUiThread();
   }
 }
Ejemplo n.º 5
0
 @SmallTest
 @Feature({"AndroidWebView", "WebKitHitTest"})
 public void testImgeType() throws Throwable {
   String relImageSrc = "/" + CommonResources.TEST_IMAGE_FILENAME;
   String fullImageSrc = mWebServer.getResponseUrl(relImageSrc);
   String page =
       CommonResources.makeHtmlPageFrom(
           "", "<img class=\"full_view\" src=\"" + relImageSrc + "\">");
   setServerResponseAndLoad(page);
   AwTestTouchUtils.simulateTouchCenterOfView(mTestView);
   pollForHitTestDataOnUiThread(HitTestResult.IMAGE_TYPE, fullImageSrc);
   pollForHrefAndImageSrcOnUiThread(null, null, fullImageSrc);
 }
  @SmallTest
  @Feature({"AndroidWebView"})
  public void testTouchScrollCanBeAlteredByUi() throws Throwable {
    final TestAwContentsClient contentsClient = new TestAwContentsClient();
    final ScrollTestContainerView testContainerView =
        (ScrollTestContainerView) createAwTestContainerViewOnMainSync(contentsClient);
    enableJavaScriptOnUiThread(testContainerView.getAwContents());

    final int dragSteps = 10;
    final int dragStepSize = 24;
    // Watch out when modifying - if the y or x delta aren't big enough vertical or horizontal
    // scroll snapping will kick in.
    final int targetScrollXPix = dragStepSize * dragSteps;
    final int targetScrollYPix = dragStepSize * dragSteps;

    final double deviceDIPScale =
        DeviceDisplayInfo.create(testContainerView.getContext()).getDIPScale();
    final int maxScrollXPix = 101;
    final int maxScrollYPix = 211;
    // Make sure we can't hit these values simply as a result of scrolling.
    assert (maxScrollXPix % dragStepSize) != 0;
    assert (maxScrollYPix % dragStepSize) != 0;
    final int maxScrollXCss = (int) Math.floor(maxScrollXPix / deviceDIPScale);
    final int maxScrollYCss = (int) Math.floor(maxScrollYPix / deviceDIPScale);

    setMaxScrollOnMainSync(testContainerView, maxScrollXPix, maxScrollYPix);

    loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, null, "");

    final CallbackHelper onScrollToCallbackHelper = testContainerView.getOnScrollToCallbackHelper();
    final int scrollToCallCount = onScrollToCallbackHelper.getCallCount();
    AwTestTouchUtils.dragCompleteView(
        testContainerView,
        0,
        -targetScrollXPix, // these need to be negative as we're scrolling down.
        0,
        -targetScrollYPix,
        dragSteps,
        null /* completionLatch */);

    for (int i = 1; i <= dragSteps; ++i) {
      onScrollToCallbackHelper.waitForCallback(scrollToCallCount, i);
      if (checkScrollOnMainSync(testContainerView, maxScrollXPix, maxScrollYPix)) break;
    }

    assertScrollOnMainSync(testContainerView, maxScrollXPix, maxScrollYPix);
    assertScrollInJs(
        testContainerView.getAwContents(), contentsClient, maxScrollXCss, maxScrollYCss);
  }
  @SmallTest
  @Feature({"AndroidWebView"})
  public void testTouchScrollingConsumesScrollByGesture() throws Throwable {
    final TestAwContentsClient contentsClient = new TestAwContentsClient();
    final ScrollTestContainerView testContainerView =
        (ScrollTestContainerView) createAwTestContainerViewOnMainSync(contentsClient);
    final TestGestureStateListener testGestureStateListener = new TestGestureStateListener();
    enableJavaScriptOnUiThread(testContainerView.getAwContents());

    final int dragSteps = 10;
    final int dragStepSize = 24;
    // Watch out when modifying - if the y or x delta aren't big enough vertical or horizontal
    // scroll snapping will kick in.
    final int targetScrollXPix = dragStepSize * dragSteps;
    final int targetScrollYPix = dragStepSize * dragSteps;

    loadTestPageAndWaitForFirstFrame(
        testContainerView,
        contentsClient,
        null,
        "<div>"
            + "  <div style=\"width:10000px; height: 10000px;\"> force scrolling </div>"
            + "</div>");

    getInstrumentation()
        .runOnMainSync(
            new Runnable() {
              @Override
              public void run() {
                testContainerView
                    .getContentViewCore()
                    .addGestureStateListener(testGestureStateListener);
              }
            });
    final CallbackHelper onScrollUpdateGestureConsumedHelper =
        testGestureStateListener.getOnScrollUpdateGestureConsumedHelper();

    final int callCount = onScrollUpdateGestureConsumedHelper.getCallCount();
    AwTestTouchUtils.dragCompleteView(
        testContainerView,
        0,
        -targetScrollXPix, // these need to be negative as we're scrolling down.
        0,
        -targetScrollYPix,
        dragSteps,
        null /* completionLatch */);
    onScrollUpdateGestureConsumedHelper.waitForCallback(callCount);
  }
Ejemplo n.º 8
0
  @LargeTest
  @Feature({"AndroidWebView", "WebKitHitTest"})
  public void testUnfocusedNodeAndTouchRace() throws Throwable {
    // Test when the touch and focus paths racing with setting different
    // results.

    String relImageSrc = "/" + CommonResources.TEST_IMAGE_FILENAME;
    String fullImageSrc = mWebServer.getResponseUrl(relImageSrc);
    String html =
        CommonResources.makeHtmlPageFrom(
            "<meta name=\"viewport\" content=\"width=device-width,height=device-height\" />"
                + "<style type=\"text/css\">"
                + ".full_width { width:100%; position:absolute; }"
                + "</style>",
            "<form><input class=\"full_width\" style=\"height:25%;\" "
                + "type=\"text\" name=\"test\"></form>"
                + "<img class=\"full_width\" style=\"height:50%;top:25%;\" "
                + "src=\""
                + relImageSrc
                + "\">");
    setServerResponseAndLoad(html);

    // Focus on input element and check the hit test results.
    simulateTabDownUpOnUiThread();
    pollForHitTestDataOnUiThread(HitTestResult.EDIT_TEXT_TYPE, null);
    pollForHrefAndImageSrcOnUiThread(null, null, null);

    // Touch image. Now the focus based hit test path will try to null out
    // the results and the touch based path will update with the result of
    // the image.
    AwTestTouchUtils.simulateTouchCenterOfView(mTestView);

    // Make sure the result of image sticks.
    for (int i = 0; i < 2; ++i) {
      Thread.sleep(500);
      pollForHitTestDataOnUiThread(HitTestResult.IMAGE_TYPE, fullImageSrc);
      pollForHrefAndImageSrcOnUiThread(null, null, fullImageSrc);
    }
  }
  @SmallTest
  @Feature({"AndroidWebView"})
  public void testOverScrollY() throws Throwable {
    final TestAwContentsClient contentsClient = new TestAwContentsClient();
    final ScrollTestContainerView testContainerView =
        (ScrollTestContainerView) createAwTestContainerViewOnMainSync(contentsClient);
    final OverScrollByCallbackHelper overScrollByCallbackHelper =
        testContainerView.getOverScrollByCallbackHelper();
    enableJavaScriptOnUiThread(testContainerView.getAwContents());

    final int overScrollDeltaY = 30;
    final int oneStep = 1;

    loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, null, "");

    int overScrollCallCount = overScrollByCallbackHelper.getCallCount();
    AwTestTouchUtils.dragCompleteView(
        testContainerView, 0, 0, 0, overScrollDeltaY, oneStep, null /* completionLatch */);
    overScrollByCallbackHelper.waitForCallback(overScrollCallCount);
    assertEquals(0, overScrollByCallbackHelper.getDeltaX());
    assertTrue(0 > overScrollByCallbackHelper.getDeltaY());

    assertScrollOnMainSync(testContainerView, 0, 0);
  }