| 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 android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.support.test.filters.SmallTest; | 8 import android.support.test.filters.SmallTest; |
| 9 import android.util.Pair; | 9 import android.util.Pair; |
| 10 | 10 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 private void setupWithProvidedContentsClient(TestAwContentsClient contentsCl
ient) | 72 private void setupWithProvidedContentsClient(TestAwContentsClient contentsCl
ient) |
| 73 throws Throwable { | 73 throws Throwable { |
| 74 mContentsClient = contentsClient; | 74 mContentsClient = contentsClient; |
| 75 mTestContainerView = createAwTestContainerViewOnMainSync(contentsClient)
; | 75 mTestContainerView = createAwTestContainerViewOnMainSync(contentsClient)
; |
| 76 mAwContents = mTestContainerView.getAwContents(); | 76 mAwContents = mTestContainerView.getAwContents(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 private void clickOnLinkUsingJs() throws Throwable { | 79 private void clickOnLinkUsingJs() throws Throwable { |
| 80 enableJavaScriptOnUiThread(mAwContents); | 80 enableJavaScriptOnUiThread(mAwContents); |
| 81 JSUtils.clickOnLinkUsingJs(this, mAwContents, | 81 JSUtils.clickOnLinkUsingJs(getInstrumentation(), mAwContents, |
| 82 mContentsClient.getOnEvaluateJavaScriptResultHelper(), "link"); | 82 mContentsClient.getOnEvaluateJavaScriptResultHelper(), "link"); |
| 83 } | 83 } |
| 84 | 84 |
| 85 // Since this value is read on the UI thread, it's simpler to set it there t
oo. | 85 // Since this value is read on the UI thread, it's simpler to set it there t
oo. |
| 86 void setShouldOverrideUrlLoadingReturnValueOnUiThread(final boolean value) t
hrows Throwable { | 86 void setShouldOverrideUrlLoadingReturnValueOnUiThread(final boolean value) t
hrows Throwable { |
| 87 runTestOnUiThread(new Runnable() { | 87 runTestOnUiThread(new Runnable() { |
| 88 @Override | 88 @Override |
| 89 public void run() { | 89 public void run() { |
| 90 mShouldOverrideUrlLoadingHelper.setShouldOverrideUrlLoadingRetur
nValue(value); | 90 mShouldOverrideUrlLoadingHelper.setShouldOverrideUrlLoadingRetur
nValue(value); |
| 91 } | 91 } |
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 setupWithProvidedContentsClient(new TestDefaultContentsClient()); | 919 setupWithProvidedContentsClient(new TestDefaultContentsClient()); |
| 920 enableJavaScriptOnUiThread(mAwContents); | 920 enableJavaScriptOnUiThread(mAwContents); |
| 921 final String pageTitle = "Click Title"; | 921 final String pageTitle = "Click Title"; |
| 922 final String htmlWithLink = "<html><title>" + pageTitle + "</title>" | 922 final String htmlWithLink = "<html><title>" + pageTitle + "</title>" |
| 923 + "<body><a id='link' href='" + testUrl + "'>Click this!</a>
</body></html>"; | 923 + "<body><a id='link' href='" + testUrl + "'>Click this!</a>
</body></html>"; |
| 924 final String urlWithLink = mWebServer.setResponse( | 924 final String urlWithLink = mWebServer.setResponse( |
| 925 "/html_with_link.html", htmlWithLink, CommonResources.getTex
tHtmlHeaders(true)); | 925 "/html_with_link.html", htmlWithLink, CommonResources.getTex
tHtmlHeaders(true)); |
| 926 | 926 |
| 927 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
urlWithLink); | 927 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
urlWithLink); |
| 928 // Executing JS code that tries to navigate somewhere should not cre
ate an intent. | 928 // Executing JS code that tries to navigate somewhere should not cre
ate an intent. |
| 929 assertEquals("\"" + testUrl + "\"", JSUtils.executeJavaScriptAndWait
ForResult( | 929 assertEquals("\"" + testUrl + "\"", |
| 930 this, mAwContents, new OnEvaluateJavaScriptResultHel
per(), | 930 JSUtils.executeJavaScriptAndWaitForResult(getInstrumentation
(), mAwContents, |
| 931 new OnEvaluateJavaScriptResultHelper(), |
| 931 "document.location.href='" + testUrl + "'")); | 932 "document.location.href='" + testUrl + "'")); |
| 932 assertNull(getActivity().getLastSentIntent()); | 933 assertNull(getActivity().getLastSentIntent()); |
| 933 | 934 |
| 934 // Clicking on a link should create an intent. | 935 // Clicking on a link should create an intent. |
| 935 DOMUtils.clickNode(mAwContents.getContentViewCore(), "link"); | 936 DOMUtils.clickNode(mAwContents.getContentViewCore(), "link"); |
| 936 pollUiThread(new Callable<Boolean>() { | 937 pollUiThread(new Callable<Boolean>() { |
| 937 @Override | 938 @Override |
| 938 public Boolean call() { | 939 public Boolean call() { |
| 939 return getActivity().getLastSentIntent() != null; | 940 return getActivity().getLastSentIntent() != null; |
| 940 } | 941 } |
| 941 }); | 942 }); |
| 942 assertEquals(testUrl, getActivity().getLastSentIntent().getData().to
String()); | 943 assertEquals(testUrl, getActivity().getLastSentIntent().getData().to
String()); |
| 943 } finally { | 944 } finally { |
| 944 getActivity().setIgnoreStartActivity(false); | 945 getActivity().setIgnoreStartActivity(false); |
| 945 } | 946 } |
| 946 } | 947 } |
| 947 } | 948 } |
| OLD | NEW |