// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/events/scoped_target_handler.h" #include <memory> #include <utility> #include "base/memory/ptr_util.h" #include "base/memory/raw_ptr.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/events/event_handler.h" #include "ui/events/event_target.h" #include "ui/events/event_target_iterator.h" #include "ui/events/event_utils.h" namespace ui { namespace { class TestEventTargetIterator : public EventTargetIterator { … }; // An EventTarget that holds ownership of its target and delegate EventHandlers. class TestEventTarget : public EventTarget { … }; // An EventHandler that sets itself as a target handler for an EventTarget and // can recursively dispatch an Event. class NestedEventHandler : public EventHandler { … }; // An EventHandler that sets itself as a target handler for an EventTarget and // destroys that EventTarget when handling an Event, possibly after recursively // handling the Event. class TargetDestroyingEventHandler : public EventHandler { … }; // An EventHandler that can be set to receive events in addition to the target // handler and counts the Events that it receives. class EventCountingEventHandler : public EventHandler { … }; // An EventCountingEventHandler that will also mark the event to stop further // propataion. class EventStopPropagationHandler : public EventCountingEventHandler { … }; } // namespace // Tests that a ScopedTargetHandler invokes both the target and a delegate. TEST(ScopedTargetHandlerTest, HandlerInvoked) { … } // Tests that a ScopedTargetHandler invokes both the target and a delegate but // does not further propagate the event after a handler stops event propagation. TEST(ScopedTargetHandlerTest, HandlerInvokedOnceThenEventStopsPropagating) { … } // Tests that a ScopedTargetHandler invokes both the target and a delegate when // an Event is dispatched recursively such as with synthetic events. TEST(ScopedTargetHandlerTest, HandlerInvokedNested) { … } // Tests that a it is safe to delete a ScopedTargetHandler while handling an // event. TEST(ScopedTargetHandlerTest, SafeToDestroy) { … } // Tests that a it is safe to delete a ScopedTargetHandler while handling an // event recursively. TEST(ScopedTargetHandlerTest, SafeToDestroyNested) { … } } // namespace ui