cocoa_test_event_utils.h revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef UI_EVENTS_TEST_COCOA_TEST_EVENT_UTILS_H_ 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define UI_EVENTS_TEST_COCOA_TEST_EVENT_UTILS_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <utility> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import <objc/objc-class.h> 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Within a given scope, replace the selector |selector| on |target| with that 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// from |source|. 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ScopedClassSwizzler { 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScopedClassSwizzler(Class target, Class source, SEL selector); 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~ScopedClassSwizzler(); 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Method old_selector_impl_; 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Method new_selector_impl_; 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ScopedClassSwizzler); 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace cocoa_test_event_utils { 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Create synthetic mouse events for testing. Currently these are very 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// basic, flesh out as needed. Points are all in window coordinates; 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// where the window is not specified, coordinate system is undefined 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (but will be repeated when the event is queried). 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSEvent* MouseEventWithType(NSEventType type, NSUInteger modifiers); 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSEvent* MouseEventAtPoint(NSPoint point, NSEventType type, 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NSUInteger modifiers); 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSEvent* LeftMouseDownAtPoint(NSPoint point); 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSEvent* LeftMouseDownAtPointInWindow(NSPoint point, NSWindow* window); 39f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)NSEvent* RightMouseDownAtPoint(NSPoint point); 40f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)NSEvent* RightMouseDownAtPointInWindow(NSPoint point, NSWindow* window); 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Return a mouse down and an up event with the given |clickCount| at 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |view|'s midpoint. 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)std::pair<NSEvent*, NSEvent*> MouseClickInView(NSView* view, 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NSUInteger clickCount); 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns a key event with the given character. 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSEvent* KeyEventWithCharacter(unichar c); 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns a key event with the given type and modifier flags. 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSEvent* KeyEventWithType(NSEventType event_type, NSUInteger modifiers); 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns a key event with the given key code, type, and modifier flags. 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSEvent* KeyEventWithKeyCode(unsigned short key_code, 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unichar c, 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NSEventType event_type, 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NSUInteger modifiers); 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns a mouse enter/exit event with the given type. 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSEvent* EnterExitEventWithType(NSEventType event_type); 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Return an "other" event with the given type. 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSEvent* OtherEventWithType(NSEventType event_type); 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace cocoa_test_event_utils 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif // UI_EVENTS_TEST_COCOA_TEST_EVENT_UTILS_H_ 68