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

Side by Side Diff: mojo/edk/base_edk/platform_message_loop_impl_unittest.cc

Issue 1465203003: EDK: Make ConnectionManagerTest not use base::MessageLoop/RunLoop. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « mojo/edk/base_edk/platform_message_loop_impl.cc ('k') | mojo/edk/platform/message_loop.h » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/edk/base_edk/platform_message_loop_impl.h" 5 #include "mojo/edk/base_edk/platform_message_loop_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <thread> 8 #include <thread>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 task_runner->PostTask(ToClosure([&stuff, &message_loop, &task_runner]() { 62 task_runner->PostTask(ToClosure([&stuff, &message_loop, &task_runner]() {
63 EXPECT_TRUE(message_loop.IsRunningOnCurrentThread()); 63 EXPECT_TRUE(message_loop.IsRunningOnCurrentThread());
64 stuff.push_back(4); 64 stuff.push_back(4);
65 task_runner->PostTask(ToClosure([&stuff]() { stuff.push_back(6); })); 65 task_runner->PostTask(ToClosure([&stuff]() { stuff.push_back(6); }));
66 })); 66 }));
67 task_runner->PostTask(ToClosure([&stuff]() { stuff.push_back(5); })); 67 task_runner->PostTask(ToClosure([&stuff]() { stuff.push_back(5); }));
68 message_loop.RunUntilIdle(); 68 message_loop.RunUntilIdle();
69 EXPECT_EQ(std::vector<int>({4, 5, 6}), stuff); 69 EXPECT_EQ(std::vector<int>({4, 5, 6}), stuff);
70 70
71 stuff.clear(); 71 stuff.clear();
72 task_runner->PostTask(ToClosure([&stuff, &message_loop, &task_runner]() {
73 EXPECT_TRUE(message_loop.IsRunningOnCurrentThread());
74 stuff.push_back(7);
75 message_loop.QuitNow();
76 task_runner->PostTask(ToClosure([&stuff]() { stuff.push_back(9); }));
77 }));
78 task_runner->PostTask(ToClosure([&stuff]() { stuff.push_back(8); }));
79 message_loop.Run();
80 EXPECT_EQ(std::vector<int>({7}), stuff);
81 stuff.clear();
82 message_loop.RunUntilIdle();
83 EXPECT_EQ(std::vector<int>({8, 9}), stuff);
84
85 stuff.clear();
72 message_loop.RunUntilIdle(); 86 message_loop.RunUntilIdle();
73 EXPECT_TRUE(stuff.empty()); 87 EXPECT_TRUE(stuff.empty());
74 88
75 { 89 {
76 std::thread other_thread([&message_loop]() { 90 std::thread other_thread([&message_loop]() {
77 // |IsRunningOnCurrentThread()| may be called on any thread. 91 // |IsRunningOnCurrentThread()| may be called on any thread.
78 EXPECT_FALSE(message_loop.IsRunningOnCurrentThread()); 92 EXPECT_FALSE(message_loop.IsRunningOnCurrentThread());
79 }); 93 });
80 other_thread.join(); 94 other_thread.join();
81 } 95 }
82 96
83 stuff.clear(); 97 stuff.clear();
84 task_runner->PostTask(ToClosure([&stuff, &message_loop, &task_runner]() { 98 task_runner->PostTask(ToClosure([&stuff, &message_loop, &task_runner]() {
85 EXPECT_TRUE(message_loop.IsRunningOnCurrentThread()); 99 EXPECT_TRUE(message_loop.IsRunningOnCurrentThread());
86 std::thread other_thread([&stuff, &message_loop, task_runner]() { 100 std::thread other_thread([&stuff, &message_loop, task_runner]() {
87 EXPECT_FALSE(message_loop.IsRunningOnCurrentThread()); 101 EXPECT_FALSE(message_loop.IsRunningOnCurrentThread());
88 EXPECT_EQ(task_runner, message_loop.GetTaskRunner()); 102 EXPECT_EQ(task_runner, message_loop.GetTaskRunner());
89 stuff.push_back(7); 103 stuff.push_back(10);
90 task_runner->PostTask(ToClosure([&stuff, &message_loop]() { 104 task_runner->PostTask(ToClosure([&stuff, &message_loop]() {
91 EXPECT_TRUE(message_loop.IsRunningOnCurrentThread()); 105 EXPECT_TRUE(message_loop.IsRunningOnCurrentThread());
92 stuff.push_back(8); 106 stuff.push_back(11);
93 message_loop.QuitWhenIdle(); 107 message_loop.QuitWhenIdle();
94 })); 108 }));
95 }); 109 });
96 other_thread.join(); 110 other_thread.join();
97 EXPECT_EQ(std::vector<int>({7}), stuff); 111 EXPECT_EQ(std::vector<int>({10}), stuff);
98 stuff.clear(); 112 stuff.clear();
99 })); 113 }));
100 message_loop.Run(); 114 message_loop.Run();
101 EXPECT_EQ(std::vector<int>({8}), stuff); 115 EXPECT_EQ(std::vector<int>({11}), stuff);
102 } 116 }
103 117
104 TEST(PlatformMessageLoopImpl, TypeIO) { 118 TEST(PlatformMessageLoopImpl, TypeIO) {
105 PlatformMessageLoopImpl message_loop(base::MessageLoop::TYPE_IO); 119 PlatformMessageLoopImpl message_loop(base::MessageLoop::TYPE_IO);
106 120
107 EXPECT_EQ(base::MessageLoop::TYPE_IO, 121 EXPECT_EQ(base::MessageLoop::TYPE_IO,
108 message_loop.base_message_loop().type()); 122 message_loop.base_message_loop().type());
109 123
110 RefPtr<TaskRunner> task_runner = message_loop.GetTaskRunner(); 124 RefPtr<TaskRunner> task_runner = message_loop.GetTaskRunner();
111 EXPECT_TRUE(task_runner); 125 EXPECT_TRUE(task_runner);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 bool was_run = false; 157 bool was_run = false;
144 message_loop->GetTaskRunner()->PostTask( 158 message_loop->GetTaskRunner()->PostTask(
145 ToClosure([&was_run]() { was_run = true; })); 159 ToClosure([&was_run]() { was_run = true; }));
146 EXPECT_FALSE(was_run); 160 EXPECT_FALSE(was_run);
147 message_loop->RunUntilIdle(); 161 message_loop->RunUntilIdle();
148 EXPECT_TRUE(was_run); 162 EXPECT_TRUE(was_run);
149 } 163 }
150 164
151 } // namespace 165 } // namespace
152 } // namespace base_edk 166 } // namespace base_edk
OLDNEW
« no previous file with comments | « mojo/edk/base_edk/platform_message_loop_impl.cc ('k') | mojo/edk/platform/message_loop.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698