event_test.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. goog.provide('goog.events.EventTest');
  15. goog.setTestOnly('goog.events.EventTest');
  16. goog.require('goog.events.Event');
  17. goog.require('goog.events.EventId');
  18. goog.require('goog.events.EventTarget');
  19. goog.require('goog.testing.jsunit');
  20. var e, target;
  21. function setUp() {
  22. target = new goog.events.EventTarget();
  23. e = new goog.events.Event('eventType', target);
  24. }
  25. function tearDown() {
  26. target.dispose();
  27. }
  28. function testConstructor() {
  29. assertNotNull('Event must not be null', e);
  30. assertEquals('Event type must be as expected', 'eventType', e.type);
  31. assertEquals('Event target must be as expected', target, e.target);
  32. assertEquals('Current target must be as expected', target, e.currentTarget);
  33. }
  34. function testStopPropagation() {
  35. // This test breaks encapsulation because there is no public getter for
  36. // propagationStopped_.
  37. assertFalse('Propagation must not have been stopped', e.propagationStopped_);
  38. e.stopPropagation();
  39. assertTrue('Propagation must have been stopped', e.propagationStopped_);
  40. }
  41. function testPreventDefault() {
  42. // This test breaks encapsulation because there is no public getter for
  43. // returnValue_.
  44. assertTrue('Return value must be true', e.returnValue_);
  45. e.preventDefault();
  46. assertFalse('Return value must be false', e.returnValue_);
  47. }
  48. function testDefaultPrevented() {
  49. assertFalse('Default action must not be prevented', e.defaultPrevented);
  50. e.preventDefault();
  51. assertTrue('Default action must be prevented', e.defaultPrevented);
  52. }
  53. function testEventId() {
  54. e = new goog.events.Event(new goog.events.EventId('eventType'));
  55. assertEquals('Event type must be as expected', 'eventType', e.type);
  56. }