Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/message_loop/message_loop_test.h" | 17 #include "base/message_loop/message_loop_test.h" |
| 18 #include "base/pending_task.h" | 18 #include "base/pending_task.h" |
| 19 #include "base/posix/eintr_wrapper.h" | 19 #include "base/posix/eintr_wrapper.h" |
| 20 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
| 21 #include "base/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
| 22 #include "base/test/test_simple_task_runner.h" | 22 #include "base/test/test_simple_task_runner.h" |
| 23 #include "base/threading/platform_thread.h" | 23 #include "base/threading/platform_thread.h" |
| 24 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
| 25 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
| 26 #include "build/build_config.h" | 26 #include "build/build_config.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 28 |
| 29 #if defined(OS_ANDROID) | |
| 30 #include "base/android/java_handler_thread.h" | |
| 31 #include "base/android/jni_android.h" | |
| 32 #endif | |
| 33 | |
| 29 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
| 30 #include "base/message_loop/message_pump_win.h" | 35 #include "base/message_loop/message_pump_win.h" |
| 31 #include "base/process/memory.h" | 36 #include "base/process/memory.h" |
| 32 #include "base/strings/string16.h" | 37 #include "base/strings/string16.h" |
| 33 #include "base/win/current_module.h" | 38 #include "base/win/current_module.h" |
| 34 #include "base/win/scoped_handle.h" | 39 #include "base/win/scoped_handle.h" |
| 35 #endif | 40 #endif |
| 36 | 41 |
| 37 namespace base { | 42 namespace base { |
| 38 | 43 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 68 | 73 |
| 69 private: | 74 private: |
| 70 friend class RefCounted<Foo>; | 75 friend class RefCounted<Foo>; |
| 71 | 76 |
| 72 ~Foo() {} | 77 ~Foo() {} |
| 73 | 78 |
| 74 int test_count_; | 79 int test_count_; |
| 75 std::string result_; | 80 std::string result_; |
| 76 }; | 81 }; |
| 77 | 82 |
| 83 #if defined(OS_ANDROID) | |
| 84 void AbortMessagePump() { | |
| 85 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 86 jclass exception = | |
| 87 env->FindClass("org/chromium/base/SystemMessageHandler$TestException"); | |
| 88 | |
| 89 env->ThrowNew(exception, | |
| 90 "This is a test exception that should be caught in " | |
| 91 "SystemMessageHandler.handleMessage"); | |
| 92 static_cast<base::MessageLoopForUI*>(base::MessageLoop::current())->Abort(); | |
| 93 } | |
| 94 | |
| 95 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.
| |
| 96 MessageLoop loop(MessageLoop::TYPE_JAVA); | |
| 97 | |
| 98 WaitableEvent test_done_event(WaitableEvent::ResetPolicy::MANUAL, | |
| 99 WaitableEvent::InitialState::NOT_SIGNALED); | |
| 100 | |
| 101 std::unique_ptr<android::JavaHandlerThread> java_thread; | |
| 102 java_thread.reset(new android::JavaHandlerThread("yolo")); | |
| 103 java_thread->StartForTesting(&test_done_event); | |
| 104 | |
| 105 if (delayed) { | |
| 106 java_thread->message_loop()->PostDelayedTask( | |
| 107 FROM_HERE, Bind(&AbortMessagePump), TimeDelta::FromMilliseconds(10)); | |
| 108 } else { | |
| 109 java_thread->message_loop()->PostTask(FROM_HERE, Bind(&AbortMessagePump)); | |
| 110 } | |
| 111 | |
| 112 // Wait to ensure we didn't crash | |
| 113 test_done_event.Wait(); | |
| 114 | |
| 115 java_thread->StopForTesting(); | |
| 116 java_thread.reset(); | |
| 117 } | |
| 118 | |
| 119 TEST(MessageLoopTest, Java_Exception_Abort) { | |
| 120 RunTest_Abort_Dont_Run_More_Tasks(false); | |
| 121 } | |
| 122 TEST(MessageLoopTest, Delayed_Java_Exception_Abort) { | |
| 123 RunTest_Abort_Dont_Run_More_Tasks(true); | |
| 124 } | |
| 125 #endif // defined(OS_ANDROID) | |
| 126 | |
| 78 #if defined(OS_WIN) | 127 #if defined(OS_WIN) |
| 79 | 128 |
| 80 // This function runs slowly to simulate a large amount of work being done. | 129 // This function runs slowly to simulate a large amount of work being done. |
| 81 static void SlowFunc(TimeDelta pause, int* quit_counter) { | 130 static void SlowFunc(TimeDelta pause, int* quit_counter) { |
| 82 PlatformThread::Sleep(pause); | 131 PlatformThread::Sleep(pause); |
| 83 if (--(*quit_counter) == 0) | 132 if (--(*quit_counter) == 0) |
| 84 MessageLoop::current()->QuitWhenIdle(); | 133 MessageLoop::current()->QuitWhenIdle(); |
| 85 } | 134 } |
| 86 | 135 |
| 87 // This function records the time when Run was called in a Time object, which is | 136 // This function records the time when Run was called in a Time object, which is |
| (...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 990 | 1039 |
| 991 { | 1040 { |
| 992 std::string kThreadName("bar"); | 1041 std::string kThreadName("bar"); |
| 993 base::Thread thread(kThreadName); | 1042 base::Thread thread(kThreadName); |
| 994 ASSERT_TRUE(thread.StartAndWaitForTesting()); | 1043 ASSERT_TRUE(thread.StartAndWaitForTesting()); |
| 995 EXPECT_EQ(kThreadName, thread.message_loop()->GetThreadName()); | 1044 EXPECT_EQ(kThreadName, thread.message_loop()->GetThreadName()); |
| 996 } | 1045 } |
| 997 } | 1046 } |
| 998 | 1047 |
| 999 } // namespace base | 1048 } // namespace base |
| OLD | NEW |