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

Unified Diff: android_webview/javatests/src/org/chromium/android_webview/test/LoadUrlTest.java

Issue 366913006: [Android WebView] Terminate execution of stuck JS code on navigation requests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: android_webview/javatests/src/org/chromium/android_webview/test/LoadUrlTest.java
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/LoadUrlTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/LoadUrlTest.java
index 4a6bab55c7560e251fd9b143673134be9e0e3761..77fb3704fd3c45b8f658d5914b9980b7880f691a 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/LoadUrlTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/LoadUrlTest.java
@@ -4,9 +4,12 @@
package org.chromium.android_webview.test;
+import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Pair;
+import junit.framework.Assert;
+
import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.chromium.android_webview.AwContents;
@@ -331,4 +334,71 @@ public class LoadUrlTest extends AwTestBase {
if (webServer != null) webServer.shutdown();
}
}
+
+ private static class TestController {
+ private final Object mLock = new Object();
+ private boolean mIsReady = false;
+ public void notifyPageIsReady() {
+ synchronized (mLock) {
+ mIsReady = true;
+ mLock.notify();
+ }
+ }
+ public void waitUntilIsReady() {
+ synchronized (mLock) {
+ while (!mIsReady) {
+ try {
+ mLock.wait(WAIT_TIMEOUT_MS);
+ } catch (Exception e) {
+ continue;
+ }
+ if (!mIsReady) {
+ Assert.fail("Wait timed out");
+ }
+ }
+ mIsReady = false;
+ }
+ }
+ }
+
+ // Verify that it is possible to interrupt JS scripts stuck in an infinite loop
+ // by calling loadUrl on a WebView.
+ @LargeTest
+ @Feature({"AndroidWebView"})
+ public void testLoadUrlInterruptsLoopedScripts() throws Throwable {
+ final String infiniteLoopPage =
+ "<html><head>" +
+ " <script>" +
+ " function infiniteLoop() {" +
+ " test.notifyPageIsReady();" +
+ " while(1);" +
+ " }" +
+ " </script>" +
+ "</head><body onload='setTimeout(infiniteLoop, 0)'>" +
+ "</body></html>";
+ final String simplePage = "<html><body onload='test.notifyPageIsReady()'></body></html>";
+ final String expectedTitle = "PASS";
+ final String pageWithTitle = "<html><body onload='document.title=\"" + expectedTitle +
+ "\"; test.notifyPageIsReady()'></body></html>";
+
+ final AwTestContainerView testContainerView =
+ createAwTestContainerViewOnMainSync(new TestAwContentsClient());
+ final AwContents awContents = testContainerView.getAwContents();
+ getAwSettingsOnUiThread(awContents).setJavaScriptEnabled(true);
+ final TestController testController = new TestController();
+ getInstrumentation().runOnMainSync(new Runnable() {
+ @Override
+ public void run() {
+ awContents.addPossiblyUnsafeJavascriptInterface(testController, "test", null);
+ }
+ });
+ loadDataAsync(awContents, infiniteLoopPage, "text/html", false);
+ testController.waitUntilIsReady();
+ loadDataAsync(awContents, simplePage, "text/html", false);
+ testController.waitUntilIsReady();
+ // Load another page that runs JS to make sure that the WebView is still functional.
+ loadDataAsync(awContents, pageWithTitle, "text/html", false);
+ testController.waitUntilIsReady();
+ assertEquals(expectedTitle, getTitleOnUiThread(awContents));
+ }
}
« no previous file with comments | « android_webview/java/src/org/chromium/android_webview/AwContents.java ('k') | android_webview/native/aw_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698