# Namespace goog.testing.events

code »

## Classes

goog.testing.events.Event goog.events.BrowserEvent expects an Event so we provide one for JSCompiler.

Show:Public Protected Private

## Global Functions

code »goog.testing.events.assertEventTarget_ ( target ) ⇒ `!EventTarget`

Asserts an event target exists. This will fail if target is not defined. TODO(nnaze): Gradually add this to the methods in this file, and eventually update the method signatures to not take nullables. See http://b/8961907

Parameters
target: `EventTarget` A target to assert.
Returns
The target, guaranteed to exist.

code »goog.testing.events.fireBlurEvent ( target ) ⇒ `boolean`

Simulate a blur event on the given target.

Parameters
target: `EventTarget` The target for the event.
Returns
The value returned by firing the blur browser event, which returns false iff 'preventDefault' was invoked.

code »goog.testing.events.fireBrowserEvent ( event ) ⇒ `boolean`

Simulates an event's capturing and bubbling phases.

Parameters
event: `Event` A simulated native event. It will be wrapped in a normalized BrowserEvent and dispatched to Closure listeners on all ancestors of its target (inclusive).
Returns
The returnValue of the event: false if preventDefault() was called on it, true otherwise.

code »goog.testing.events.fireClickEvent ( target, opt_button, opt_coords, opt_eventProperties ) ⇒ `boolean`

Simulates a click event on the given target. IE only supports click with the left mouse button.

Parameters
target: `EventTarget` The target for the event. opt_button: `goog.events.BrowserEvent.MouseButton=` Mouse button; defaults to `goog.events.BrowserEvent.MouseButton.LEFT`. opt_coords: `goog.math.Coordinate=` Mouse position. Defaults to event's target's position (if available), otherwise (0, 0). opt_eventProperties: `Object=` Event properties to be mixed into the BrowserEvent.
Returns
The returnValue of the event: false if preventDefault() was called on it, true otherwise.

code »goog.testing.events.fireClickSequence ( target, opt_button, opt_coords, opt_eventProperties ) ⇒ `boolean`

Simulates a mousedown, mouseup, and then click on the given event target, with the left mouse button.

Parameters
target: `EventTarget` The target for the event. opt_button: `goog.events.BrowserEvent.MouseButton=` Mouse button; defaults to `goog.events.BrowserEvent.MouseButton.LEFT`. opt_coords: `goog.math.Coordinate=` Mouse position. Defaults to event's target's position (if available), otherwise (0, 0). opt_eventProperties: `Object=` Event properties to be mixed into the BrowserEvent.
Returns
The returnValue of the sequence: false if preventDefault() was called on any of the events, true otherwise.

code »goog.testing.events.fireContextMenuEvent ( target, opt_coords ) ⇒ `boolean`

Simulates a contextmenu event on the given target.

Parameters
target: `EventTarget` The target for the event. opt_coords: `goog.math.Coordinate=` Mouse position. Defaults to event's target's position (if available), otherwise (0, 0).
Returns
The returnValue of the event: false if preventDefault() was called on it, true otherwise.

code »goog.testing.events.fireContextMenuSequence ( target, opt_coords ) ⇒ `boolean`

Simulates a mousedown, contextmenu, and the mouseup on the given event target, with the right mouse button.

Parameters
target: `EventTarget` The target for the event. opt_coords: `goog.math.Coordinate=` Mouse position. Defaults to event's target's position (if available), otherwise (0, 0).
Returns
The returnValue of the sequence: false if preventDefault() was called on any of the events, true otherwise.

code »goog.testing.events.fireDoubleClickEvent ( target, opt_coords, opt_eventProperties ) ⇒ `boolean`

Simulates a double-click event on the given target. Always double-clicks with the left mouse button since no browser supports double-clicking with any other buttons.

Parameters
target: `EventTarget` The target for the event. opt_coords: `goog.math.Coordinate=` Mouse position. Defaults to event's target's position (if available), otherwise (0, 0). opt_eventProperties: `Object=` Event properties to be mixed into the BrowserEvent.
Returns
The returnValue of the event: false if preventDefault() was called on it, true otherwise.

code »goog.testing.events.fireDoubleClickSequence ( target, opt_coords, opt_eventProperties ) ⇒ `boolean`

Simulates the sequence of events fired by the browser when the user double- clicks the given target.

