Chromium Code Reviews| Index: chrome/test/data/webui/webui_resource_async_browsertest.js |
| diff --git a/chrome/test/data/webui/webui_resource_async_browsertest.js b/chrome/test/data/webui/webui_resource_async_browsertest.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0a25be4cddc1359526e9a81f9f88d0e8cafd3275 |
| --- /dev/null |
| +++ b/chrome/test/data/webui/webui_resource_async_browsertest.js |
| @@ -0,0 +1,83 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @fileoverview Framework for running async JS tests for cr.js utility methods. |
| + */ |
| + |
| +/** @const {string} Path to source root. */ |
| +var ROOT_PATH = '../../../../'; |
| + |
| +/** |
| + * Test fixture for testing async methods of cr.js. |
| + * @constructor |
| + * @extends testing.Test |
| + */ |
| +function WebUIResourceAsyncTest() {} |
| + |
| +WebUIResourceAsyncTest.prototype = { |
| + __proto__: testing.Test.prototype, |
| + |
| + /** @override */ |
| + browsePreload: DUMMY_URL, |
|
Dan Beam
2016/01/23 02:48:51
where does this magic come from?
dpapad
2016/01/25 18:34:22
https://code.google.com/p/chromium/codesearch#chro
|
| + |
| + /** @override */ |
| + isAsync: true, |
| + |
| + /** @override */ |
| + runAccessibilityChecks: false, |
| + |
| + /** @override */ |
| + extraLibraries: [ |
| + ROOT_PATH + 'third_party/mocha/mocha.js', |
| + ROOT_PATH + 'chrome/test/data/webui/mocha_adapter.js', |
| + ROOT_PATH + 'ui/webui/resources/js/cr.js', |
| + ], |
| +}; |
| + |
| +TEST_F('WebUIResourceAsyncTest', 'SendWithPromise', function() { |
| + var expectedChromeSendMessageName = 'echoMessage'; |
| + |
| + /** |
| + * TODO(dpapad): Move this helper method in test_api.js. |
| + * @param {string} name chrome.send message name. |
| + * @return {!Promise} Fires when chrome.send is called with the given message |
| + * name. |
| + */ |
| + function whenChromeSendCalled(name) { |
| + return new Promise(function(resolve, reject) { |
| + registerMessageCallback(name, null, resolve); |
| + }); |
| + } |
| + |
| + suite('cr.js', function() { |
| + setup(function() { |
| + // Simulate a WebUI handler that echoes back all parameters passed to it. |
| + whenChromeSendCalled(expectedChromeSendMessageName).then( |
| + function(args) { |
| + assertEquals('cr.webUIResponse', args[0]); |
| + var globalCallbackArgs = args.slice(1); |
| + window['cr']['webUIResponse'].apply(null, globalCallbackArgs); |
|
Dan Beam
2016/01/23 02:48:51
why can't this just be cr.webUIResponse.apply(cr,
dpapad
2016/01/25 18:34:22
Done.
|
| + }); |
| + }); |
| + |
| + test('sendWithPromise_MultipleArgs', function() { |
| + return cr.sendWithPromise( |
| + expectedChromeSendMessageName, 'foo', 'bar').then( |
| + function(response) { |
| + assertEquals(['foo', 'bar'].join(), response.join()); |
| + }); |
| + }); |
| + |
| + test('sendWithPromise_NoArgs', function() { |
| + return cr.sendWithPromise(expectedChromeSendMessageName).then( |
| + function(response) { |
| + assertEquals(undefined, response); |
| + }); |
| + }); |
| + }); |
| + |
| + // Run all registered tests. |
| + mocha.run(); |
| +}); |