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

Side by Side Diff: chrome/test/data/webui/webui_resource_async_browsertest.js

Issue 1622663002: WebUI: Replace cr.sendWithCallback with cr.sendWithPromise. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments: Removing new line before anonymous function. Created 4 years, 11 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
(Empty)
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
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview Framework for running async JS tests for cr.js utility methods.
7 */
8
9 /** @const {string} Path to source root. */
10 var ROOT_PATH = '../../../../';
11
12 /** @const {string} Name of the chrome.send() message to be used in tests. */
13 var CHROME_SEND_NAME = 'echoMessage';
14
15 /**
16 * Test fixture for testing async methods of cr.js.
17 * @constructor
18 * @extends testing.Test
19 */
20 function WebUIResourceAsyncTest() {}
21
22 WebUIResourceAsyncTest.prototype = {
23 __proto__: testing.Test.prototype,
24
25 /** @override */
26 browsePreload: DUMMY_URL,
27
28 /** @override */
29 isAsync: true,
30
31 /** @override */
32 runAccessibilityChecks: false,
33
34 /** @override */
35 extraLibraries: [
36 ROOT_PATH + 'third_party/mocha/mocha.js',
37 ROOT_PATH + 'chrome/test/data/webui/mocha_adapter.js',
38 ROOT_PATH + 'ui/webui/resources/js/cr.js',
39 ],
40 };
41
42 TEST_F('WebUIResourceAsyncTest', 'SendWithPromise', function() {
43 /**
44 * TODO(dpapad): Move this helper method in test_api.js.
45 * @param {string} name chrome.send message name.
46 * @return {!Promise} Fires when chrome.send is called with the given message
47 * name.
48 */
49 function whenChromeSendCalled(name) {
50 return new Promise(function(resolve, reject) {
51 registerMessageCallback(name, null, resolve);
52 });
53 }
54
55 suite('cr.js', function() {
56 setup(function() {
57 // Simulate a WebUI handler that echoes back all parameters passed to it.
58 whenChromeSendCalled(CHROME_SEND_NAME).then(function(args) {
59 assertEquals('cr.webUIResponse', args[0]);
60 var globalCallbackArgs = args.slice(1);
61 cr.webUIResponse.apply(null, globalCallbackArgs);
62 });
63 });
64
65 test('sendWithPromise_MultipleArgs', function() {
66 return cr.sendWithPromise(CHROME_SEND_NAME, 'foo', 'bar').then(
67 function(response) {
68 assertEquals(['foo', 'bar'].join(), response.join());
Dan Beam 2016/01/26 00:54:52 in this case I don't think it's suitable for me to
69 });
70 });
71
72 test('sendWithPromise_NoArgs', function() {
73 return cr.sendWithPromise(CHROME_SEND_NAME).then(function(response) {
74 assertEquals([].join(), response.join());
75 });
76 });
77 });
78
79 // Run all registered tests.
80 mocha.run();
81 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698