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

Side by Side Diff: ui/file_manager/integration_tests/remote_call.js

Issue 942393002: Add a simple way of performing step by step tests for testers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More cleanup. Created 5 years, 10 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * Class to manipulate the window in the remote extension. 8 * Class to manipulate the window in the remote extension.
9 * 9 *
10 * @param {string} extensionId ID of extension to be manipulated. 10 * @param {string} extensionId ID of extension to be manipulated.
11 * @constructor 11 * @constructor
12 */ 12 */
13 function RemoteCall(extensionId) { 13 function RemoteCall(extensionId) {
14 this.extensionId_ = extensionId; 14 this.extensionId_ = extensionId;
15 } 15 }
16 16
17 /** 17 /**
18 * Checks whether step by step tests are enabled or not.
19 * @return {Promise<bool>}
20 */
21 RemoteCall.isStepByStepEnabled = function() {
22 return new Promise(function(fulfill) {
23 chrome.commandLinePrivate.hasSwitch('enable-step-by-step-tests', fulfill);
24 });
25 };
26
27 /**
18 * Calls a remote test util in Files.app's extension. See: test_util.js. 28 * Calls a remote test util in Files.app's extension. See: test_util.js.
19 * 29 *
20 * @param {string} func Function name. 30 * @param {string} func Function name.
21 * @param {?string} appId Target window's App ID or null for functions 31 * @param {?string} appId Target window's App ID or null for functions
22 * not requiring a window. 32 * not requiring a window.
23 * @param {Array.<*>} args Array of arguments. 33 * @param {Array.<*>} args Array of arguments.
24 * @param {function(*)=} opt_callback Callback handling the function's result. 34 * @param {function(*)=} opt_callback Callback handling the function's result.
25 * @return {Promise} Promise to be fulfilled with the result of the remote 35 * @return {Promise} Promise to be fulfilled with the result of the remote
26 * utility. 36 * utility.
27 */ 37 */
28 RemoteCall.prototype.callRemoteTestUtil = 38 RemoteCall.prototype.callRemoteTestUtil =
29 function(func, appId, args, opt_callback) { 39 function(func, appId, args, opt_callback) {
30 return new Promise(function(onFulfilled) { 40 var stepByStepEnabled = false;
31 chrome.runtime.sendMessage( 41 return RemoteCall.isStepByStepEnabled().then(function(enabled) {
32 this.extensionId_, 42 stepByStepEnabled = enabled;
33 { 43 }).then(function() {
hirono 2015/02/23 07:00:40 nit: We can receive stepByStepEnabled directly fro
mtomasz 2015/02/23 09:30:43 I'm not sure if I understand. You mean to embed #5
hirono 2015/02/23 10:01:10 SGTM!
34 func: func, 44 if (stepByStepEnabled) {
35 appId: appId, 45 return new Promise(function(onFulfilled) {
36 args: args 46 console.info('Executing: ' + func + ' on ' + appId + ' with args: ');
37 }, 47 console.info(args);
38 function() { 48 console.info('Type step() to continue...');
39 if (opt_callback) 49 window.step = function() {
40 opt_callback.apply(null, arguments); 50 window.step = null;
41 onFulfilled(arguments[0]); 51 onFulfilled();
42 }); 52 };
53 });
54 }
55 }).then(function() {
56 return new Promise(function(onFulfilled) {
57 chrome.runtime.sendMessage(
58 this.extensionId_,
59 {
60 func: func,
61 appId: appId,
62 args: args
63 },
64 function(var_args) {
65 if (stepByStepEnabled) {
66 console.info('Returned value:');
67 console.info(arguments);
68 }
69 if (opt_callback)
70 opt_callback.apply(null, arguments);
71 onFulfilled(arguments[0]);
72 });
73 }.bind(this));
43 }.bind(this)); 74 }.bind(this));
44 }; 75 };
45 76
46 /** 77 /**
47 * Waits until a window having the given ID prefix appears. 78 * Waits until a window having the given ID prefix appears.
48 * @param {string} windowIdPrefix ID prefix of the requested window. 79 * @param {string} windowIdPrefix ID prefix of the requested window.
49 * @return {Promise} promise Promise to be fulfilled with a found window's ID. 80 * @return {Promise} promise Promise to be fulfilled with a found window's ID.
50 */ 81 */
51 RemoteCall.prototype.waitForWindow = function(windowIdPrefix) { 82 RemoteCall.prototype.waitForWindow = function(windowIdPrefix) {
52 return repeatUntil(function() { 83 return repeatUntil(function() {
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 RemoteCallFilesApp.prototype.waitUntilCurrentDirectoryIsChanged = 330 RemoteCallFilesApp.prototype.waitUntilCurrentDirectoryIsChanged =
300 function(windowId, expectedPath) { 331 function(windowId, expectedPath) {
301 return repeatUntil(function () { 332 return repeatUntil(function () {
302 return this.callRemoteTestUtil('getBreadcrumbPath', windowId, []).then( 333 return this.callRemoteTestUtil('getBreadcrumbPath', windowId, []).then(
303 function(path) { 334 function(path) {
304 if(path !== expectedPath) 335 if(path !== expectedPath)
305 return pending('Expected path is %s', expectedPath); 336 return pending('Expected path is %s', expectedPath);
306 }); 337 });
307 }.bind(this)); 338 }.bind(this));
308 }; 339 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698