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

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

Issue 984203003: Move mocks and unittest JS files to sit alongside production code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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
(Empty)
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.
4
5 /**
6 * @fileoverview
7 * TODO(garykac) Remove suppression once chromeMocks has been replaced.
8 * @suppress {checkTypes|checkVars|reportUnknownTypes}
9 */
10
11 (function() {
12
13 'use strict';
14
15 /** @type {base.EventSourceImpl} */
16 var eventSource = null;
17
18 /** @type {HTMLElement} */
19 var domElement = null;
20
21 /** @type {chromeMocks.Event} */
22 var myChromeEvent = null;
23
24 /** @type {Listener} */
25 var listener = null;
26
27 /**
28 * @param {HTMLElement} element
29 * @constructor
30 */
31 var Listener = function(element) {
32 /** @type {(sinon.Spy|function(...?))} */
33 this.onChromeEvent = sinon.spy();
34 /** @type {(sinon.Spy|function(...?))} */
35 this.onClickEvent = sinon.spy();
36 /** @type {(sinon.Spy|function(...?))} */
37 this.onCustomEvent = sinon.spy();
38
39 this.eventHooks_ = new base.Disposables(
40 new base.DomEventHook(element, 'click', this.onClickEvent.bind(this),
41 false),
42 new base.EventHook(eventSource, 'customEvent',
43 this.onCustomEvent.bind(this)),
44 new base.ChromeEventHook(myChromeEvent, this.onChromeEvent.bind(this)));
45 };
46
47 Listener.prototype.dispose = function() {
48 this.eventHooks_.dispose();
49 };
50
51 function raiseAllEvents() {
52 domElement.click();
53 myChromeEvent.mock$fire();
54 eventSource.raiseEvent('customEvent');
55 }
56
57 module('base.EventHook', {
58 setup: function() {
59 domElement = /** @type {HTMLElement} */ (document.createElement('div'));
60 eventSource = new base.EventSourceImpl();
61 eventSource.defineEvents(['customEvent']);
62 myChromeEvent = new chromeMocks.Event();
63 listener = new Listener(domElement);
64 },
65 tearDown: function() {
66 domElement = null;
67 eventSource = null;
68 myChromeEvent = null;
69 listener = null;
70 }
71 });
72
73 test('EventHook should hook events when constructed', function() {
74 raiseAllEvents();
75 sinon.assert.calledOnce(listener.onClickEvent);
76 sinon.assert.calledOnce(listener.onChromeEvent);
77 sinon.assert.calledOnce(listener.onCustomEvent);
78 listener.dispose();
79 });
80
81 test('EventHook should unhook events when disposed', function() {
82 listener.dispose();
83 raiseAllEvents();
84 sinon.assert.notCalled(listener.onClickEvent);
85 sinon.assert.notCalled(listener.onChromeEvent);
86 sinon.assert.notCalled(listener.onCustomEvent);
87 });
88
89 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698