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

Unified Diff: base/test/android/java/src/org/chromium/base/TestSystemMessageHandler.java

Issue 2169553002: Properly throw java exceptions from shouldOverrideUrlLoading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix trybot compilation failure. Created 4 years, 4 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
« no previous file with comments | « base/test/BUILD.gn ('k') | base/test/android/java_handler_thread_for_testing.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/android/java/src/org/chromium/base/TestSystemMessageHandler.java
diff --git a/base/test/android/java/src/org/chromium/base/TestSystemMessageHandler.java b/base/test/android/java/src/org/chromium/base/TestSystemMessageHandler.java
new file mode 100644
index 0000000000000000000000000000000000000000..b6ba8df7a7ee971019b5dea0a29cac03e3268e7b
--- /dev/null
+++ b/base/test/android/java/src/org/chromium/base/TestSystemMessageHandler.java
@@ -0,0 +1,54 @@
+// 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.base;
+
+import android.os.Message;
+
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.base.annotations.JNINamespace;
+
+/**
+ * Test-only message handler enabling us to test that Java exceptions thrown from a JNI call
+ * originating from the native side are propagated to the Message Handler (instead of causing a
+ * native crash).
+ * This class declares a custom exception and wraps the SystemMessageHandler message handling
+ * mechanism to catch such exceptions. When catching an exception we call the native side to notify
+ * tests that the correct exception was thrown and caught.
+ */
+@JNINamespace("base::android")
+class TestSystemMessageHandler extends SystemMessageHandler {
+ private long mWaitableTestEventNative;
+
+ private TestSystemMessageHandler(
+ long messagePumpDelegateNative, long messagePumpNative, long waitableTestEventNative) {
+ super(messagePumpDelegateNative, messagePumpNative);
+ mWaitableTestEventNative = waitableTestEventNative;
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ try {
+ super.handleMessage(msg);
+ } catch (TestException e) {
+ nativeNotifyTestDone(mWaitableTestEventNative);
+ return;
+ }
+ }
+
+ private static class TestException extends RuntimeException {
+ TestException(String message) {
+ super(message);
+ }
+ }
+
+ @CalledByNative
+ private static TestSystemMessageHandler create(
+ long messagePumpDelegateNative, long messagePumpNative, long waitableTestEvent) {
+ return new TestSystemMessageHandler(
+ messagePumpDelegateNative, messagePumpNative, waitableTestEvent);
+ }
+
+ private static native void nativeNotifyTestDone(long messagePumpNative);
+}
« no previous file with comments | « base/test/BUILD.gn ('k') | base/test/android/java_handler_thread_for_testing.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698