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

Side by Side Diff: mojo/public/cpp/system/tests/watcher_unittest.cc

Issue 1811433002: [mojo-edk] Expose notification source to MojoWatch callbacks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 // This should trigger the watcher above... 195 // This should trigger the watcher above...
196 b.reset(); 196 b.reset();
197 // ...but the watcher is cancelled first. 197 // ...but the watcher is cancelled first.
198 b_watcher.Cancel(); 198 b_watcher.Cancel();
199 199
200 EXPECT_FALSE(b_watcher.IsWatching()); 200 EXPECT_FALSE(b_watcher.IsWatching());
201 201
202 base::RunLoop().RunUntilIdle(); 202 base::RunLoop().RunUntilIdle();
203 } 203 }
204 204
205 TEST_F(WatcherTest, SyncDispatch) {
206 ScopedMessagePipeHandle a, b;
207 CreateMessagePipe(nullptr, &a, &b);
208
209 bool notified = false;
210 Watcher b_watcher;
211 EXPECT_EQ(MOJO_RESULT_OK,
212 b_watcher.Start(b.get(), MOJO_HANDLE_SIGNAL_READABLE,
213 OnReady([&] (MojoResult result) {
214 EXPECT_EQ(MOJO_RESULT_OK, result);
215 notified = true;
216 })));
217 EXPECT_TRUE(b_watcher.IsWatching());
218
219 b_watcher.SetAllowSyncDispatch(true);
220 EXPECT_EQ(MOJO_RESULT_OK, WriteMessageRaw(a.get(), "hello", 5, nullptr, 0,
221 MOJO_WRITE_MESSAGE_FLAG_NONE));
222
223 // We don't spin the MessageLoop but should have been notified anyway.
224
225 EXPECT_TRUE(notified);
226
227 b_watcher.Cancel();
228 }
229
205 } // namespace 230 } // namespace
206 } // namespace mojo 231 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698