| OLD | NEW |
| 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 static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; | 7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; |
| 8 | 8 |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.graphics.Point; | 10 import android.graphics.Point; |
| (...skipping 2938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2949 } | 2949 } |
| 2950 } | 2950 } |
| 2951 | 2951 |
| 2952 private void doAllowEmptyDocumentPersistenceTest(boolean allow) throws Throw
able { | 2952 private void doAllowEmptyDocumentPersistenceTest(boolean allow) throws Throw
able { |
| 2953 mOverridenFactory = new EmptyDocumentPeristenceTestDependencyFactory(all
ow); | 2953 mOverridenFactory = new EmptyDocumentPeristenceTestDependencyFactory(all
ow); |
| 2954 | 2954 |
| 2955 final TestAwContentsClient client = new TestAwContentsClient(); | 2955 final TestAwContentsClient client = new TestAwContentsClient(); |
| 2956 final AwTestContainerView mContainerView = createAwTestContainerViewOnMa
inSync(client); | 2956 final AwTestContainerView mContainerView = createAwTestContainerViewOnMa
inSync(client); |
| 2957 final AwContents awContents = mContainerView.getAwContents(); | 2957 final AwContents awContents = mContainerView.getAwContents(); |
| 2958 enableJavaScriptOnUiThread(awContents); | 2958 enableJavaScriptOnUiThread(awContents); |
| 2959 JSUtils.executeJavaScriptAndWaitForResult(this, awContents, | 2959 JSUtils.executeJavaScriptAndWaitForResult(getInstrumentation(), awConten
ts, |
| 2960 client.getOnEvaluateJavaScriptResultHelper(), | 2960 client.getOnEvaluateJavaScriptResultHelper(), |
| 2961 "window.emptyDocumentPersistenceTest = true;"); | 2961 "window.emptyDocumentPersistenceTest = true;"); |
| 2962 loadUrlSync(awContents, client.getOnPageFinishedHelper(), | 2962 loadUrlSync(awContents, client.getOnPageFinishedHelper(), |
| 2963 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL); | 2963 ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL); |
| 2964 String result = JSUtils.executeJavaScriptAndWaitForResult(this, awConten
ts, | 2964 String result = JSUtils.executeJavaScriptAndWaitForResult(getInstrumenta
tion(), awContents, |
| 2965 client.getOnEvaluateJavaScriptResultHelper(), | 2965 client.getOnEvaluateJavaScriptResultHelper(), |
| 2966 "window.emptyDocumentPersistenceTest ? 'set' : 'not set';"); | 2966 "window.emptyDocumentPersistenceTest ? 'set' : 'not set';"); |
| 2967 assertEquals(allow ? "\"set\"" : "\"not set\"", result); | 2967 assertEquals(allow ? "\"set\"" : "\"not set\"", result); |
| 2968 } | 2968 } |
| 2969 | 2969 |
| 2970 @SmallTest | 2970 @SmallTest |
| 2971 @Feature({"AndroidWebView", "Preferences"}) | 2971 @Feature({"AndroidWebView", "Preferences"}) |
| 2972 public void testAllowEmptyDocumentPersistence() throws Throwable { | 2972 public void testAllowEmptyDocumentPersistence() throws Throwable { |
| 2973 doAllowEmptyDocumentPersistenceTest(true); | 2973 doAllowEmptyDocumentPersistenceTest(true); |
| 2974 } | 2974 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3007 + "var a = document.getElementById('a');" | 3007 + "var a = document.getElementById('a');" |
| 3008 + "document.addEventListener('selectionchange', onSelectionChang
e, false);" | 3008 + "document.addEventListener('selectionchange', onSelectionChang
e, false);" |
| 3009 + "function onSelectionChange(event) {" | 3009 + "function onSelectionChange(event) {" |
| 3010 + " cnt++;" | 3010 + " cnt++;" |
| 3011 + "}" | 3011 + "}" |
| 3012 + "</script></body></html>"; | 3012 + "</script></body></html>"; |
| 3013 loadDataSync( | 3013 loadDataSync( |
| 3014 awContents, client.getOnPageFinishedHelper(), testPageHtml, "tex
t/html", false); | 3014 awContents, client.getOnPageFinishedHelper(), testPageHtml, "tex
t/html", false); |
| 3015 | 3015 |
| 3016 // Focus on an empty DIV. | 3016 // Focus on an empty DIV. |
| 3017 JSUtils.executeJavaScriptAndWaitForResult(this, awContents, | 3017 JSUtils.executeJavaScriptAndWaitForResult(getInstrumentation(), awConten
ts, |
| 3018 client.getOnEvaluateJavaScriptResultHelper(), "window.a.focus();
"); | 3018 client.getOnEvaluateJavaScriptResultHelper(), "window.a.focus();
"); |
| 3019 assertEquals(1, getSelectionChangeCountForSelectionUpdateTest(awContents
, client)); | 3019 assertEquals(1, getSelectionChangeCountForSelectionUpdateTest(awContents
, client)); |
| 3020 | 3020 |
| 3021 // Create and delete a zero-width space. See crbug.com/698752 for detail
s. | 3021 // Create and delete a zero-width space. See crbug.com/698752 for detail
s. |
| 3022 JSUtils.executeJavaScriptAndWaitForResult(this, awContents, | 3022 JSUtils.executeJavaScriptAndWaitForResult(getInstrumentation(), awConten
ts, |
| 3023 client.getOnEvaluateJavaScriptResultHelper(), | 3023 client.getOnEvaluateJavaScriptResultHelper(), |
| 3024 "(function() {" | 3024 "(function() {" |
| 3025 + "var sel = window.getSelection();" | 3025 + "var sel = window.getSelection();" |
| 3026 + "var range = sel.getRangeAt(0);" | 3026 + "var range = sel.getRangeAt(0);" |
| 3027 + "var span = document.createElement('span');" | 3027 + "var span = document.createElement('span');" |
| 3028 + "var textNodeForZWSP = document.createTextNode('\u200B
');" | 3028 + "var textNodeForZWSP = document.createTextNode('\u200B
');" |
| 3029 + "span.appendChild(textNodeForZWSP);" | 3029 + "span.appendChild(textNodeForZWSP);" |
| 3030 + "range.insertNode(span);" | 3030 + "range.insertNode(span);" |
| 3031 + "range.selectNode(span);" | 3031 + "range.selectNode(span);" |
| 3032 + "range.deleteContents();" | 3032 + "range.deleteContents();" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3044 } | 3044 } |
| 3045 }); | 3045 }); |
| 3046 } | 3046 } |
| 3047 | 3047 |
| 3048 private int getSelectionChangeCountForSelectionUpdateTest( | 3048 private int getSelectionChangeCountForSelectionUpdateTest( |
| 3049 AwContents awContents, TestAwContentsClient client) throws Exception
{ | 3049 AwContents awContents, TestAwContentsClient client) throws Exception
{ |
| 3050 mTitleIdx++; | 3050 mTitleIdx++; |
| 3051 String expectedTitle = Integer.toString(mTitleIdx); | 3051 String expectedTitle = Integer.toString(mTitleIdx); |
| 3052 // Since selectionchange event is posted on a message loop, we run anoth
er message loop | 3052 // Since selectionchange event is posted on a message loop, we run anoth
er message loop |
| 3053 // before we get the result. On Chromium both run on the same message lo
op. | 3053 // before we get the result. On Chromium both run on the same message lo
op. |
| 3054 JSUtils.executeJavaScriptAndWaitForResult(this, awContents, | 3054 JSUtils.executeJavaScriptAndWaitForResult(getInstrumentation(), awConten
ts, |
| 3055 client.getOnEvaluateJavaScriptResultHelper(), | 3055 client.getOnEvaluateJavaScriptResultHelper(), |
| 3056 "setTimeout(function() { document.title = '" + expectedTitle + "
'; });"); | 3056 "setTimeout(function() { document.title = '" + expectedTitle + "
'; });"); |
| 3057 pollTitleAs(expectedTitle, awContents); | 3057 pollTitleAs(expectedTitle, awContents); |
| 3058 | 3058 |
| 3059 String result = JSUtils.executeJavaScriptAndWaitForResult( | 3059 String result = JSUtils.executeJavaScriptAndWaitForResult(getInstrumenta
tion(), awContents, |
| 3060 this, awContents, client.getOnEvaluateJavaScriptResultHelper(),
"window.cnt"); | 3060 client.getOnEvaluateJavaScriptResultHelper(), "window.cnt"); |
| 3061 // Clean up | 3061 // Clean up |
| 3062 JSUtils.executeJavaScriptAndWaitForResult( | 3062 JSUtils.executeJavaScriptAndWaitForResult(getInstrumentation(), awConten
ts, |
| 3063 this, awContents, client.getOnEvaluateJavaScriptResultHelper(),
"window.cnt = 0;"); | 3063 client.getOnEvaluateJavaScriptResultHelper(), "window.cnt = 0;")
; |
| 3064 return Integer.parseInt(result); | 3064 return Integer.parseInt(result); |
| 3065 } | 3065 } |
| 3066 | 3066 |
| 3067 @SmallTest | 3067 @SmallTest |
| 3068 @Feature({"AndroidWebView", "Selection"}) | 3068 @Feature({"AndroidWebView", "Selection"}) |
| 3069 public void testDoNotUpdateSelectionOnMutatingSelectionRange() throws Throwa
ble { | 3069 public void testDoNotUpdateSelectionOnMutatingSelectionRange() throws Throwa
ble { |
| 3070 selectionUpdateOnMutatingSelectionRangeTest(true); | 3070 selectionUpdateOnMutatingSelectionRangeTest(true); |
| 3071 } | 3071 } |
| 3072 | 3072 |
| 3073 @SmallTest | 3073 @SmallTest |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3217 final AwContents awContents = webView.getAwContents(); | 3217 final AwContents awContents = webView.getAwContents(); |
| 3218 runTestOnUiThread(new Runnable() { | 3218 runTestOnUiThread(new Runnable() { |
| 3219 @Override | 3219 @Override |
| 3220 public void run() { | 3220 public void run() { |
| 3221 awContents.getContentViewCore().sendDoubleTapForTest( | 3221 awContents.getContentViewCore().sendDoubleTapForTest( |
| 3222 SystemClock.uptimeMillis(), x, y); | 3222 SystemClock.uptimeMillis(), x, y); |
| 3223 } | 3223 } |
| 3224 }); | 3224 }); |
| 3225 } | 3225 } |
| 3226 } | 3226 } |
| OLD | NEW |