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

Unified Diff: base/message_loop/message_loop_unittest.cc

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/message_loop/message_loop.cc ('k') | base/message_loop/message_pump_android.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_loop/message_loop_unittest.cc
diff --git a/base/message_loop/message_loop_unittest.cc b/base/message_loop/message_loop_unittest.cc
index 70b3f8ba50937142097d22c78659795eb65fbd41..84379d7f95e1b111eb7f95d2adeb44479d59052f 100644
--- a/base/message_loop/message_loop_unittest.cc
+++ b/base/message_loop/message_loop_unittest.cc
@@ -26,6 +26,11 @@
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
+#if defined(OS_ANDROID)
+#include "base/android/jni_android.h"
+#include "base/test/android/java_handler_thread_for_testing.h"
+#endif
+
#if defined(OS_WIN)
#include "base/message_loop/message_pump_win.h"
#include "base/process/memory.h"
@@ -75,6 +80,52 @@ class Foo : public RefCounted<Foo> {
std::string result_;
};
+#if defined(OS_ANDROID)
+void AbortMessagePump() {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ jclass exception = env->FindClass(
+ "org/chromium/base/TestSystemMessageHandler$TestException");
+
+ env->ThrowNew(exception,
+ "This is a test exception that should be caught in "
+ "TestSystemMessageHandler.handleMessage");
+ static_cast<base::MessageLoopForUI*>(base::MessageLoop::current())->Abort();
+}
+
+void RunTest_AbortDontRunMoreTasks(bool delayed) {
+ MessageLoop loop(MessageLoop::TYPE_JAVA);
+
+ WaitableEvent test_done_event(WaitableEvent::ResetPolicy::MANUAL,
+ WaitableEvent::InitialState::NOT_SIGNALED);
+
+ std::unique_ptr<android::JavaHandlerThreadForTesting> java_thread;
+ java_thread.reset(new android::JavaHandlerThreadForTesting(
+ "JavaHandlerThreadForTesting from AbortDontRunMoreTasks",
+ &test_done_event));
+ java_thread->Start();
+
+ if (delayed) {
+ java_thread->message_loop()->PostDelayedTask(
+ FROM_HERE, Bind(&AbortMessagePump), TimeDelta::FromMilliseconds(10));
+ } else {
+ java_thread->message_loop()->PostTask(FROM_HERE, Bind(&AbortMessagePump));
+ }
+
+ // Wait to ensure we catch the correct exception (and don't crash)
+ test_done_event.Wait();
+
+ java_thread->Stop();
+ java_thread.reset();
+}
+
+TEST(MessageLoopTest, JavaExceptionAbort) {
+ RunTest_AbortDontRunMoreTasks(false);
+}
+TEST(MessageLoopTest, DelayedJavaExceptionAbort) {
+ RunTest_AbortDontRunMoreTasks(true);
+}
+#endif // defined(OS_ANDROID)
+
#if defined(OS_WIN)
// This function runs slowly to simulate a large amount of work being done.
« no previous file with comments | « base/message_loop/message_loop.cc ('k') | base/message_loop/message_pump_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698