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

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

Issue 959963002: [Chromoting] Enable jscompile for webapp unittests. (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
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 (function() { 5 (function() {
6 6
7 'use strict'; 7 'use strict';
8 8
9 /** @type {base.Ipc} */
9 var ipc_; 10 var ipc_;
10 11
11 function pass() { 12 function pass() {
12 ok(true); 13 ok(true);
13 QUnit.start(); 14 QUnit.start();
14 } 15 }
15 16
16 function fail() { 17 function fail() {
17 ok(false); 18 ok(false);
18 QUnit.start(); 19 QUnit.start();
19 } 20 }
20 21
21 module('base.Ipc', { 22 module('base.Ipc', {
22 setup: function() { 23 setup: function() {
23 chromeMocks.activate(['runtime']);
24 ipc_ = base.Ipc.getInstance(); 24 ipc_ = base.Ipc.getInstance();
25 }, 25 },
26 teardown: function() { 26 teardown: function() {
27 base.Ipc.deleteInstance(); 27 base.Ipc.deleteInstance();
28 ipc_ = null; 28 ipc_ = null;
29 chromeMocks.restore();
30 } 29 }
31 }); 30 });
32 31
33 QUnit.test( 32 QUnit.test(
34 'register() should return false if the request type was already registered', 33 'register() should return false if the request type was already registered',
35 function() { 34 function() {
35 /** @type {function(...?)} */
36 var handler1 = function() {}; 36 var handler1 = function() {};
37 /** @type {function(...?)} */
37 var handler2 = function() {}; 38 var handler2 = function() {};
38 QUnit.equal(true, ipc_.register('foo', handler1)); 39 QUnit.equal(true, ipc_.register('foo', handler1));
39 QUnit.equal(false, ipc_.register('foo', handler2)); 40 QUnit.equal(false, ipc_.register('foo', handler2));
40 }); 41 });
41 42
42 QUnit.asyncTest( 43 QUnit.asyncTest(
43 'send() should invoke a registered handler with the correct arguments', 44 'send() should invoke a registered handler with the correct arguments',
44 function() { 45 function() {
45 var handler = sinon.spy(); 46 var handler = /** @type {function(...?)} */ (sinon.spy());
kelvinp 2015/02/26 00:31:30 You can simply change the definition ipc.js to be
garykac 2015/02/28 02:33:33 Done.
46 var argArray = [1, 2, 3]; 47 var argArray = [1, 2, 3];
47 var argDict = { 48 var argDict = {
48 key1: 'value1', 49 key1: 'value1',
49 key2: false 50 key2: false
50 }; 51 };
51 52
52 ipc_.register('foo', handler); 53 ipc_.register('foo', handler);
53 base.Ipc.invoke('foo', 1, false, 'string', argArray, argDict).then( 54 base.Ipc.invoke('foo', 1, false, 'string', argArray, argDict).then(
54 function() { 55 function() {
55 sinon.assert.calledWith(handler, 1, false, 'string', argArray, argDict); 56 sinon.assert.calledWith(handler, 1, false, 'string', argArray, argDict);
56 pass(); 57 pass();
57 }, fail); 58 }, fail);
58 }); 59 });
59 60
60 QUnit.asyncTest( 61 QUnit.asyncTest(
61 'send() should not invoke a handler that is unregistered', 62 'send() should not invoke a handler that is unregistered',
62 function() { 63 function() {
63 var handler = sinon.spy(); 64 var handler = /** @type {function(...?)} */ (sinon.spy());
64 ipc_.register('foo', handler); 65 ipc_.register('foo', handler);
65 ipc_.unregister('foo', handler); 66 ipc_.unregister('foo');
66 base.Ipc.invoke('foo', 'hello', 'world').then(fail, function(error) { 67 base.Ipc.invoke('foo', 'hello', 'world').then(fail, function(error) {
67 sinon.assert.notCalled(handler); 68 sinon.assert.notCalled(handler);
68 QUnit.equal(error, base.Ipc.Error.UNSUPPORTED_REQUEST_TYPE); 69 QUnit.equal(error, base.Ipc.Error.UNSUPPORTED_REQUEST_TYPE);
69 pass(); 70 pass();
70 }); 71 });
71 }); 72 });
72 73
73 QUnit.asyncTest( 74 QUnit.asyncTest(
74 'send() should raise exceptions on unknown request types', 75 'send() should raise exceptions on unknown request types',
75 function() { 76 function() {
76 var handler = sinon.spy(); 77 var handler = /** @type {function(...?)} */ (sinon.spy());
77 ipc_.register('foo', handler); 78 ipc_.register('foo', handler);
78 base.Ipc.invoke('bar', 'hello', 'world').then(fail, function(error) { 79 base.Ipc.invoke('bar', 'hello', 'world').then(fail, function(error) {
79 QUnit.equal(error, base.Ipc.Error.UNSUPPORTED_REQUEST_TYPE); 80 QUnit.equal(error, base.Ipc.Error.UNSUPPORTED_REQUEST_TYPE);
80 pass(); 81 pass();
81 }); 82 });
82 }); 83 });
83 84
84 QUnit.asyncTest( 85 QUnit.asyncTest(
85 'send() should raise exceptions on request from another extension', 86 'send() should raise exceptions on request from another extension',
86 function() { 87 function() {
87 var handler = sinon.spy(); 88 var handler = /** @type {function(...?)} */ (sinon.spy());
88 var oldId = chrome.runtime.id; 89 var oldId = chrome.runtime.id;
89 ipc_.register('foo', handler); 90 ipc_.register('foo', handler);
90 chrome.runtime.id = 'foreign-extension'; 91 chrome.runtime.id = 'foreign-extension';
91 base.Ipc.invoke('foo', 'hello', 'world').then(fail, function(error) { 92 base.Ipc.invoke('foo', 'hello', 'world').then(fail, function(error) {
92 QUnit.equal(error, base.Ipc.Error.INVALID_REQUEST_ORIGIN); 93 QUnit.equal(error, base.Ipc.Error.INVALID_REQUEST_ORIGIN);
93 pass(); 94 pass();
94 }); 95 });
95 chrome.runtime.id = oldId; 96 chrome.runtime.id = oldId;
96 }); 97 });
97 98
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 QUnit.equal(results[0], false); 131 QUnit.equal(results[0], false);
131 QUnit.equal(results[1], 12); 132 QUnit.equal(results[1], 12);
132 QUnit.equal(results[2], 'string'); 133 QUnit.equal(results[2], 'string');
133 QUnit.deepEqual(results[3], [1,2]); 134 QUnit.deepEqual(results[3], [1,2]);
134 QUnit.deepEqual(results[4], {key1: 'value1', key2: 'value2'}); 135 QUnit.deepEqual(results[4], {key1: 'value1', key2: 'value2'});
135 pass(); 136 pass();
136 }, fail); 137 }, fail);
137 }); 138 });
138 139
139 })(); 140 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698