| 1 |
// Copyright 2008 The Closure Library Authors. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
goog.provide('goog.events.EventTest'); |
| 16 |
goog.setTestOnly('goog.events.EventTest'); |
| 17 |
|
| 18 |
goog.require('goog.events.Event'); |
| 19 |
goog.require('goog.events.EventId'); |
| 20 |
goog.require('goog.events.EventTarget'); |
| 21 |
goog.require('goog.testing.jsunit'); |
| 22 |
|
| 23 |
var e, target; |
| 24 |
|
| 25 |
function setUp() { |
| 26 |
target = new goog.events.EventTarget(); |
| 27 |
e = new goog.events.Event('eventType', target); |
| 28 |
} |
| 29 |
|
| 30 |
function tearDown() { |
| 31 |
target.dispose(); |
| 32 |
} |
| 33 |
|
| 34 |
function testConstructor() { |
| 35 |
assertNotNull('Event must not be null', e); |
| 36 |
assertEquals('Event type must be as expected', 'eventType', e.type); |
| 37 |
assertEquals('Event target must be as expected', target, e.target); |
| 38 |
assertEquals('Current target must be as expected', target, e.currentTarget); |
| 39 |
} |
| 40 |
|
| 41 |
function testStopPropagation() { |
| 42 |
// This test breaks encapsulation because there is no public getter for |
| 43 |
// propagationStopped_. |
| 44 |
assertFalse('Propagation must not have been stopped', e.propagationStopped_); |
| 45 |
e.stopPropagation(); |
| 46 |
assertTrue('Propagation must have been stopped', e.propagationStopped_); |
| 47 |
} |
| 48 |
|
| 49 |
function testPreventDefault() { |
| 50 |
// This test breaks encapsulation because there is no public getter for |
| 51 |
// returnValue_. |
| 52 |
assertTrue('Return value must be true', e.returnValue_); |
| 53 |
e.preventDefault(); |
| 54 |
assertFalse('Return value must be false', e.returnValue_); |
| 55 |
} |
| 56 |
|
| 57 |
function testDefaultPrevented() { |
| 58 |
assertFalse('Default action must not be prevented', e.defaultPrevented); |
| 59 |
e.preventDefault(); |
| 60 |
assertTrue('Default action must be prevented', e.defaultPrevented); |
| 61 |
} |
| 62 |
|
| 63 |
function testEventId() { |
| 64 |
e = new goog.events.Event(new goog.events.EventId('eventType')); |
| 65 |
assertEquals('Event type must be as expected', 'eventType', e.type); |
| 66 |
} |