Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: remoting/webapp/unittests/event_hook_unittest.js

Issue 959963002: [Chromoting] Enable jscompile for webapp unittests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix key tester Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /**
6 * @fileoverview
7 * TODO(garykac) Remove suppression once chromeMocks has been replaced.
8 * @suppress {checkTypes|checkVars|reportUnknownTypes}
9 */
10
5 (function() { 11 (function() {
6 12
7 'use strict'; 13 'use strict';
8 14
15 /** @type {base.EventSourceImpl} */
9 var eventSource = null; 16 var eventSource = null;
17
18 /** @type {HTMLElement} */
10 var domElement = null; 19 var domElement = null;
20
21 /** @type {chromeMocks.Event} */
11 var myChromeEvent = null; 22 var myChromeEvent = null;
23
24 /** @type {Listener} */
12 var listener = null; 25 var listener = null;
13 26
27 /**
28 * @param {HTMLElement} element
29 * @constructor
30 */
14 var Listener = function(element) { 31 var Listener = function(element) {
15 this.onChromeEvent = sinon.stub(); 32 /** @type {(sinon.Spy|function(...?))} */
16 this.onClickEvent = sinon.stub(); 33 this.onChromeEvent = sinon.spy();
17 this.onCustomEvent = sinon.stub(); 34 /** @type {(sinon.Spy|function(...?))} */
35 this.onClickEvent = sinon.spy();
36 /** @type {(sinon.Spy|function(...?))} */
37 this.onCustomEvent = sinon.spy();
38
18 this.eventHooks_ = new base.Disposables( 39 this.eventHooks_ = new base.Disposables(
19 new base.DomEventHook(element, 'click', this.onClickEvent.bind(this), 40 new base.DomEventHook(element, 'click', this.onClickEvent.bind(this),
20 false), 41 false),
21 new base.EventHook(eventSource, 'customEvent', 42 new base.EventHook(eventSource, 'customEvent',
22 this.onCustomEvent.bind(this)), 43 this.onCustomEvent.bind(this)),
23 new base.ChromeEventHook(myChromeEvent, this.onChromeEvent.bind(this))); 44 new base.ChromeEventHook(myChromeEvent, this.onChromeEvent.bind(this)));
24 }; 45 };
25 46
26 Listener.prototype.dispose = function() { 47 Listener.prototype.dispose = function() {
27 this.eventHooks_.dispose(); 48 this.eventHooks_.dispose();
28 }; 49 };
29 50
30 function raiseAllEvents() { 51 function raiseAllEvents() {
31 domElement.click(); 52 domElement.click();
32 myChromeEvent.mock$fire(); 53 myChromeEvent.mock$fire();
33 eventSource.raiseEvent('customEvent'); 54 eventSource.raiseEvent('customEvent');
34 } 55 }
35 56
36 module('base.EventHook', { 57 module('base.EventHook', {
37 setup: function() { 58 setup: function() {
38 domElement = document.createElement('div'); 59 domElement = /** @type {HTMLElement} */ (document.createElement('div'));
39 eventSource = new base.EventSourceImpl(); 60 eventSource = new base.EventSourceImpl();
40 eventSource.defineEvents(['customEvent']); 61 eventSource.defineEvents(['customEvent']);
41 myChromeEvent = new chromeMocks.Event(); 62 myChromeEvent = new chromeMocks.Event();
42 listener = new Listener(domElement); 63 listener = new Listener(domElement);
43 }, 64 },
44 tearDown: function() { 65 tearDown: function() {
45 domElement = null; 66 domElement = null;
46 eventSource = null; 67 eventSource = null;
47 myChromeEvent = null; 68 myChromeEvent = null;
48 listener = null; 69 listener = null;
(...skipping 10 matching lines...) Expand all
59 80
60 test('EventHook should unhook events when disposed', function() { 81 test('EventHook should unhook events when disposed', function() {
61 listener.dispose(); 82 listener.dispose();
62 raiseAllEvents(); 83 raiseAllEvents();
63 sinon.assert.notCalled(listener.onClickEvent); 84 sinon.assert.notCalled(listener.onClickEvent);
64 sinon.assert.notCalled(listener.onChromeEvent); 85 sinon.assert.notCalled(listener.onChromeEvent);
65 sinon.assert.notCalled(listener.onCustomEvent); 86 sinon.assert.notCalled(listener.onCustomEvent);
66 }); 87 });
67 88
68 })(); 89 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698