Chromium Code Reviews| Index: chrome/browser/resources/file_manager/js/test_util.js |
| diff --git a/chrome/browser/resources/file_manager/js/test_util.js b/chrome/browser/resources/file_manager/js/test_util.js |
| index 2ff8d20c7e17d4344e6611782aa8e244b9ae27ab..bc6bcf2254bac8687912eedfb3528094aa9494d9 100644 |
| --- a/chrome/browser/resources/file_manager/js/test_util.js |
| +++ b/chrome/browser/resources/file_manager/js/test_util.js |
| @@ -108,6 +108,60 @@ test.util.waitForFileListChange = function( |
| }; |
| /** |
| + * Returns an array of suggestions on the file manager's autocomplete list. |
| + * |
| + * @param {Window} contentWindow Window to be tested. |
| + * @return {Array.<string>} Array of suggestions. |
| + */ |
| +test.util.getAutocompleteList = function(contentWindow) { |
| + var list = contentWindow.document.querySelector('#autocomplete-list'); |
| + var lines = list.querySelectorAll('li'); |
| + var suggestions = []; |
| + for (var j = 0; j < lines.length; ++j) { |
| + var line = lines[j]; |
| + suggestions.push(line.innerText); |
| + } |
| + return suggestions; |
| +}; |
| + |
| +/** |
| + * 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
|
| + * |
| + * @param {Window} contentWindow Window to be tested. |
| + * @param {string} query Query used for autocomplete. |
| + * @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.
|
| + * @param {function(Array.<string>)} callback Change callback. |
| + */ |
| +test.util.performAutocomplete = function( |
| + contentWindow, query, numExpectedEntries, callback) { |
| + // Dispatch a 'focus' event to the search box so that the autocomplete list |
| + // is attached to the search box. Note that calling searchBox.focus() won't |
| + // dispatch a 'focus' event. |
| + var searchBox = contentWindow.document.querySelector('#search-box'); |
| + var focusEvent = contentWindow.document.createEvent('Event'); |
| + focusEvent.initEvent('focus', true /* bubbles */, true /* cancelable */); |
| + searchBox.dispatchEvent(focusEvent); |
| + |
| + // Change the value of the search box and dispatch an 'input' event so that |
| + // the autocomplete query is processed. |
| + searchBox.value = query; |
| + var inputEvent = contentWindow.document.createEvent('Event'); |
| + inputEvent.initEvent('input', true /* bubbles */, true /* cancelable */); |
| + searchBox.dispatchEvent(inputEvent); |
| + |
| + function helper() { |
| + var suggestions = test.util.getAutocompleteList(contentWindow); |
| + // The first suggestion is always "'<query>' - search Drive", which we |
| + // don't count as an entry. |
|
satorux1
2013/04/17 08:03:31
I found it confusing. Changed the function to take
|
| + if (suggestions.length > numExpectedEntries) |
| + callback(suggestions); |
| + else |
| + window.setTimeout(helper, 50); |
| + } |
| + helper(); |
| +}; |
| + |
| +/** |
| * Waits until a dialog with an OK button is shown and accepts it. |
| * |
| * @param {Window} contentWindow Window to be tested. |
| @@ -249,6 +303,10 @@ test.util.registerRemoteTestUtils = function() { |
| case 'getFileList': |
| sendResponse(test.util.getFileList(contentWindow)); |
| return false; |
| + case 'performAutocomplete': |
| + test.util.performAutocomplete( |
| + contentWindow, request.args[0], request.args[1], sendResponse); |
| + return true; |
| case 'waitForFileListChange': |
| test.util.waitForFileListChange( |
| contentWindow, request.args[0], sendResponse); |