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

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

Issue 1635673003: MD Settings: Add helper method for responding to cr.sendWithPromise. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments. 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
« no previous file with comments | « chrome/browser/ui/webui/settings/md_settings_ui.cc ('k') | ui/webui/resources/js/cr.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 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
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 });
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/md_settings_ui.cc ('k') | ui/webui/resources/js/cr.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698