| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 /** | 5 /** |
| 6 * @fileoverview A mock version of remoting.Xhr. Compared to | 6 * @fileoverview A mock version of remoting.Xhr. Compared to |
| 7 * sinon.useMockXhr, this allows unit tests to be written at a higher | 7 * sinon.useMockXhr, this allows unit tests to be written at a higher |
| 8 * level, and it eliminates a fair amount of boilerplate involved in | 8 * level, and it eliminates a fair amount of boilerplate involved in |
| 9 * making the sinon mocks work with asynchronous calls | 9 * making the sinon mocks work with asynchronous calls |
| 10 * (cf. gcd_client_unittest.js vs. gcd_client_with_mock_xhr.js for an | 10 * (cf. gcd_client_unittest.js vs. gcd_client_with_mock_xhr.js for an |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 method, urlPattern, callback, opt_reuse) { | 183 method, urlPattern, callback, opt_reuse) { |
| 184 handlers.push({ | 184 handlers.push({ |
| 185 method: method, | 185 method: method, |
| 186 urlPattern: urlPattern, | 186 urlPattern: urlPattern, |
| 187 callback: callback, | 187 callback: callback, |
| 188 reuse: !!opt_reuse | 188 reuse: !!opt_reuse |
| 189 }); | 189 }); |
| 190 }; | 190 }; |
| 191 | 191 |
| 192 /** | 192 /** |
| 193 * Installs a 204 (no content) response. See |setResponseFor| for | 193 * Installs an emptresponse. See |setResponseFor| for |
| 194 * more details on how the parameters work. | 194 * more details on how the parameters work. |
| 195 * | 195 * |
| 196 * @param {?string} method | 196 * @param {?string} method |
| 197 * @param {?string|!RegExp} urlPattern | 197 * @param {?string|!RegExp} urlPattern |
| 198 * @param {number=} opt_status |
| 198 * @param {boolean=} opt_reuse | 199 * @param {boolean=} opt_reuse |
| 199 */ | 200 */ |
| 200 remoting.MockXhr.setEmptyResponseFor = function(method, urlPattern, opt_reuse) { | 201 remoting.MockXhr.setEmptyResponseFor = function( |
| 202 method, urlPattern, opt_status, opt_reuse) { |
| 201 remoting.MockXhr.setResponseFor( | 203 remoting.MockXhr.setResponseFor( |
| 202 method, urlPattern, function(/** remoting.MockXhr */ xhr) { | 204 method, urlPattern, function(/** remoting.MockXhr */ xhr) { |
| 203 xhr.setEmptyResponse(204); | 205 xhr.setEmptyResponse(opt_status === undefined ? 204 : opt_status); |
| 204 }, opt_reuse); | 206 }, opt_reuse); |
| 205 }; | 207 }; |
| 206 | 208 |
| 207 /** | 209 /** |
| 208 * Installs a 200 response with text content. See |setResponseFor| | 210 * Installs a 200 response with text content. See |setResponseFor| |
| 209 * for more details on how the parameters work. | 211 * for more details on how the parameters work. |
| 210 * | 212 * |
| 211 * @param {?string} method | 213 * @param {?string} method |
| 212 * @param {?string|!RegExp} urlPattern | 214 * @param {?string|!RegExp} urlPattern |
| 213 * @param {string} content | 215 * @param {string} content |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 // Can't put put typedefs inside a function :-( | 302 // Can't put put typedefs inside a function :-( |
| 301 /** | 303 /** |
| 302 * @typedef {{ | 304 * @typedef {{ |
| 303 * method:?string, | 305 * method:?string, |
| 304 * urlPattern:(?string|RegExp), | 306 * urlPattern:(?string|RegExp), |
| 305 * callback:function(!remoting.MockXhr):void, | 307 * callback:function(!remoting.MockXhr):void, |
| 306 * reuse:boolean | 308 * reuse:boolean |
| 307 * }} | 309 * }} |
| 308 */ | 310 */ |
| 309 remoting.MockXhr.UrlHandler; | 311 remoting.MockXhr.UrlHandler; |
| OLD | NEW |