OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.base; |
| 6 |
| 7 import android.os.Message; |
| 8 |
| 9 import org.chromium.base.annotations.CalledByNative; |
| 10 import org.chromium.base.annotations.JNINamespace; |
| 11 |
| 12 /** |
| 13 * Test-only message handler enabling us to test that Java exceptions thrown fro
m a JNI call |
| 14 * originating from the native side are propagated to the Message Handler (inste
ad of causing a |
| 15 * native crash). |
| 16 * This class declares a custom exception and wraps the SystemMessageHandler mes
sage handling |
| 17 * mechanism to catch such exceptions. When catching an exception we call the na
tive side to notify |
| 18 * tests that the correct exception was thrown and caught. |
| 19 */ |
| 20 @JNINamespace("base::android") |
| 21 class TestSystemMessageHandler extends SystemMessageHandler { |
| 22 private long mWaitableTestEventNative; |
| 23 |
| 24 private TestSystemMessageHandler( |
| 25 long messagePumpDelegateNative, long messagePumpNative, long waitabl
eTestEventNative) { |
| 26 super(messagePumpDelegateNative, messagePumpNative); |
| 27 mWaitableTestEventNative = waitableTestEventNative; |
| 28 } |
| 29 |
| 30 @Override |
| 31 public void handleMessage(Message msg) { |
| 32 try { |
| 33 super.handleMessage(msg); |
| 34 } catch (TestException e) { |
| 35 nativeNotifyTestDone(mWaitableTestEventNative); |
| 36 return; |
| 37 } |
| 38 } |
| 39 |
| 40 private static class TestException extends RuntimeException { |
| 41 TestException(String message) { |
| 42 super(message); |
| 43 } |
| 44 } |
| 45 |
| 46 @CalledByNative |
| 47 private static TestSystemMessageHandler create( |
| 48 long messagePumpDelegateNative, long messagePumpNative, long waitabl
eTestEvent) { |
| 49 return new TestSystemMessageHandler( |
| 50 messagePumpDelegateNative, messagePumpNative, waitableTestEvent)
; |
| 51 } |
| 52 |
| 53 private static native void nativeNotifyTestDone(long messagePumpNative); |
| 54 } |
OLD | NEW |