Convert cacheinvalidation_unittests to run exclusively on Swarming
[chromium-blink-merge.git] / remoting / webapp / base / js / base_event_hook_unittest.js
blobd8523f70e9b0f2b3a97179faa06019cfbf569ee4
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.
5 (function() {
7 'use strict';
9 /** @type {base.EventSourceImpl} */
10 var eventSource = null;
12 /** @type {HTMLElement} */
13 var domElement = null;
15 /** @type {chromeMocks.Event} */
16 var myChromeEvent = null;
18 /** @type {Listener} */
19 var listener = null;
21 /**
22 * @param {HTMLElement} element
23 * @constructor
25 var Listener = function(element) {
26 /** @type {(sinon.Spy|function(...?))} */
27 this.onChromeEvent = sinon.spy();
28 /** @type {(sinon.Spy|function(...?))} */
29 this.onClickEvent = sinon.spy();
30 /** @type {(sinon.Spy|function(...?))} */
31 this.onCustomEvent = sinon.spy();
33 this.eventHooks_ = new base.Disposables(
34 new base.DomEventHook(element, 'click', this.onClickEvent.bind(this),
35 false),
36 new base.EventHook(eventSource, 'customEvent',
37 this.onCustomEvent.bind(this)),
38 new base.ChromeEventHook(myChromeEvent, this.onChromeEvent.bind(this)));
41 Listener.prototype.dispose = function() {
42 this.eventHooks_.dispose();
45 function raiseAllEvents() {
46 domElement.click();
47 myChromeEvent.mock$fire();
48 eventSource.raiseEvent('customEvent');
51 QUnit.module('base.EventHook', {
52 beforeEach: function() {
53 domElement = /** @type {HTMLElement} */ (document.createElement('div'));
54 eventSource = new base.EventSourceImpl();
55 eventSource.defineEvents(['customEvent']);
56 myChromeEvent = new chromeMocks.Event();
57 listener = new Listener(domElement);
59 afterEach: function() {
60 domElement = null;
61 eventSource = null;
62 myChromeEvent = null;
63 listener = null;
65 });
67 QUnit.test('EventHook should hook events when constructed', function() {
68 raiseAllEvents();
69 sinon.assert.calledOnce(listener.onClickEvent);
70 sinon.assert.calledOnce(listener.onChromeEvent);
71 sinon.assert.calledOnce(listener.onCustomEvent);
72 listener.dispose();
73 });
75 QUnit.test('EventHook should unhook events when disposed', function() {
76 listener.dispose();
77 raiseAllEvents();
78 sinon.assert.notCalled(listener.onClickEvent);
79 sinon.assert.notCalled(listener.onChromeEvent);
80 sinon.assert.notCalled(listener.onCustomEvent);
81 });
83 })();