nondisposableeventtarget_test.js 2.8 KB

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