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.os.Build; | 7 import android.os.Build; |
8 import android.test.suitebuilder.annotation.SmallTest; | 8 import android.test.suitebuilder.annotation.SmallTest; |
9 import android.util.Pair; | 9 import android.util.Pair; |
10 | 10 |
11 import org.chromium.android_webview.AwContents; | 11 import org.chromium.android_webview.AwContents; |
12 import org.chromium.android_webview.test.util.CommonResources; | 12 import org.chromium.android_webview.test.util.CommonResources; |
13 import org.chromium.android_webview.test.util.JSUtils; | 13 import org.chromium.android_webview.test.util.JSUtils; |
14 import org.chromium.android_webview.test.util.JavascriptEventObserver; | |
14 import org.chromium.base.annotations.SuppressFBWarnings; | 15 import org.chromium.base.annotations.SuppressFBWarnings; |
15 import org.chromium.base.test.util.DisabledTest; | 16 import org.chromium.base.test.util.DisabledTest; |
16 import org.chromium.base.test.util.Feature; | 17 import org.chromium.base.test.util.Feature; |
17 import org.chromium.base.test.util.MinAndroidSdkLevel; | 18 import org.chromium.base.test.util.MinAndroidSdkLevel; |
18 import org.chromium.content.browser.test.util.CallbackHelper; | 19 import org.chromium.content.browser.test.util.CallbackHelper; |
19 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage StartedHelper; | 20 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage StartedHelper; |
20 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnRece ivedErrorHelper; | 21 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnRece ivedErrorHelper; |
21 import org.chromium.content_public.browser.LoadUrlParams; | 22 import org.chromium.content_public.browser.LoadUrlParams; |
22 import org.chromium.net.test.util.TestWebServer; | 23 import org.chromium.net.test.util.TestWebServer; |
23 | 24 |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
863 clickOnLinkUsingJs(awContents, contentsClient); | 864 clickOnLinkUsingJs(awContents, contentsClient); |
864 shouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingC allCount); | 865 shouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingC allCount); |
865 | 866 |
866 pollOnUiThread(new Callable<Boolean>() { | 867 pollOnUiThread(new Callable<Boolean>() { |
867 @Override | 868 @Override |
868 public Boolean call() { | 869 public Boolean call() { |
869 return AwContents.getNativeInstanceCount() == 0; | 870 return AwContents.getNativeInstanceCount() == 0; |
870 } | 871 } |
871 }); | 872 }); |
872 } | 873 } |
874 | |
875 @SmallTest | |
876 @Feature({"AndroidWebView"}) | |
877 public void testXhrOnLoad() throws Throwable { | |
878 final TestAwContentsClient contentsClient = new TestAwContentsClient(); | |
879 final AwTestContainerView testContainerView = | |
880 createAwTestContainerViewOnMainSync(contentsClient); | |
881 final AwContents awContents = testContainerView.getAwContents(); | |
882 TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoa dingHelper = | |
883 contentsClient.getShouldOverrideUrlLoadingHelper(); | |
884 | |
885 final String startPath = "/startPath.html"; | |
886 final String startUrl = addPageToTestServer(mWebServer, | |
887 startPath, | |
888 CommonResources.makeHtmlPageFrom("", "")); | |
889 | |
890 final String xhrPath = "/xhrPath.html"; | |
891 final String xhrUrl = addPageToTestServer(mWebServer, | |
892 xhrPath, | |
893 CommonResources.makeHtmlPageFrom("", "")); | |
894 | |
895 final String xhrJs = | |
896 "(function() {" | |
897 + " var xhr = new XMLHttpRequest();" | |
898 + " xhr.onload=function() {" | |
899 + " console.info('xhr loaded');" | |
900 + " window.jsInterface.setValue(true);" | |
901 + " };" | |
902 + " xhr.onerror=function() {" | |
903 + " console.info('xhr failed, status ' + xhr.status);" | |
904 + " window.jsInterface.setValue(false);" | |
905 + " };" | |
906 + " xhr.open('GET', '" + xhrUrl + "', true);" | |
907 + " xhr.send();" // TODO need to delay xhr request handling on the server to make | |
908 // sure that xhr request won't be handled before shouldInterrupt UrlLoading? | |
mnaganov (inactive)
2015/06/04 19:09:27
typo: shouldOverrideUrlLoading?
| |
909 + " window.location = 'interception://whatwhat/';" | |
910 + "})();"; | |
911 enableJavaScriptOnUiThread(awContents); | |
912 final BooleanValueJavascriptObserver jsInterface = new BooleanValueJavas criptObserver(); | |
913 | |
914 // add javascript interface | |
915 getInstrumentation().runOnMainSync(new Runnable() { | |
916 @Override | |
917 public void run() { | |
918 jsInterface.register(awContents.getContentViewCore(), "jsInterfa ce"); | |
919 } | |
920 }); | |
921 | |
922 setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadin gHelper, true); | |
923 | |
924 loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), startU rl); | |
925 | |
926 executeJavaScriptAndWaitForResult(awContents, contentsClient, xhrJs); | |
927 | |
928 jsInterface.waitForEvent(WAIT_TIMEOUT_MS); // TODO waiting timeout ok? | |
sgurun-gerrit only
2015/06/05 07:52:49
I was expecting a little bit different test: one w
| |
929 assertTrue(jsInterface.getValue()); | |
930 assertEquals(1, mWebServer.getRequestCount(xhrPath)); | |
931 } | |
932 | |
933 private class BooleanValueJavascriptObserver extends JavascriptEventObserver { | |
934 private boolean mValue = false; | |
935 | |
936 public void setValue(boolean value) { | |
937 mValue = value; | |
938 notifyJava(); | |
939 } | |
940 | |
941 public boolean getValue() { | |
942 return mValue; | |
943 } | |
944 } | |
873 } | 945 } |
OLD | NEW |