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

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: Reviewer's feedback 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
« no previous file with comments | « remoting/webapp/base/js/base.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.DomEventHook(element, 'click', this.onClickEvent.bind(this),
20 false),
21 new base.EventHook(eventSource, 'customEvent',
22 this.onCustomEvent.bind(this)),
23 new base.ChromeEventHook(myChromeEvent, this.onChromeEvent.bind(this)));
24 };
25
26 Listener.prototype.dispose = function() {
27 this.eventHooks_.dispose();
28 };
29
30 function raiseAllEvents() {
31 domElement.click();
32 myChromeEvent.mock$fire();
33 eventSource.raiseEvent('customEvent');
34 }
35
36 module('base.EventHook', {
37 setup: function() {
38 domElement = document.createElement('div');
39 eventSource = new base.EventSource();
40 eventSource.defineEvents(['customEvent']);
41 myChromeEvent = new chromeMocks.Event();
42 listener = new Listener(domElement);
43 },
44 tearDown: function() {
45 domElement = null;
46 eventSource = null;
47 myChromeEvent = null;
48 listener = null;
49 }
50 });
51
52 test('EventHook should hook events when constructed', function() {
53 raiseAllEvents();
54 sinon.assert.calledOnce(listener.onClickEvent);
55 sinon.assert.calledOnce(listener.onChromeEvent);
56 sinon.assert.calledOnce(listener.onCustomEvent);
57 listener.dispose();
58 });
59
60 test('EventHook should unhook events when disposed', function() {
61 listener.dispose();
62 raiseAllEvents();
63 sinon.assert.notCalled(listener.onClickEvent);
64 sinon.assert.notCalled(listener.onChromeEvent);
65 sinon.assert.notCalled(listener.onCustomEvent);
66 });
67
68 })();
OLDNEW
« no previous file with comments | « remoting/webapp/base/js/base.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698