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. 4 5 #include "ui/events/test/platform_event_waiter.h" 6 7 #include "base/message_loop/message_loop.h" 8 #include "ui/events/platform/platform_event_source.h" 9 10 namespace ui { 11 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); 18 } 19 20 PlatformEventWaiter::~PlatformEventWaiter() { 21 PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this); 22 } 23 24 void PlatformEventWaiter::WillProcessEvent(const PlatformEvent& event) { 25 if (event_matcher_.Run(event)) { 26 base::MessageLoop::current()->PostTask(FROM_HERE, success_callback_); 27 delete this; 28 } 29 } 30 31 void PlatformEventWaiter::DidProcessEvent(const PlatformEvent& event) { 32 } 33 34 // static 35 PlatformEventWaiter* PlatformEventWaiter::Create( 36 const base::Closure& success_callback, 37 const PlatformEventMatcher& event_matcher) { 38 return new PlatformEventWaiter(success_callback, event_matcher); 39 } 40 41 } // namespace ui 42