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

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

Issue 403663002: Fix base_unittest.js (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « remoting/webapp/unittests/base_unittest.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 source = null;
10 var listener = null;
11
12 module('base.EventSource.raiseEvent', {
13 setup: function() {
14 source = new base.EventSource();
15 source.defineEvents(['foo', 'bar']);
16 listener = sinon.spy();
17 source.addEventListener('foo', listener);
18 },
19 teardown: function() {
20 source = null;
21 listener = null;
22 }
23 });
24
25 test('should invoke the listener', function() {
26 source.raiseEvent('foo');
27 sinon.assert.called(listener);
28 });
29
30 test('should invoke the listener with the correct event data', function() {
31 var data = {
32 field: 'foo'
33 };
34 source.raiseEvent('foo', data);
35 sinon.assert.calledWith(listener, data);
36 });
37
38 test('should not invoke listeners that are added during raiseEvent',
39 function() {
40 source.addEventListener('foo', function() {
41 source.addEventListener('foo', function() {
42 ok(false);
43 });
44 ok(true);
45 });
46 source.raiseEvent('foo');
47 });
48
49 test('should not invoke listeners of a different event',
50 function() {
51 source.raiseEvent('bar');
52 sinon.assert.notCalled(listener);
53 });
54
55 test('should assert when undeclared events are raised', function() {
56 sinon.spy(base.debug, 'assert');
57 try {
58 source.raiseEvent('undefined');
59 } catch (e){
60 } finally{
61 sinon.assert.called(base.debug.assert);
62 base.debug.assert.restore();
63 }
64 });
65
66 module('base.EventSource.removeEventListener', {
67 setup: function() {
68 source = new base.EventSource();
69 source.defineEvents(['foo', 'bar']);
70 },
71 teardown: function() {
72 source = null;
73 listener = null;
74 }
75 });
76
77 test('should not invoke the listener in subsequent calls to |raiseEvent|',
78 function() {
79 listener = sinon.spy();
80 source.addEventListener('foo', listener);
81
82 source.raiseEvent('foo');
83 sinon.assert.calledOnce(listener);
84
85 source.removeEventListener('foo', listener);
86 source.raiseEvent('foo');
87 sinon.assert.calledOnce(listener);
88 });
89
90 test('should work even if the listener is removed during |raiseEvent|',
91 function() {
92 var sink = {};
93 sink.listener = sinon.spy(function() {
94 source.removeEventListener('foo', sink.listener);
95 });
96
97 source.addEventListener('foo', sink.listener);
98 source.raiseEvent('foo');
99 sinon.assert.calledOnce(sink.listener);
100
101 source.raiseEvent('foo');
102 sinon.assert.calledOnce(sink.listener);
103 });
104
105 })();
OLDNEW
« no previous file with comments | « remoting/webapp/unittests/base_unittest.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698