1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
9 var eventSource = null;
10 var domElement = null;
11 var myChromeEvent = null;
14 var Listener = function(element) {
15 this.onChromeEvent = sinon.stub();
16 this.onClickEvent = sinon.stub();
17 this.onCustomEvent = sinon.stub();
18 this.eventHooks_ = new base.Disposables(
19 new base.DomEventHook(element, 'click', this.onClickEvent.bind(this),
21 new base.EventHook(eventSource, 'customEvent',
22 this.onCustomEvent.bind(this)),
23 new base.ChromeEventHook(myChromeEvent, this.onChromeEvent.bind(this)));
26 Listener.prototype.dispose = function() {
27 this.eventHooks_.dispose();
30 function raiseAllEvents() {
32 myChromeEvent.mock$fire();
33 eventSource.raiseEvent('customEvent');
36 module('base.EventHook', {
38 domElement = document.createElement('div');
39 eventSource = new base.EventSourceImpl();
40 eventSource.defineEvents(['customEvent']);
41 myChromeEvent = new chromeMocks.Event();
42 listener = new Listener(domElement);
44 tearDown: function() {
52 test('EventHook should hook events when constructed', function() {
54 sinon.assert.calledOnce(listener.onClickEvent);
55 sinon.assert.calledOnce(listener.onChromeEvent);
56 sinon.assert.calledOnce(listener.onCustomEvent);
60 test('EventHook should unhook events when disposed', function() {
63 sinon.assert.notCalled(listener.onClickEvent);
64 sinon.assert.notCalled(listener.onChromeEvent);
65 sinon.assert.notCalled(listener.onCustomEvent);