Parameters
target: `EventTarget` The target for the event. opt_coords: `goog.math.Coordinate=` Mouse position. Defaults to event's target's position (if available), otherwise (0, 0). opt_eventProperties: `Object=` Event properties to be mixed into the BrowserEvent.
Returns
The returnValue of the sequence: false if preventDefault() was called on any of the events, true otherwise.

code »goog.testing.events.fireFocusEvent ( target ) ⇒ `boolean`

Simulate a focus event on the given target.

Parameters
target: `EventTarget` The target for the event.
Returns
The value returned by firing the focus browser event, which returns false iff 'preventDefault' was invoked.

code »goog.testing.events.fireKeySequence ( target, keyCode, opt_eventProperties ) ⇒ `boolean`

Simulates a complete keystroke (keydown, keypress, and keyup). Note that if preventDefault is called on the keydown, the keypress will not fire.

Parameters
target: `EventTarget` The target for the event. keyCode: `number` The keycode of the key pressed. opt_eventProperties: `Object=` Event properties to be mixed into the BrowserEvent.
Returns
The returnValue of the sequence: false if preventDefault() was called on any of the events, true otherwise.

code »goog.testing.events.fireMouseButtonEvent_ ( type, target, opt_button, opt_coords, opt_eventProperties ) ⇒ `boolean`

Helper function to fire a mouse event. with the left mouse button since no browser supports double-clicking with any other buttons.

Parameters
type: `string` The event type. target: `EventTarget` The target for the event. opt_button: `number=` Mouse button; defaults to `goog.events.BrowserEvent.MouseButton.LEFT`. opt_coords: `goog.math.Coordinate=` Mouse position. Defaults to event's target's position (if available), otherwise (0, 0). opt_eventProperties: `Object=` Event properties to be mixed into the BrowserEvent.
Returns
The returnValue of the event: false if preventDefault() was called on it, true otherwise.

code »goog.testing.events.fireMouseDownEvent ( target, opt_button, opt_coords, opt_eventProperties ) ⇒ `boolean`

Simulates a mousedown event on the given target.

Parameters
target: `EventTarget` The target for the event. opt_button: `goog.events.BrowserEvent.MouseButton=` Mouse button; defaults to `goog.events.BrowserEvent.MouseButton.LEFT`. opt_coords: `goog.math.Coordinate=` Mouse position. Defaults to event's target's position (if available), otherwise (0, 0). opt_eventProperties: `Object=` Event properties to be mixed into the BrowserEvent.
Returns
The returnValue of the event: false if preventDefault() was called on it, true otherwise.

code »goog.testing.events.fireMouseMoveEvent ( target, opt_coords ) ⇒ `boolean`

Simulates a mousemove event on the given target.

Parameters
target: `EventTarget` The target for the event. opt_coords: `goog.math.Coordinate=` Mouse position. Defaults to event's target's position (if available), otherwise (0, 0).
Returns
The returnValue of the event: false if preventDefault() was called on it, true otherwise.

code »goog.testing.events.fireMouseOutEvent ( target, relatedTarget, opt_coords ) ⇒ `boolean`

Simulates a mouseout event on the given target.

Parameters
target: `EventTarget` The target for the event. relatedTarget: `EventTarget` The related target for the event (e.g., the node that the mouse is being moved into). opt_coords: `goog.math.Coordinate=` Mouse position. Defaults to event's target's position (if available), otherwise (0, 0).
Returns
The returnValue of the event: false if preventDefault() was called on it, true otherwise.

code »goog.testing.events.fireMouseOverEvent ( target, relatedTarget, opt_coords ) ⇒ `boolean`

Simulates a mouseover event on the given target.

Parameters
target: `EventTarget` The target for the event. relatedTarget: `EventTarget` The related target for the event (e.g., the node that the mouse is being moved out of). opt_coords: `goog.math.Coordinate=` Mouse position. Defaults to event's target's position (if available), otherwise (0, 0).
Returns
The returnValue of the event: false if preventDefault() was called on it, true otherwise.

code »goog.testing.events.fireMouseUpEvent ( target, opt_button, opt_coords, opt_eventProperties ) ⇒ `boolean`

Simulates a mouseup event on the given target.

