| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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.SystemClock; | 7 import android.os.SystemClock; |
| 8 import android.test.FlakyTest; | 8 import android.test.FlakyTest; |
| 9 import android.test.suitebuilder.annotation.SmallTest; | 9 import android.test.suitebuilder.annotation.SmallTest; |
| 10 import android.view.MotionEvent; | 10 import android.view.MotionEvent; |
| 11 import android.webkit.WebView.HitTestResult; | 11 import android.webkit.WebView.HitTestResult; |
| 12 | 12 |
| 13 import org.chromium.android_webview.AwContents; | 13 import org.chromium.android_webview.AwContents; |
| 14 import org.chromium.base.test.util.Feature; | 14 import org.chromium.base.test.util.Feature; |
| 15 import org.chromium.android_webview.test.util.CommonResources; | 15 import org.chromium.android_webview.test.util.CommonResources; |
| 16 import org.chromium.content.browser.test.util.Criteria; | |
| 17 import org.chromium.content.browser.test.util.CriteriaHelper; | |
| 18 import org.chromium.net.test.util.TestWebServer; | 16 import org.chromium.net.test.util.TestWebServer; |
| 19 | 17 |
| 20 import java.util.concurrent.Callable; | 18 import java.util.concurrent.Callable; |
| 21 | 19 |
| 22 public class WebKitHitTestTest extends AndroidWebViewTestBase { | 20 public class WebKitHitTestTest extends AndroidWebViewTestBase { |
| 23 private TestAwContentsClient mContentsClient; | 21 private TestAwContentsClient mContentsClient; |
| 24 private AwTestContainerView mTestView; | 22 private AwTestContainerView mTestView; |
| 25 private AwContents mAwContents; | 23 private AwContents mAwContents; |
| 26 private TestWebServer mWebServer; | 24 private TestWebServer mWebServer; |
| 27 | 25 |
| 28 private static String HREF = "http://foo/"; | 26 private static String HREF = "http://foo/"; |
| 29 private static String ANCHOR_TEXT = "anchor text"; | 27 private static String ANCHOR_TEXT = "anchor text"; |
| 30 | 28 |
| 31 @Override | 29 @Override |
| 32 public void setUp() throws Exception { | 30 public void setUp() throws Exception { |
| 33 super.setUp(); | 31 super.setUp(); |
| 34 mContentsClient = new TestAwContentsClient(); | 32 mContentsClient = new TestAwContentsClient(); |
| 35 mTestView = createAwTestContainerViewOnMainSync(mContentsClient); | 33 mTestView = createAwTestContainerViewOnMainSync(mContentsClient); |
| 36 mAwContents = mTestView.getAwContents(); | 34 mAwContents = mTestView.getAwContents(); |
| 37 mWebServer = new TestWebServer(false); | 35 mWebServer = new TestWebServer(false); |
| 38 } | 36 } |
| 39 | 37 |
| 40 @Override | 38 @Override |
| 41 public void tearDown() throws Exception { | 39 public void tearDown() throws Exception { |
| 42 // TODO(boliu): This is to work around disk cache corruption bug on | 40 // TODO(boliu): This is to work around disk cache corruption bug on |
| 43 // unclean shutdown (crbug.com/154805). | 41 // unclean shutdown (crbug.com/154805). |
| 44 try { | 42 try { |
| 45 runTestOnUiThread(new Runnable() { | 43 clearCacheOnUiThread(mAwContents, true); |
| 46 @Override | |
| 47 public void run() { | |
| 48 mAwContents.clearCache(true); | |
| 49 } | |
| 50 }); | |
| 51 } catch (Throwable e) { | 44 } catch (Throwable e) { |
| 52 throw new Exception(e); | 45 throw new Exception(e); |
| 53 } | 46 } |
| 54 if (mWebServer != null) { | 47 if (mWebServer != null) { |
| 55 mWebServer.shutdown(); | 48 mWebServer.shutdown(); |
| 56 } | 49 } |
| 57 super.tearDown(); | 50 super.tearDown(); |
| 58 } | 51 } |
| 59 | 52 |
| 60 private void setServerResponseAndLoad(String response) throws Throwable { | 53 private void setServerResponseAndLoad(String response) throws Throwable { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 76 long eventTime = SystemClock.uptimeMillis(); | 69 long eventTime = SystemClock.uptimeMillis(); |
| 77 mAwContents.onTouchEvent(MotionEvent.obtain( | 70 mAwContents.onTouchEvent(MotionEvent.obtain( |
| 78 eventTime, eventTime, MotionEvent.ACTION_DOWN, | 71 eventTime, eventTime, MotionEvent.ACTION_DOWN, |
| 79 (float)(mTestView.getRight() - mTestView.getLeft()) / 2, | 72 (float)(mTestView.getRight() - mTestView.getLeft()) / 2, |
| 80 (float)(mTestView.getBottom() - mTestView.getTop()) / 2, | 73 (float)(mTestView.getBottom() - mTestView.getTop()) / 2, |
| 81 0)); | 74 0)); |
| 82 } | 75 } |
| 83 }); | 76 }); |
| 84 } | 77 } |
| 85 | 78 |
| 86 private boolean pollOnUiThread(final Callable<Boolean> callable) throws Thro
wable { | |
| 87 return CriteriaHelper.pollForCriteria(new Criteria() { | |
| 88 @Override | |
| 89 public boolean isSatisfied() { | |
| 90 try { | |
| 91 return runTestOnUiThreadAndGetResult(callable); | |
| 92 } catch (Throwable e) { | |
| 93 return false; | |
| 94 } | |
| 95 } | |
| 96 }); | |
| 97 } | |
| 98 | |
| 99 private boolean pollForHitTestDataOnUiThread( | 79 private boolean pollForHitTestDataOnUiThread( |
| 100 final int type, final String extra) throws Throwable { | 80 final int type, final String extra) throws Throwable { |
| 101 return pollOnUiThread(new Callable<Boolean>() { | 81 return pollOnUiThread(new Callable<Boolean>() { |
| 102 @Override | 82 @Override |
| 103 public Boolean call() { | 83 public Boolean call() { |
| 104 AwContents.HitTestData data = mAwContents.getLastHitTestResult()
; | 84 AwContents.HitTestData data = mAwContents.getLastHitTestResult()
; |
| 105 return type == data.hitTestResultType && | 85 return type == data.hitTestResultType && |
| 106 (extra == null ? data.hitTestResultExtraData == null : | 86 (extra == null ? data.hitTestResultExtraData == null : |
| 107 extra.equals(data.hitTestResultExtraData)); | 87 extra.equals(data.hitTestResultExtraData)); |
| 108 } | 88 } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 // this test to be valid. | 226 // this test to be valid. |
| 247 testSrcAnchorType(); | 227 testSrcAnchorType(); |
| 248 | 228 |
| 249 String page = CommonResources.makeHtmlPageFrom("", | 229 String page = CommonResources.makeHtmlPageFrom("", |
| 250 "<div class=\"full_view\">div text</div>"); | 230 "<div class=\"full_view\">div text</div>"); |
| 251 setServerResponseAndLoad(page); | 231 setServerResponseAndLoad(page); |
| 252 simulateTouchCenterOfWebViewOnUiThread(); | 232 simulateTouchCenterOfWebViewOnUiThread(); |
| 253 assertTrue(pollForHitTestDataOnUiThread(HitTestResult.UNKNOWN_TYPE, null
)); | 233 assertTrue(pollForHitTestDataOnUiThread(HitTestResult.UNKNOWN_TYPE, null
)); |
| 254 } | 234 } |
| 255 } | 235 } |
| OLD | NEW |