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

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

Issue 863863003: base.EventHook (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 (function() {
6
7 'use strict';
8
9 var eventSource = null;
10 var domElement = null;
11 var myChromeEvent = null;
12 var listener = null;
13
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.EventHook(element, 'click', this.onClickEvent.bind(this), false),
20 new base.EventHook(eventSource, 'customEvent',
21 this.onCustomEvent.bind(this)),
22 new base.ChromeEventHook(myChromeEvent, this.onChromeEvent.bind(this)));
23 };
24
25 Listener.prototype.dispose = function() {
26 this.eventHooks_.dispose();
27 };
28
29 function raiseAllEvents() {
30 domElement.click();
31 myChromeEvent.mock$fire();
32 eventSource.raiseEvent('customEvent');
33 }
34
35 module('base.EventHook', {
36 setup: function() {
37 domElement = document.createElement('div');
38 eventSource = new base.EventSource();
39 eventSource.defineEvents(['customEvent']);
40 myChromeEvent = new chromeMocks.Event();
41 listener = new Listener(domElement);
42 },
43 tearDown: function() {
44 domElement = null;
45 eventSource = null;
46 myChromeEvent = null;
47 listener = null;
48 }
49 });
50
51 test('EventHook should hook events when constructed', function() {
52 raiseAllEvents();
53 sinon.assert.calledOnce(listener.onClickEvent);
54 sinon.assert.calledOnce(listener.onChromeEvent);
55 sinon.assert.calledOnce(listener.onCustomEvent);
56 listener.dispose();
57 });
58
59 test('EventHook should unhook events when disposed', function() {
60 listener.dispose();
61 raiseAllEvents();
62 sinon.assert.notCalled(listener.onClickEvent);
63 sinon.assert.notCalled(listener.onChromeEvent);
64 sinon.assert.notCalled(listener.onCustomEvent);
65 });
66
67 })();
OLDNEW
« remoting/webapp/base/js/base.js ('K') | « remoting/webapp/base/js/base.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698