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

Unified Diff: mojo/public/cpp/system/tests/watcher_unittest.cc

Issue 2480153004: Revert of Remove MessageLoop destruction observer from mojo::Watcher. (Closed)
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ipc/ipc_sync_channel.cc ('k') | mojo/public/cpp/system/watcher.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/system/tests/watcher_unittest.cc
diff --git a/mojo/public/cpp/system/tests/watcher_unittest.cc b/mojo/public/cpp/system/tests/watcher_unittest.cc
index ebeebf6777888a67aeeba7af1b6bf0290cd2d312..5cb3ed23b7799571da5820a1d81492791b8267f1 100644
--- a/mojo/public/cpp/system/tests/watcher_unittest.cc
+++ b/mojo/public/cpp/system/tests/watcher_unittest.cc
@@ -8,7 +8,6 @@
#include "base/bind.h"
#include "base/callback.h"
-#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/threading/thread_task_runner_handle.h"
@@ -36,10 +35,16 @@
WatcherTest() {}
~WatcherTest() override {}
- private:
- base::MessageLoop message_loop_;
-
- DISALLOW_COPY_AND_ASSIGN(WatcherTest);
+ void SetUp() override {
+ message_loop_.reset(new base::MessageLoop);
+ }
+
+ void TearDown() override {
+ message_loop_.reset();
+ }
+
+ protected:
+ std::unique_ptr<base::MessageLoop> message_loop_;
};
TEST_F(WatcherTest, WatchBasic) {
@@ -157,6 +162,28 @@
run_loop.Run();
}
+TEST_F(WatcherTest, NotifyOnMessageLoopDestruction) {
+ ScopedMessagePipeHandle a, b;
+ CreateMessagePipe(nullptr, &a, &b);
+
+ bool notified = false;
+ Watcher b_watcher;
+ EXPECT_EQ(MOJO_RESULT_OK,
+ b_watcher.Start(b.get(), MOJO_HANDLE_SIGNAL_READABLE,
+ OnReady([&] (MojoResult result) {
+ EXPECT_EQ(MOJO_RESULT_ABORTED, result);
+ notified = true;
+ })));
+ EXPECT_TRUE(b_watcher.IsWatching());
+
+ message_loop_.reset();
+
+ EXPECT_TRUE(notified);
+
+ EXPECT_TRUE(b_watcher.IsWatching());
+ b_watcher.Cancel();
+}
+
TEST_F(WatcherTest, CloseAndCancel) {
ScopedMessagePipeHandle a, b;
CreateMessagePipe(nullptr, &a, &b);
« no previous file with comments | « ipc/ipc_sync_channel.cc ('k') | mojo/public/cpp/system/watcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698