Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(772)

Side by Side Diff: android_webview/javatests/src/org/chromium/android_webview/test/WebKitHitTestTest.java

Issue 552813002: [android_webview] Use a MotionEvent to trigger ShouldInterceptRequest tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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.os.Handler; 7 import android.os.Handler;
8 import android.os.Message; 8 import android.os.Message;
9 import android.os.SystemClock;
10 import android.test.suitebuilder.annotation.LargeTest; 9 import android.test.suitebuilder.annotation.LargeTest;
11 import android.test.suitebuilder.annotation.SmallTest; 10 import android.test.suitebuilder.annotation.SmallTest;
12 import android.view.KeyEvent; 11 import android.view.KeyEvent;
13 import android.view.MotionEvent;
14 import android.webkit.WebView.HitTestResult; 12 import android.webkit.WebView.HitTestResult;
15 13
16 import org.chromium.android_webview.AwContents; 14 import org.chromium.android_webview.AwContents;
15 import org.chromium.android_webview.test.util.AwTestTouchUtils;
17 import org.chromium.android_webview.test.util.CommonResources; 16 import org.chromium.android_webview.test.util.CommonResources;
18 import org.chromium.base.ThreadUtils; 17 import org.chromium.base.ThreadUtils;
19 import org.chromium.base.test.util.Feature; 18 import org.chromium.base.test.util.Feature;
20 import org.chromium.net.test.util.TestWebServer; 19 import org.chromium.net.test.util.TestWebServer;
21 20
22 import java.util.concurrent.Callable; 21 import java.util.concurrent.Callable;
23 22
24 /** 23 /**
25 * Test for getHitTestResult, requestFocusNodeHref, and requestImageRef methods 24 * Test for getHitTestResult, requestFocusNodeHref, and requestImageRef methods
26 */ 25 */
(...skipping 28 matching lines...) Expand all
55 loadUrlSync(mAwContents, 54 loadUrlSync(mAwContents,
56 mContentsClient.getOnPageFinishedHelper(), 55 mContentsClient.getOnPageFinishedHelper(),
57 url); 56 url);
58 } 57 }
59 58
60 private static String fullPageLink(String href, String anchorText) { 59 private static String fullPageLink(String href, String anchorText) {
61 return CommonResources.makeHtmlPageFrom("", "<a class=\"full_view\" href =\"" + 60 return CommonResources.makeHtmlPageFrom("", "<a class=\"full_view\" href =\"" +
62 href + "\" " + "onclick=\"return false;\">" + anchorText + "</a> "); 61 href + "\" " + "onclick=\"return false;\">" + anchorText + "</a> ");
63 } 62 }
64 63
65 private void simulateTouchCenterOfWebViewOnUiThread() throws Throwable {
66 runTestOnUiThread(new Runnable() {
67 @Override
68 public void run() {
69 long eventTime = SystemClock.uptimeMillis();
70 float x = (float) (mTestView.getRight() - mTestView.getLeft()) / 2;
71 float y = (float) (mTestView.getBottom() - mTestView.getTop()) / 2;
72 mAwContents.onTouchEvent(MotionEvent.obtain(
73 eventTime, eventTime, MotionEvent.ACTION_DOWN,
74 x, y, 0));
75 mAwContents.onTouchEvent(MotionEvent.obtain(
76 eventTime, eventTime, MotionEvent.ACTION_UP,
77 x, y, 0));
78 }
79 });
80 }
81
82 private void simulateTabDownUpOnUiThread() throws Throwable { 64 private void simulateTabDownUpOnUiThread() throws Throwable {
83 runTestOnUiThread(new Runnable() { 65 runTestOnUiThread(new Runnable() {
84 @Override 66 @Override
85 public void run() { 67 public void run() {
86 mAwContents.getContentViewCore().dispatchKeyEvent( 68 mAwContents.getContentViewCore().dispatchKeyEvent(
87 new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_TAB) ); 69 new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_TAB) );
88 mAwContents.getContentViewCore().dispatchKeyEvent( 70 mAwContents.getContentViewCore().dispatchKeyEvent(
89 new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_TAB)); 71 new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_TAB));
90 } 72 }
91 }); 73 });
92 } 74 }
93 75
94 private void simulateInput(boolean byTouch) throws Throwable { 76 private void simulateInput(boolean byTouch) throws Throwable {
95 // Send a touch click event if byTouch is true. Otherwise, send a TAB 77 // Send a touch click event if byTouch is true. Otherwise, send a TAB
96 // key event to change the focused element of the page. 78 // key event to change the focused element of the page.
97 if (byTouch) { 79 if (byTouch) {
98 simulateTouchCenterOfWebViewOnUiThread(); 80 AwTestTouchUtils.simulateTouchCenterOfView(mTestView);
99 } else { 81 } else {
100 simulateTabDownUpOnUiThread(); 82 simulateTabDownUpOnUiThread();
101 } 83 }
102 } 84 }
103 85
104 private static boolean stringEquals(String a, String b) { 86 private static boolean stringEquals(String a, String b) {
105 return a == null ? b == null : a.equals(b); 87 return a == null ? b == null : a.equals(b);
106 } 88 }
107 89
108 private void pollForHitTestDataOnUiThread( 90 private void pollForHitTestDataOnUiThread(
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } 309 }
328 310
329 @SmallTest 311 @SmallTest
330 @Feature({"AndroidWebView", "WebKitHitTest"}) 312 @Feature({"AndroidWebView", "WebKitHitTest"})
331 public void testImgeType() throws Throwable { 313 public void testImgeType() throws Throwable {
332 String relImageSrc = "/nonexistent2.jpg"; 314 String relImageSrc = "/nonexistent2.jpg";
333 String fullImageSrc = mWebServer.getResponseUrl(relImageSrc); 315 String fullImageSrc = mWebServer.getResponseUrl(relImageSrc);
334 String page = CommonResources.makeHtmlPageFrom("", 316 String page = CommonResources.makeHtmlPageFrom("",
335 "<img class=\"full_view\" src=\"" + relImageSrc + "\">"); 317 "<img class=\"full_view\" src=\"" + relImageSrc + "\">");
336 setServerResponseAndLoad(page); 318 setServerResponseAndLoad(page);
337 simulateTouchCenterOfWebViewOnUiThread(); 319 AwTestTouchUtils.simulateTouchCenterOfView(mTestView);
338 pollForHitTestDataOnUiThread(HitTestResult.IMAGE_TYPE, fullImageSrc); 320 pollForHitTestDataOnUiThread(HitTestResult.IMAGE_TYPE, fullImageSrc);
339 pollForHrefAndImageSrcOnUiThread(null, null, fullImageSrc); 321 pollForHrefAndImageSrcOnUiThread(null, null, fullImageSrc);
340 } 322 }
341 323
342 private void editTextTypeTestBody(boolean byTouch) throws Throwable { 324 private void editTextTypeTestBody(boolean byTouch) throws Throwable {
343 String page = CommonResources.makeHtmlPageFrom("", 325 String page = CommonResources.makeHtmlPageFrom("",
344 "<form><input class=\"full_view\" type=\"text\" name=\"test\"></ form>"); 326 "<form><input class=\"full_view\" type=\"text\" name=\"test\"></ form>");
345 setServerResponseAndLoad(page); 327 setServerResponseAndLoad(page);
346 simulateInput(byTouch); 328 simulateInput(byTouch);
347 pollForHitTestDataOnUiThread(HitTestResult.EDIT_TEXT_TYPE, null); 329 pollForHitTestDataOnUiThread(HitTestResult.EDIT_TEXT_TYPE, null);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 "<div class=\"full_view\">div text</div>"); 378 "<div class=\"full_view\">div text</div>");
397 setServerResponseAndLoad(page); 379 setServerResponseAndLoad(page);
398 380
399 // Wait for the new page to be loaded before trying hit test. 381 // Wait for the new page to be loaded before trying hit test.
400 pollOnUiThread(new Callable<Boolean>() { 382 pollOnUiThread(new Callable<Boolean>() {
401 @Override 383 @Override
402 public Boolean call() { 384 public Boolean call() {
403 return mAwContents.getContentViewCore().getTitle().equals(title) ; 385 return mAwContents.getContentViewCore().getTitle().equals(title) ;
404 } 386 }
405 }); 387 });
406 simulateTouchCenterOfWebViewOnUiThread(); 388 AwTestTouchUtils.simulateTouchCenterOfView(mTestView);
407 pollForHitTestDataOnUiThread(HitTestResult.UNKNOWN_TYPE, null); 389 pollForHitTestDataOnUiThread(HitTestResult.UNKNOWN_TYPE, null);
408 } 390 }
409 391
410 @LargeTest 392 @LargeTest
411 @Feature({"AndroidWebView", "WebKitHitTest"}) 393 @Feature({"AndroidWebView", "WebKitHitTest"})
412 public void testUnfocusedNodeAndTouchRace() throws Throwable { 394 public void testUnfocusedNodeAndTouchRace() throws Throwable {
413 // Test when the touch and focus paths racing with setting different 395 // Test when the touch and focus paths racing with setting different
414 // results. 396 // results.
415 397
416 String relImageSrc = "/nonexistent3.jpg"; 398 String relImageSrc = "/nonexistent3.jpg";
(...skipping 10 matching lines...) Expand all
427 setServerResponseAndLoad(html); 409 setServerResponseAndLoad(html);
428 410
429 // Focus on input element and check the hit test results. 411 // Focus on input element and check the hit test results.
430 simulateTabDownUpOnUiThread(); 412 simulateTabDownUpOnUiThread();
431 pollForHitTestDataOnUiThread(HitTestResult.EDIT_TEXT_TYPE, null); 413 pollForHitTestDataOnUiThread(HitTestResult.EDIT_TEXT_TYPE, null);
432 pollForHrefAndImageSrcOnUiThread(null, null, null); 414 pollForHrefAndImageSrcOnUiThread(null, null, null);
433 415
434 // Touch image. Now the focus based hit test path will try to null out 416 // Touch image. Now the focus based hit test path will try to null out
435 // the results and the touch based path will update with the result of 417 // the results and the touch based path will update with the result of
436 // the image. 418 // the image.
437 simulateTouchCenterOfWebViewOnUiThread(); 419 AwTestTouchUtils.simulateTouchCenterOfView(mTestView);
438 420
439 // Make sure the result of image sticks. 421 // Make sure the result of image sticks.
440 for (int i = 0; i < 2; ++i) { 422 for (int i = 0; i < 2; ++i) {
441 Thread.sleep(500); 423 Thread.sleep(500);
442 pollForHitTestDataOnUiThread(HitTestResult.IMAGE_TYPE, fullImageSrc) ; 424 pollForHitTestDataOnUiThread(HitTestResult.IMAGE_TYPE, fullImageSrc) ;
443 pollForHrefAndImageSrcOnUiThread(null, null, fullImageSrc); 425 pollForHrefAndImageSrcOnUiThread(null, null, fullImageSrc);
444 } 426 }
445 } 427 }
446 } 428 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698