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

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: Better separation of production and test code, and minor cleanups. 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
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..1076caef09dd42ba1d8953388bcc87074f2c7783 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/java_handler_thread.h"
+#include "base/android/jni_android.h"
+#endif
+
#if defined(OS_WIN)
#include "base/message_loop/message_pump_win.h"
#include "base/process/memory.h"
@@ -75,6 +80,50 @@ 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/SystemMessageHandler$TestException");
+
+ env->ThrowNew(exception,
+ "This is a test exception that should be caught in "
+ "SystemMessageHandler.handleMessage");
+ static_cast<base::MessageLoopForUI*>(base::MessageLoop::current())->Abort();
+}
+
+void RunTest_Abort_Dont_Run_More_Tasks(bool delayed) {
danakj 2016/08/15 18:29:59 normally for CapitilizedNames you don't put _ betw
gsennton 2016/08/16 15:27:36 Done.
+ MessageLoop loop(MessageLoop::TYPE_JAVA);
+
+ WaitableEvent test_done_event(WaitableEvent::ResetPolicy::MANUAL,
+ WaitableEvent::InitialState::NOT_SIGNALED);
+
+ std::unique_ptr<android::JavaHandlerThread> java_thread;
+ java_thread.reset(new android::JavaHandlerThread("yolo"));
+ java_thread->StartForTesting(&test_done_event);
+
+ 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 didn't crash
+ test_done_event.Wait();
+
+ java_thread->StopForTesting();
+ java_thread.reset();
+}
+
+TEST(MessageLoopTest, Java_Exception_Abort) {
+ RunTest_Abort_Dont_Run_More_Tasks(false);
+}
+TEST(MessageLoopTest, Delayed_Java_Exception_Abort) {
+ RunTest_Abort_Dont_Run_More_Tasks(true);
+}
+#endif // defined(OS_ANDROID)
+
#if defined(OS_WIN)
// This function runs slowly to simulate a large amount of work being done.

Powered by Google App Engine
This is Rietveld 408576698