1// Copyright (c) 2010 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#ifndef CHROME_BROWSER_UI_COCOA_TEST_EVENT_UTILS_H_ 6#define CHROME_BROWSER_UI_COCOA_TEST_EVENT_UTILS_H_ 7#pragma once 8 9#include <utility> 10 11#import <objc/objc-class.h> 12 13#include "base/basictypes.h" 14 15// Within a given scope, replace the selector |selector| on |target| with that 16// from |source|. 17class ScopedClassSwizzler { 18 public: 19 ScopedClassSwizzler(Class target, Class source, SEL selector); 20 ~ScopedClassSwizzler(); 21 22 private: 23 Method old_selector_impl_; 24 Method new_selector_impl_; 25 26 DISALLOW_COPY_AND_ASSIGN(ScopedClassSwizzler); 27}; 28 29namespace test_event_utils { 30 31// Create synthetic mouse events for testing. Currently these are very 32// basic, flesh out as needed. Points are all in window coordinates; 33// where the window is not specified, coordinate system is undefined 34// (but will be repeated when the event is queried). 35NSEvent* MakeMouseEvent(NSEventType type, NSUInteger modifiers); 36NSEvent* MouseEventAtPoint(NSPoint point, NSEventType type, 37 NSUInteger modifiers); 38NSEvent* LeftMouseDownAtPoint(NSPoint point); 39NSEvent* LeftMouseDownAtPointInWindow(NSPoint point, NSWindow* window); 40 41// Return a mouse down and an up event with the given |clickCount| at 42// |view|'s midpoint. 43std::pair<NSEvent*, NSEvent*> MouseClickInView(NSView* view, 44 NSUInteger clickCount); 45 46} // namespace test_event_utils 47 48#endif // CHROME_BROWSER_UI_COCOA_TEST_EVENT_UTILS_H_ 49