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

Unified Diff: base/message_loop/message_loop_test.cc

Issue 1891233006: mus: Fix handled status in UI event ack, add MessageLoop::NestingObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@eventresult
Patch Set: review comments 3 Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/message_loop/message_loop_test.h ('k') | base/run_loop.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_loop/message_loop_test.cc
diff --git a/base/message_loop/message_loop_test.cc b/base/message_loop/message_loop_test.cc
index c0e6481c4209b785a9bfee60800b63b5f73080d1..0f1e924518cbdcb78d1bc46924d66dcc874d6139 100644
--- a/base/message_loop/message_loop_test.cc
+++ b/base/message_loop/message_loop_test.cc
@@ -378,6 +378,66 @@ void RunTest_Nesting(MessagePumpFactory factory) {
EXPECT_EQ(depth, 0);
}
+// A NestingObserver that tracks the number of nested message loop starts it
+// has seen.
+class TestNestingObserver : public MessageLoop::NestingObserver {
+ public:
+ TestNestingObserver() {}
+ ~TestNestingObserver() override {}
+
+ int begin_nested_loop_count() const { return begin_nested_loop_count_; }
+
+ // MessageLoop::NestingObserver:
+ void OnBeginNestedMessageLoop() override { begin_nested_loop_count_++; }
+
+ private:
+ int begin_nested_loop_count_ = 0;
+
+ DISALLOW_COPY_AND_ASSIGN(TestNestingObserver);
+};
+
+void ExpectOneBeginNestedLoop(TestNestingObserver* observer) {
+ EXPECT_EQ(1, observer->begin_nested_loop_count());
+}
+
+// Starts a nested message loop.
+void RunNestedLoop(TestNestingObserver* observer,
+ const Closure& quit_outer_loop) {
+ // The nested loop hasn't started yet.
+ EXPECT_EQ(0, observer->begin_nested_loop_count());
+
+ MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
+ RunLoop nested_loop;
+ // Verify that by the time the first task is run the observer has seen the
+ // message loop begin.
+ MessageLoop::current()->PostTask(FROM_HERE,
+ Bind(&ExpectOneBeginNestedLoop, observer));
+ MessageLoop::current()->PostTask(FROM_HERE, nested_loop.QuitClosure());
+ nested_loop.Run();
+
+ // Quitting message loops doesn't change the begin count.
+ EXPECT_EQ(1, observer->begin_nested_loop_count());
+
+ quit_outer_loop.Run();
+}
+
+// Tests that a NestingObserver is notified when a nested message loop begins.
+void RunTest_NestingObserver(MessagePumpFactory factory) {
+ std::unique_ptr<MessagePump> pump(factory());
+ MessageLoop outer_loop(std::move(pump));
+
+ // Observe the outer loop for nested message loops beginning.
+ TestNestingObserver nesting_observer;
+ outer_loop.AddNestingObserver(&nesting_observer);
+
+ // Post a task that runs a nested message loop.
+ outer_loop.PostTask(FROM_HERE, Bind(&RunNestedLoop, &nesting_observer,
+ outer_loop.QuitWhenIdleClosure()));
+ outer_loop.Run();
+
+ outer_loop.RemoveNestingObserver(&nesting_observer);
+}
+
enum TaskType {
MESSAGEBOX,
ENDDIALOG,
« no previous file with comments | « base/message_loop/message_loop_test.h ('k') | base/run_loop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698