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

Side by Side Diff: chrome/browser/resources/file_manager/js/test_util.js

Issue 14312009: drive: Add a very basic browser test for the autocomplete feature (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 * Namespace for test related things. 6 * Namespace for test related things.
7 */ 7 */
8 var test = test || {}; 8 var test = test || {};
9 9
10 /** 10 /**
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 }); 101 });
102 if (notReadyRows.length === 0 && files.length !== lengthBefore) 102 if (notReadyRows.length === 0 && files.length !== lengthBefore)
103 callback(files); 103 callback(files);
104 else 104 else
105 window.setTimeout(helper, 50); 105 window.setTimeout(helper, 50);
106 } 106 }
107 helper(); 107 helper();
108 }; 108 };
109 109
110 /** 110 /**
111 * Returns an array of suggestions on the file manager's autocomplete list.
112 *
113 * @param {Window} contentWindow Window to be tested.
114 * @return {Array.<string>} Array of suggestions.
115 */
116 test.util.getAutocompleteList = function(contentWindow) {
117 var list = contentWindow.document.querySelector('#autocomplete-list');
118 var lines = list.querySelectorAll('li');
119 var suggestions = [];
120 for (var j = 0; j < lines.length; ++j) {
121 var line = lines[j];
122 suggestions.push(line.innerText);
123 }
124 return suggestions;
125 };
126
127 /**
128 * Performs autocomplete with the given query.
mtomasz 2013/04/17 07:51:10 Please write down that it not only performs but al
satorux1 2013/04/17 08:03:31 Done. Renamed it to performAutocompleteAndWait
129 *
130 * @param {Window} contentWindow Window to be tested.
131 * @param {string} query Query used for autocomplete.
132 * @param {number} numExpectedEntries number of entries that matche the query.
mtomasz 2013/04/17 07:51:10 matche -> match
satorux1 2013/04/17 08:03:31 Done.
133 * @param {function(Array.<string>)} callback Change callback.
134 */
135 test.util.performAutocomplete = function(
136 contentWindow, query, numExpectedEntries, callback) {
137 // Dispatch a 'focus' event to the search box so that the autocomplete list
138 // is attached to the search box. Note that calling searchBox.focus() won't
139 // dispatch a 'focus' event.
140 var searchBox = contentWindow.document.querySelector('#search-box');
141 var focusEvent = contentWindow.document.createEvent('Event');
142 focusEvent.initEvent('focus', true /* bubbles */, true /* cancelable */);
143 searchBox.dispatchEvent(focusEvent);
144
145 // Change the value of the search box and dispatch an 'input' event so that
146 // the autocomplete query is processed.
147 searchBox.value = query;
148 var inputEvent = contentWindow.document.createEvent('Event');
149 inputEvent.initEvent('input', true /* bubbles */, true /* cancelable */);
150 searchBox.dispatchEvent(inputEvent);
151
152 function helper() {
153 var suggestions = test.util.getAutocompleteList(contentWindow);
154 // The first suggestion is always "'<query>' - search Drive", which we
155 // don't count as an entry.
satorux1 2013/04/17 08:03:31 I found it confusing. Changed the function to take
156 if (suggestions.length > numExpectedEntries)
157 callback(suggestions);
158 else
159 window.setTimeout(helper, 50);
160 }
161 helper();
162 };
163
164 /**
111 * Waits until a dialog with an OK button is shown and accepts it. 165 * Waits until a dialog with an OK button is shown and accepts it.
112 * 166 *
113 * @param {Window} contentWindow Window to be tested. 167 * @param {Window} contentWindow Window to be tested.
114 * @param {function()} callback Success callback. 168 * @param {function()} callback Success callback.
115 */ 169 */
116 test.util.waitAndAcceptDialog = function(contentWindow, callback) { 170 test.util.waitAndAcceptDialog = function(contentWindow, callback) {
117 var tryAccept = function() { 171 var tryAccept = function() {
118 var button = contentWindow.document.querySelector('.cr-dialog-ok'); 172 var button = contentWindow.document.querySelector('.cr-dialog-ok');
119 if (button) { 173 if (button) {
120 button.click(); 174 button.click();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 } 296 }
243 } else { 297 } else {
244 // Functions working on a window. 298 // Functions working on a window.
245 switch (request.func) { 299 switch (request.func) {
246 case 'getSelectedFiles': 300 case 'getSelectedFiles':
247 sendResponse(test.util.getSelectedFiles(contentWindow)); 301 sendResponse(test.util.getSelectedFiles(contentWindow));
248 return false; 302 return false;
249 case 'getFileList': 303 case 'getFileList':
250 sendResponse(test.util.getFileList(contentWindow)); 304 sendResponse(test.util.getFileList(contentWindow));
251 return false; 305 return false;
306 case 'performAutocomplete':
307 test.util.performAutocomplete(
308 contentWindow, request.args[0], request.args[1], sendResponse);
309 return true;
252 case 'waitForFileListChange': 310 case 'waitForFileListChange':
253 test.util.waitForFileListChange( 311 test.util.waitForFileListChange(
254 contentWindow, request.args[0], sendResponse); 312 contentWindow, request.args[0], sendResponse);
255 return true; 313 return true;
256 case 'waitAndAcceptDialog': 314 case 'waitAndAcceptDialog':
257 test.util.waitAndAcceptDialog(contentWindow, sendResponse); 315 test.util.waitAndAcceptDialog(contentWindow, sendResponse);
258 return true; 316 return true;
259 case 'selectFile': 317 case 'selectFile':
260 test.util.sendResponse(selectFile(contentWindow, request.args[0])); 318 test.util.sendResponse(selectFile(contentWindow, request.args[0]));
261 return false; 319 return false;
(...skipping 14 matching lines...) Expand all
276 default: 334 default:
277 console.error('Window function ' + request.func + ' not found.'); 335 console.error('Window function ' + request.func + ' not found.');
278 } 336 }
279 } 337 }
280 return false; 338 return false;
281 }); 339 });
282 }; 340 };
283 341
284 // Register the test utils. 342 // Register the test utils.
285 test.util.registerRemoteTestUtils(); 343 test.util.registerRemoteTestUtils();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698