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

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

Issue 2671103002: Implement host settings migration. (Closed)
Patch Set: Created 3 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/ipc.js ('k') | remoting/webapp/crd/js/background.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /** @type {base.Ipc} */
10 var ipc_; 10 var ipc_;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 QUnit.test( 74 QUnit.test(
75 'send() should raise exceptions on request from another extension', 75 'send() should raise exceptions on request from another extension',
76 function(assert) { 76 function(assert) {
77 var handler = sinon.spy(); 77 var handler = sinon.spy();
78 var oldId = chrome.runtime.id; 78 var oldId = chrome.runtime.id;
79 ipc_.register('foo', handler); 79 ipc_.register('foo', handler);
80 chrome.runtime.id = 'foreign-extension'; 80 chrome.runtime.id = 'foreign-extension';
81 var promise = base.Ipc.invoke('foo', 'hello', 'world').then(function() { 81 var promise = base.Ipc.invoke('foo', 'hello', 'world').then(function() {
82 assert.ok(false, 'Requests from another extension should fail.'); 82 assert.ok(false, 'Requests from another extension should fail.');
83 }).catch(function(error) { 83 }).catch(function(error) {
84 assert.equal(error, base.Ipc.Error.INVALID_REQUEST_ORIGIN); 84 assert.equal(error, base.Ipc.Error.UNAUTHORIZED_REQUEST_ORIGIN);
85 }); 85 });
86 chrome.runtime.id = oldId; 86 chrome.runtime.id = oldId;
87 return promise; 87 return promise;
88 }); 88 });
89 89
90 QUnit.test(
91 'send() should not raise exceptions for externally-accessible methods',
92 function(assert) {
93 var handler = function(request) { return request; };
94 var oldId = chrome.runtime.id;
95 ipc_.register('foo', handler, true);
96 chrome.runtime.id = 'foreign-extension';
97 var promise = base.Ipc.invoke('foo', 'payload').then(function(response) {
98 assert.equal(response, 'payload');
99 });
100 chrome.runtime.id = oldId;
101 return promise;
102 });
90 103
91 QUnit.test( 104 QUnit.test(
92 'send() should pass exceptions raised by the handler to the caller', 105 'send() should pass exceptions raised by the handler to the caller',
93 function(assert) { 106 function(assert) {
94 var handler = function() { 107 var handler = function() {
95 throw new Error('Whatever can go wrong, will go wrong.'); 108 throw new Error('Whatever can go wrong, will go wrong.');
96 }; 109 };
97 ipc_.register('foo', handler); 110 ipc_.register('foo', handler);
98 return base.Ipc.invoke('foo').then(function() { 111 return base.Ipc.invoke('foo').then(function() {
99 assert.ok(false, 'Exceptions expected.'); 112 assert.ok(false, 'Exceptions expected.');
(...skipping 21 matching lines...) Expand all
121 134
122 return Promise.all(testCases).then(function(results){ 135 return Promise.all(testCases).then(function(results){
123 assert.equal(results[0], false); 136 assert.equal(results[0], false);
124 assert.equal(results[1], 12); 137 assert.equal(results[1], 12);
125 assert.equal(results[2], 'string'); 138 assert.equal(results[2], 'string');
126 assert.deepEqual(results[3], [1,2]); 139 assert.deepEqual(results[3], [1,2]);
127 assert.deepEqual(results[4], {key1: 'value1', key2: 'value2'}); 140 assert.deepEqual(results[4], {key1: 'value1', key2: 'value2'});
128 }); 141 });
129 }); 142 });
130 143
144 QUnit.test(
145 'send() supports asynchronous handlers',
146 function(assert) {
147 var success = function() {
148 return new Promise(function(resolve) { resolve('result'); });
149 };
150 var failure = function() {
151 return new Promise(function() {
152 throw new Error('Whatever can go wrong, will go wrong.');
153 });
154 };
155 ipc_.register('foo', success);
156 ipc_.register('bar', failure);
157 var testCases = [];
158 testCases.push(base.Ipc.invoke('foo').then(function(response) {
159 assert.equal(response, 'result');
160 }));
161 testCases.push(base.Ipc.invoke('bar').then(function() {
162 assert.ok(false, 'bar method expected to fail.');
163 }).catch(function(error) {
164 assert.equal(error, 'Whatever can go wrong, will go wrong.');
165 }))
166 return Promise.all(testCases);
167 });
168
131 })(); 169 })();
OLDNEW
« no previous file with comments | « remoting/webapp/base/js/ipc.js ('k') | remoting/webapp/crd/js/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698