| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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 Framework for running async JS tests for cr.js utility methods. | 6 * @fileoverview Framework for running async JS tests for cr.js utility methods. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 /** @const {string} Path to source root. */ | 9 /** @const {string} Path to source root. */ |
| 10 var ROOT_PATH = '../../../../'; | 10 var ROOT_PATH = '../../../../'; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 function whenChromeSendCalled(name) { | 49 function whenChromeSendCalled(name) { |
| 50 return new Promise(function(resolve, reject) { | 50 return new Promise(function(resolve, reject) { |
| 51 registerMessageCallback(name, null, resolve); | 51 registerMessageCallback(name, null, resolve); |
| 52 }); | 52 }); |
| 53 } | 53 } |
| 54 | 54 |
| 55 suite('cr.js', function() { | 55 suite('cr.js', function() { |
| 56 setup(function() { | 56 setup(function() { |
| 57 // Simulate a WebUI handler that echoes back all parameters passed to it. | 57 // Simulate a WebUI handler that echoes back all parameters passed to it. |
| 58 whenChromeSendCalled(CHROME_SEND_NAME).then(function(args) { | 58 whenChromeSendCalled(CHROME_SEND_NAME).then(function(args) { |
| 59 assertEquals('cr.webUIResponse', args[0]); | 59 cr.webUIResponse.apply(null, args); |
| 60 var globalCallbackArgs = args.slice(1); | |
| 61 cr.webUIResponse.apply(null, globalCallbackArgs); | |
| 62 }); | 60 }); |
| 63 }); | 61 }); |
| 64 | 62 |
| 65 test('sendWithPromise_MultipleArgs', function() { | 63 test('sendWithPromise_ResponseObject', function() { |
| 66 return cr.sendWithPromise(CHROME_SEND_NAME, 'foo', 'bar').then( | 64 var expectedResponse = {'foo': 'bar'}; |
| 65 return cr.sendWithPromise(CHROME_SEND_NAME, expectedResponse).then( |
| 67 function(response) { | 66 function(response) { |
| 68 assertEquals(['foo', 'bar'].join(), response.join()); | 67 assertEquals( |
| 68 JSON.stringify(expectedResponse), JSON.stringify(response)); |
| 69 }); | 69 }); |
| 70 }); | 70 }); |
| 71 | 71 |
| 72 test('sendWithPromise_NoArgs', function() { | 72 test('sendWithPromise_ResponseArray', function() { |
| 73 var expectedResponse = ['foo', 'bar']; |
| 74 return cr.sendWithPromise(CHROME_SEND_NAME, expectedResponse).then( |
| 75 function(response) { |
| 76 assertEquals( |
| 77 JSON.stringify(expectedResponse), JSON.stringify(response)); |
| 78 }); |
| 79 }); |
| 80 |
| 81 test('sendWithPromise_ResponsePrimitive', function() { |
| 82 var expectedResponse = 1234; |
| 83 return cr.sendWithPromise(CHROME_SEND_NAME, expectedResponse).then( |
| 84 function(response) { |
| 85 assertEquals(expectedResponse, response); |
| 86 }); |
| 87 }); |
| 88 |
| 89 test('sendWithPromise_ResponseVoid', function() { |
| 73 return cr.sendWithPromise(CHROME_SEND_NAME).then(function(response) { | 90 return cr.sendWithPromise(CHROME_SEND_NAME).then(function(response) { |
| 74 assertEquals([].join(), response.join()); | 91 assertEquals(undefined, response); |
| 75 }); | 92 }); |
| 76 }); | 93 }); |
| 77 }); | 94 }); |
| 78 | 95 |
| 79 // Run all registered tests. | 96 // Run all registered tests. |
| 80 mocha.run(); | 97 mocha.run(); |
| 81 }); | 98 }); |
| OLD | NEW |