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 "mojo/common/handle_watcher.h" | 5 #include "mojo/common/handle_watcher.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/test/simple_test_tick_clock.h" | 12 #include "base/test/simple_test_tick_clock.h" |
13 #include "mojo/common/time_helper.h" | 13 #include "mojo/common/time_helper.h" |
14 #include "mojo/public/cpp/environment/environment.h" | 14 #include "mojo/public/cpp/environment/environment.h" |
15 #include "mojo/public/cpp/system/core.h" | 15 #include "mojo/public/cpp/system/core.h" |
16 #include "mojo/public/cpp/test_support/test_utils.h" | 16 #include "mojo/public/cpp/test_support/test_utils.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 namespace mojo { | 19 namespace mojo { |
20 namespace common { | 20 namespace common { |
21 namespace test { | 21 namespace test { |
22 | 22 |
23 void ObserveCallback(bool* was_signaled, MojoResult* result_observed, | |
sky
2014/05/13 21:22:42
nit: one param per line when you wrap.
| |
24 MojoResult result) { | |
25 *was_signaled = true; | |
26 *result_observed = result; | |
27 } | |
28 | |
23 void RunUntilIdle() { | 29 void RunUntilIdle() { |
24 base::RunLoop run_loop; | 30 base::RunLoop run_loop; |
25 run_loop.RunUntilIdle(); | 31 run_loop.RunUntilIdle(); |
26 } | 32 } |
27 | 33 |
28 void DeleteWatcherAndForwardResult( | 34 void DeleteWatcherAndForwardResult( |
29 HandleWatcher* watcher, | 35 HandleWatcher* watcher, |
30 base::Callback<void(MojoResult)> next_callback, | 36 base::Callback<void(MojoResult)> next_callback, |
31 MojoResult result) { | 37 MojoResult result) { |
32 delete watcher; | 38 delete watcher; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 callback_helper.StartWithCallback(watcher, test_pipe.handle1.get(), | 314 callback_helper.StartWithCallback(watcher, test_pipe.handle1.get(), |
309 base::Bind(&DeleteWatcherAndForwardResult, | 315 base::Bind(&DeleteWatcherAndForwardResult, |
310 watcher, | 316 watcher, |
311 callback_helper.GetCallback())); | 317 callback_helper.GetCallback())); |
312 EXPECT_TRUE(mojo::test::WriteTextMessage(test_pipe.handle0.get(), | 318 EXPECT_TRUE(mojo::test::WriteTextMessage(test_pipe.handle0.get(), |
313 std::string())); | 319 std::string())); |
314 callback_helper.RunUntilGotCallback(); | 320 callback_helper.RunUntilGotCallback(); |
315 EXPECT_TRUE(callback_helper.got_callback()); | 321 EXPECT_TRUE(callback_helper.got_callback()); |
316 } | 322 } |
317 | 323 |
324 TEST(HandleWatcherCleanEnvironmentTest, AbortedOnMessageLoopDestruction) { | |
325 bool was_signaled = false; | |
326 MojoResult result; | |
sky
2014/05/13 21:22:42
nit: initialize this to something.
| |
327 | |
328 Environment env; | |
329 | |
330 MessagePipe pipe; | |
331 HandleWatcher watcher; | |
332 { | |
333 base::MessageLoop loop; | |
334 | |
335 watcher.Start(pipe.handle0.get(), | |
336 MOJO_WAIT_FLAG_READABLE, | |
337 MOJO_DEADLINE_INDEFINITE, | |
338 base::Bind(&ObserveCallback, &was_signaled, &result)); | |
339 | |
340 // Now, let the MessageLoop get torn down. We expect our callback to run. | |
341 } | |
342 | |
343 EXPECT_TRUE(was_signaled); | |
344 EXPECT_EQ(MOJO_RESULT_ABORTED, result); | |
345 } | |
346 | |
318 } // namespace test | 347 } // namespace test |
319 } // namespace common | 348 } // namespace common |
320 } // namespace mojo | 349 } // namespace mojo |
OLD | NEW |