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

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

Issue 2201783003: Add test to ensure shouldOverrideUrlLoading throws Java exception (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add testbase for separate-service tests, use this from AwSecondBrowserTest. Created 4 years, 3 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/JniCrashTest.java
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/JniCrashTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/JniCrashTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..856dd52959b4d244be3deaba915f03855da75d06
--- /dev/null
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/JniCrashTest.java
@@ -0,0 +1,52 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.android_webview.test;
+
+import android.os.Handler;
+import android.os.Message;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import org.chromium.base.test.util.Feature;
+
+/**
+ * Test class ensuring we handle Java exceptions thrown in WebView callbacks correctly.
+ */
+public class JniCrashTest extends SeparateServiceTestBase {
+ private static final String TAG = JniCrashTest.class.getSimpleName();
+
+ /**
+ * Ensure that java exceptions thrown in the shouldOverrideUrlLoading callback are propagated
+ * properly to the process using WebView (rather than causing a native crash).
+ *
+ * OBS! This test does not support method annotations such as DisableHardwareAccelerationForTest
+ * since the actual "WebView" creation is performed in another process.
+ */
+ @LargeTest
+ @Feature({"AndroidWebView"})
+ public void testShouldOverrideUrlLoadingCrash() throws Exception {
+ runServiceTestBlocking(
+ new ShouldOverrideUrlLoadingJniCrashTestRunner(), new Handler.Callback() {
+ @Override
+ public boolean handleMessage(Message message) {
+ switch (message.what) {
+ case ShouldOverrideUrlLoadingJniCrashTestRunner
+ .RETURN_JNI_CRASH_TEST_SUCCESS:
+ return true;
+ case ShouldOverrideUrlLoadingJniCrashTestRunner
+ .RETURN_JNI_CRASH_TEST_FAILED:
+ fail("Something went wrong in the separate process, see logcat");
+ return true;
+ default:
+ fail("Received an unexpected message response " + message);
+ return false;
+ }
+ }
+ }, true /* unBindAndStopService */);
+ // Since we override the UnhandledExceptionHandler in the separate WebView process we
+ // should ensure we kill it properly.
+ killSeparateProcess();
+ resetSeparateProcessPid();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698