1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/events/test/platform_event_waiter.h"
7 #include "base/message_loop/message_loop.h"
8 #include "ui/events/platform/platform_event_source.h"
12 PlatformEventWaiter::PlatformEventWaiter(
13 const base::Closure
& success_callback
,
14 const PlatformEventMatcher
& event_matcher
)
15 : success_callback_(success_callback
),
16 event_matcher_(event_matcher
) {
17 PlatformEventSource::GetInstance()->AddPlatformEventObserver(this);
20 PlatformEventWaiter::~PlatformEventWaiter() {
21 PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this);
24 void PlatformEventWaiter::WillProcessEvent(const PlatformEvent
& event
) {
25 if (event_matcher_
.Run(event
)) {
26 base::MessageLoop::current()->PostTask(FROM_HERE
, success_callback_
);
31 void PlatformEventWaiter::DidProcessEvent(const PlatformEvent
& event
) {
35 PlatformEventWaiter
* PlatformEventWaiter::Create(
36 const base::Closure
& success_callback
,
37 const PlatformEventMatcher
& event_matcher
) {
38 return new PlatformEventWaiter(success_callback
, event_matcher
);