eventtarget_test.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2006 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.EventTargetTest');
  15. goog.setTestOnly('goog.events.EventTargetTest');
  16. goog.require('goog.events.EventTarget');
  17. goog.require('goog.events.Listenable');
  18. goog.require('goog.events.eventTargetTester');
  19. goog.require('goog.events.eventTargetTester.KeyType');
  20. goog.require('goog.events.eventTargetTester.UnlistenReturnType');
  21. goog.require('goog.testing.jsunit');
  22. function setUp() {
  23. var newListenableFn = function() { return new goog.events.EventTarget(); };
  24. var listenFn = function(src, type, listener, opt_capt, opt_handler) {
  25. return src.listen(type, listener, opt_capt, opt_handler);
  26. };
  27. var unlistenFn = function(src, type, listener, opt_capt, opt_handler) {
  28. return src.unlisten(type, listener, opt_capt, opt_handler);
  29. };
  30. var unlistenByKeyFn = function(src, key) { return src.unlistenByKey(key); };
  31. var listenOnceFn = function(src, type, listener, opt_capt, opt_handler) {
  32. return src.listenOnce(type, listener, opt_capt, opt_handler);
  33. };
  34. var dispatchEventFn = function(src, e) { return src.dispatchEvent(e); };
  35. var removeAllFn = function(src, opt_type, opt_capture) {
  36. return src.removeAllListeners(opt_type, opt_capture);
  37. };
  38. var getListenersFn = function(src, type, capture) {
  39. return src.getListeners(type, capture);
  40. };
  41. var getListenerFn = function(src, type, listener, capture, opt_handler) {
  42. return src.getListener(type, listener, capture, opt_handler);
  43. };
  44. var hasListenerFn = function(src, opt_type, opt_capture) {
  45. return src.hasListener(opt_type, opt_capture);
  46. };
  47. goog.events.eventTargetTester.setUp(
  48. newListenableFn, listenFn, unlistenFn, unlistenByKeyFn, listenOnceFn,
  49. dispatchEventFn, removeAllFn, getListenersFn, getListenerFn,
  50. hasListenerFn, goog.events.eventTargetTester.KeyType.NUMBER,
  51. goog.events.eventTargetTester.UnlistenReturnType.BOOLEAN, false);
  52. }
  53. function tearDown() {
  54. goog.events.eventTargetTester.tearDown();
  55. }
  56. function testRuntimeTypeIsCorrect() {
  57. var target = new goog.events.EventTarget();
  58. assertTrue(goog.events.Listenable.isImplementedBy(target));
  59. }