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

Unified Diff: base/test/android/java_handler_thread_for_testing.cc

Issue 2169553002: Properly throw java exceptions from shouldOverrideUrlLoading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused includes in test_support_android.cc. 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/test/android/java_handler_thread_for_testing.cc
diff --git a/base/test/android/java_handler_thread_for_testing.cc b/base/test/android/java_handler_thread_for_testing.cc
new file mode 100644
index 0000000000000000000000000000000000000000..896f78550399a9eebbbc8fcfcfd88ba9a999c9e9
--- /dev/null
+++ b/base/test/android/java_handler_thread_for_testing.cc
@@ -0,0 +1,49 @@
+// 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.
+
+#include "base/test/android/java_handler_thread_for_testing.h"
+
+#include "base/message_loop/message_loop.h"
+
+namespace base {
+namespace android {
+
+base::android::ScopedJavaLocalRef<jobject>
+TestJavaMessageHandlerFactory::CreateMessageHandler(
+ JNIEnv* env,
+ base::MessagePump::Delegate* delegate,
+ MessagePumpForUI* message_pump,
+ WaitableEvent* test_done_event) {
+ return TestSystemMessageHandlerLink::createTestSystemMessageHandler(
+ env, delegate, message_pump, test_done_event);
+}
+
+JavaHandlerThreadForTesting::JavaHandlerThreadForTesting(
+ const char* name,
+ base::WaitableEvent* test_done_event)
+ : JavaHandlerThread(name),
+ message_handler_factory_(new TestJavaMessageHandlerFactory()),
+ test_done_event_(test_done_event) {}
+
+JavaHandlerThreadForTesting::~JavaHandlerThreadForTesting() = default;
+
+void JavaHandlerThreadForTesting::StartMessageLoop() {
+ static_cast<MessageLoopForUI*>(message_loop_.get())
+ ->StartForTesting(
+ message_handler_factory_.get(),
+ reinterpret_cast<base::WaitableEvent*>(test_done_event_));
+}
+
+void JavaHandlerThreadForTesting::StopMessageLoop() {
+ // Instead of calling MessageLoop::QuitWhenIdle here we call
+ // MessageLoop::QuitNow. This is because QuitWhenIdle will have no effect on
+ // the message loop after MessageLoop::Abort has been called (which should
+ // have happened at this point).
+ static_cast<MessageLoopForUI*>(message_loop_.get())->QuitNow();
+ // The message loop must be destroyed on the thread it is attached to.
+ message_loop_.reset();
+}
+
+} // namespace base
+} // namespace android

Powered by Google App Engine
This is Rietveld 408576698