@@ -33,18 +33,22 @@ base::ResultError<> error(const std::ostringstream& ss) {
3333 return base::ResultError (ss.str (), BAD_VALUE);
3434}
3535
36+ inline auto getId (const trace::TracedEvent& v) {
37+ return std::visit ([](const auto & event) { return event.id ; }, v);
38+ }
39+
3640} // namespace
3741
3842// --- VerifyingTrace ---
3943
40- void VerifyingTrace::expectKeyDispatchTraced (const KeyEvent& event) {
44+ void VerifyingTrace::expectKeyDispatchTraced (const KeyEvent& event, int32_t windowId ) {
4145 std::scoped_lock lock (mLock );
42- mExpectedEvents .emplace_back (event);
46+ mExpectedEvents .emplace_back (event, windowId );
4347}
4448
45- void VerifyingTrace::expectMotionDispatchTraced (const MotionEvent& event) {
49+ void VerifyingTrace::expectMotionDispatchTraced (const MotionEvent& event, int32_t windowId ) {
4650 std::scoped_lock lock (mLock );
47- mExpectedEvents .emplace_back (event);
51+ mExpectedEvents .emplace_back (event, windowId );
4852}
4953
5054void VerifyingTrace::verifyExpectedEventsTraced () {
@@ -53,9 +57,9 @@ void VerifyingTrace::verifyExpectedEventsTraced() {
5357
5458 base::Result<void > result;
5559 mEventTracedCondition .wait_for (lock, TRACE_TIMEOUT, [&]() REQUIRES (mLock ) {
56- for (const auto & expectedEvent : mExpectedEvents ) {
60+ for (const auto & [ expectedEvent, windowId] : mExpectedEvents ) {
5761 std::visit ([&](const auto & event)
58- REQUIRES (mLock ) { result = verifyEventTraced (event); },
62+ REQUIRES (mLock ) { result = verifyEventTraced (event, windowId ); },
5963 expectedEvent);
6064 if (!result.ok ()) {
6165 return false ;
@@ -72,11 +76,13 @@ void VerifyingTrace::verifyExpectedEventsTraced() {
7276void VerifyingTrace::reset () {
7377 std::scoped_lock lock (mLock );
7478 mTracedEvents .clear ();
79+ mTracedWindowDispatches .clear ();
7580 mExpectedEvents .clear ();
7681}
7782
7883template <typename Event>
79- base::Result<void > VerifyingTrace::verifyEventTraced (const Event& expectedEvent) const {
84+ base::Result<void > VerifyingTrace::verifyEventTraced (const Event& expectedEvent,
85+ int32_t expectedWindowId) const {
8086 std::ostringstream msg;
8187
8288 auto tracedEventsIt = mTracedEvents .find (expectedEvent.getId ());
@@ -87,6 +93,19 @@ base::Result<void> VerifyingTrace::verifyEventTraced(const Event& expectedEvent)
8793 return error (msg);
8894 }
8995
96+ auto tracedDispatchesIt =
97+ std::find_if (mTracedWindowDispatches .begin (), mTracedWindowDispatches .end (),
98+ [&](const WindowDispatchArgs& args) {
99+ return args.windowId == expectedWindowId &&
100+ getId (args.eventEntry ) == expectedEvent.getId ();
101+ });
102+ if (tracedDispatchesIt == mTracedWindowDispatches .end ()) {
103+ msg << " Expected dispatch of event with ID 0x" << std::hex << expectedEvent.getId ()
104+ << " to window with ID 0x" << expectedWindowId << " to be traced, but it was not."
105+ << " \n Expected event: " << expectedEvent;
106+ return error (msg);
107+ }
108+
90109 return {};
91110}
92111
@@ -108,4 +127,12 @@ void FakeInputTracingBackend::traceMotionEvent(const trace::TracedMotionEvent& e
108127 mTrace ->mEventTracedCondition .notify_all ();
109128}
110129
130+ void FakeInputTracingBackend::traceWindowDispatch (const WindowDispatchArgs& args) const {
131+ {
132+ std::scoped_lock lock (mTrace ->mLock );
133+ mTrace ->mTracedWindowDispatches .push_back (args);
134+ }
135+ mTrace ->mEventTracedCondition .notify_all ();
136+ }
137+
111138} // namespace android::inputdispatcher
0 commit comments