Parameters
target: `EventTarget` The target for the event. opt_button: `goog.events.BrowserEvent.MouseButton=` Mouse button; defaults to `goog.events.BrowserEvent.MouseButton.LEFT`. opt_coords: `goog.math.Coordinate=` Mouse position. Defaults to event's target's position (if available), otherwise (0, 0). opt_eventProperties: `Object=` Event properties to be mixed into the BrowserEvent.
Returns
The returnValue of the event: false if preventDefault() was called on it, true otherwise.

code »goog.testing.events.fireNonAsciiKeySequence ( target, keyCode, keyPressKeyCode, opt_eventProperties ) ⇒ `boolean`

Simulates a complete keystroke (keydown, keypress, and keyup) when typing a non-ASCII character. Same as fireKeySequence, the keypress will not fire if preventDefault is called on the keydown.

Parameters
target: `EventTarget` The target for the event. keyCode: `number` The keycode of the keydown and keyup events. keyPressKeyCode: `number` The keycode of the keypress event. opt_eventProperties: `Object=` Event properties to be mixed into the BrowserEvent.
Returns
The returnValue of the sequence: false if preventDefault() was called on any of the events, true otherwise.

code »goog.testing.events.firePopStateEvent ( target, state ) ⇒ `boolean`

Simulates a popstate event on the given target.

Parameters
target: `EventTarget` The target for the event. state: `Object` History state object.
Returns
The returnValue of the event: false if preventDefault() was called on it, true otherwise.

code »goog.testing.events.fireTouchEndEvent ( target, opt_coords, opt_eventProperties ) ⇒ `boolean`

Simulates a touchend event on the given target.

Parameters
target: `EventTarget` The target for the event. opt_coords: `goog.math.Coordinate=` Touch position. Defaults to event's target's position (if available), otherwise (0, 0). opt_eventProperties: `Object=` Event properties to be mixed into the BrowserEvent.
Returns
The returnValue of the event: false if preventDefault() was called on it, true otherwise.

code »goog.testing.events.fireTouchMoveEvent ( target, opt_coords, opt_eventProperties ) ⇒ `boolean`

Simulates a touchmove event on the given target.

Parameters
target: `EventTarget` The target for the event. opt_coords: `goog.math.Coordinate=` Touch position. Defaults to event's target's position (if available), otherwise (0, 0). opt_eventProperties: `Object=` Event properties to be mixed into the BrowserEvent.
Returns
The returnValue of the event: false if preventDefault() was called on it, true otherwise.

code »goog.testing.events.fireTouchSequence ( target, opt_coords, opt_eventProperties ) ⇒ `boolean`

Simulates a simple touch sequence on the given target.

Parameters
target: `EventTarget` The target for the event. opt_coords: `goog.math.Coordinate=` Touch position. Defaults to event target's position (if available), otherwise (0, 0). opt_eventProperties: `Object=` Event properties to be mixed into the BrowserEvent.
Returns
The returnValue of the sequence: false if preventDefault() was called on any of the events, true otherwise.

code »goog.testing.events.fireTouchStartEvent ( target, opt_coords, opt_eventProperties ) ⇒ `boolean`

Simulates a touchstart event on the given target.

Parameters
target: `EventTarget` The target for the event. opt_coords: `goog.math.Coordinate=` Touch position. Defaults to event's target's position (if available), otherwise (0, 0). opt_eventProperties: `Object=` Event properties to be mixed into the BrowserEvent.
Returns
The returnValue of the event: false if preventDefault() was called on it, true otherwise.

code »goog.testing.events.isBrokenGeckoMacActionKey_ ( e ) ⇒ `boolean`

Parameters
e: `goog.testing.events.Event` The event.
Returns
Whether this is the Gecko/Mac's Meta-C/V/X, which is broken and requires special handling.

code »goog.testing.events.mixinListenable ( obj )

Mixins a listenable into the given object. This turns the object into a goog.events.Listenable. This is useful, for example, when you need to mock a implementation of listenable and still want it to work with goog.events.

Parameters
obj: `!Object` The object to mixin into.

code »goog.testing.events.setEventClientXY_ ( event, opt_coords )

A static helper function that sets the mouse position to the event.

Parameters
event: `Event` A simulated native event. opt_coords: `goog.math.Coordinate=` Mouse position. Defaults to event's target's position (if available), otherwise (0, 0).