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

Side by Side Diff: mojo/common/handle_watcher_unittest.cc

Issue 281353005: Mojo: nuke EnvironmentData (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix gn Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/common/handle_watcher.cc ('k') | mojo/environment/environment.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/at_exit.h"
9 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/run_loop.h" 12 #include "base/run_loop.h"
12 #include "base/test/simple_test_tick_clock.h" 13 #include "base/test/simple_test_tick_clock.h"
13 #include "mojo/common/time_helper.h" 14 #include "mojo/common/time_helper.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, 23 void ObserveCallback(bool* was_signaled,
24 MojoResult* result_observed, 24 MojoResult* result_observed,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 109 }
110 110
111 protected: 111 protected:
112 void InstallTickClock() { 112 void InstallTickClock() {
113 test::SetTickClockForTest(&tick_clock_); 113 test::SetTickClockForTest(&tick_clock_);
114 } 114 }
115 115
116 base::SimpleTestTickClock tick_clock_; 116 base::SimpleTestTickClock tick_clock_;
117 117
118 private: 118 private:
119 Environment environment_; 119 base::ShadowingAtExitManager at_exit_;
120 base::MessageLoop message_loop_; 120 base::MessageLoop message_loop_;
121 121
122 DISALLOW_COPY_AND_ASSIGN(HandleWatcherTest); 122 DISALLOW_COPY_AND_ASSIGN(HandleWatcherTest);
123 }; 123 };
124 124
125 // Trivial test case with a single handle to watch. 125 // Trivial test case with a single handle to watch.
126 TEST_F(HandleWatcherTest, SingleHandler) { 126 TEST_F(HandleWatcherTest, SingleHandler) {
127 MessagePipe test_pipe; 127 MessagePipe test_pipe;
128 ASSERT_TRUE(test_pipe.handle0.is_valid()); 128 ASSERT_TRUE(test_pipe.handle0.is_valid());
129 CallbackHelper callback_helper; 129 CallbackHelper callback_helper;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 EXPECT_TRUE(mojo::test::WriteTextMessage(test_pipe.handle0.get(), 311 EXPECT_TRUE(mojo::test::WriteTextMessage(test_pipe.handle0.get(),
312 std::string())); 312 std::string()));
313 callback_helper.RunUntilGotCallback(); 313 callback_helper.RunUntilGotCallback();
314 EXPECT_TRUE(callback_helper.got_callback()); 314 EXPECT_TRUE(callback_helper.got_callback());
315 } 315 }
316 316
317 TEST(HandleWatcherCleanEnvironmentTest, AbortedOnMessageLoopDestruction) { 317 TEST(HandleWatcherCleanEnvironmentTest, AbortedOnMessageLoopDestruction) {
318 bool was_signaled = false; 318 bool was_signaled = false;
319 MojoResult result = MOJO_RESULT_OK; 319 MojoResult result = MOJO_RESULT_OK;
320 320
321 Environment env; 321 base::ShadowingAtExitManager at_exit;
322
323 MessagePipe pipe; 322 MessagePipe pipe;
324 HandleWatcher watcher; 323 HandleWatcher watcher;
325 { 324 {
326 base::MessageLoop loop; 325 base::MessageLoop loop;
327 326
328 watcher.Start(pipe.handle0.get(), 327 watcher.Start(pipe.handle0.get(),
329 MOJO_WAIT_FLAG_READABLE, 328 MOJO_WAIT_FLAG_READABLE,
330 MOJO_DEADLINE_INDEFINITE, 329 MOJO_DEADLINE_INDEFINITE,
331 base::Bind(&ObserveCallback, &was_signaled, &result)); 330 base::Bind(&ObserveCallback, &was_signaled, &result));
332 331
333 // Now, let the MessageLoop get torn down. We expect our callback to run. 332 // Now, let the MessageLoop get torn down. We expect our callback to run.
334 } 333 }
335 334
336 EXPECT_TRUE(was_signaled); 335 EXPECT_TRUE(was_signaled);
337 EXPECT_EQ(MOJO_RESULT_ABORTED, result); 336 EXPECT_EQ(MOJO_RESULT_ABORTED, result);
338 } 337 }
339 338
340 } // namespace test 339 } // namespace test
341 } // namespace common 340 } // namespace common
342 } // namespace mojo 341 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/common/handle_watcher.cc ('k') | mojo/environment/environment.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698