Commit 6604b159 authored by satorux@chromium.org's avatar satorux@chromium.org

drive: Add a very basic browser test for the autocomplete feature

The test verifies that the autocomplete list is shown properly.

BUG=179976
TEST=none

Review URL: https://codereview.chromium.org/14312009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194730 0039d316-1c4b-4281-b951-d872f2087c98
parent 7a0fc7fb
...@@ -707,4 +707,12 @@ IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, TestOpenRecent) { ...@@ -707,4 +707,12 @@ IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, TestOpenRecent) {
ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
} }
IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, TestAutocomplete) {
drive_test_util::WaitUntilDriveMountPointIsAdded(browser()->profile());
ResultCatcher catcher;
StartTest("autocomplete");
ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
}
} // namespace } // namespace
...@@ -107,6 +107,60 @@ test.util.waitForFileListChange = function( ...@@ -107,6 +107,60 @@ test.util.waitForFileListChange = function(
helper(); helper();
}; };
/**
* Returns an array of items on the file manager's autocomplete list.
*
* @param {Window} contentWindow Window to be tested.
* @return {Array.<string>} Array of items.
*/
test.util.getAutocompleteList = function(contentWindow) {
var list = contentWindow.document.querySelector('#autocomplete-list');
var lines = list.querySelectorAll('li');
var items = [];
for (var j = 0; j < lines.length; ++j) {
var line = lines[j];
items.push(line.innerText);
}
return items;
};
/**
* Performs autocomplete with the given query and waits until at least
* |numExpectedItems| items are shown, including the first item which
* always looks like "'<query>' - search Drive".
*
* @param {Window} contentWindow Window to be tested.
* @param {string} query Query used for autocomplete.
* @param {number} numExpectedItems number of items to be shown.
* @param {function(Array.<string>)} callback Change callback.
*/
test.util.performAutocompleteAndWait = function(
contentWindow, query, numExpectedItems, 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 items = test.util.getAutocompleteList(contentWindow);
if (items.length >= numExpectedItems)
callback(items);
else
window.setTimeout(helper, 50);
}
helper();
};
/** /**
* Waits until a dialog with an OK button is shown and accepts it. * Waits until a dialog with an OK button is shown and accepts it.
* *
...@@ -249,6 +303,10 @@ test.util.registerRemoteTestUtils = function() { ...@@ -249,6 +303,10 @@ test.util.registerRemoteTestUtils = function() {
case 'getFileList': case 'getFileList':
sendResponse(test.util.getFileList(contentWindow)); sendResponse(test.util.getFileList(contentWindow));
return false; return false;
case 'performAutocompleteAndWait':
test.util.performAutocompleteAndWait(
contentWindow, request.args[0], request.args[1], sendResponse);
return true;
case 'waitForFileListChange': case 'waitForFileListChange':
test.util.waitForFileListChange( test.util.waitForFileListChange(
contentWindow, request.args[0], sendResponse); contentWindow, request.args[0], sendResponse);
......
...@@ -173,3 +173,26 @@ testcase.openSidebarRecent = function() { ...@@ -173,3 +173,26 @@ testcase.openSidebarRecent = function() {
}); });
}); });
}; };
/**
* Tests autocomplete with a query 'hello'. This test is only available for
* Drive.
*/
testcase.autocomplete = function() {
var EXPECTED_AUTOCOMPLETE_LIST = [
'\'hello\' - search Drive\n',
'hello.txt\n',
];
var onAutocompleteListShown = chrome.test.callbackPass(
function(autocompleteList) {
chrome.test.assertEq(EXPECTED_AUTOCOMPLETE_LIST, autocompleteList);
});
setupAndWaitUntilReady('/drive/root', function(appId, list) {
callRemoteTestUtil('performAutocompleteAndWait',
appId,
['hello', EXPECTED_AUTOCOMPLETE_LIST.length],
onAutocompleteListShown);
});
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment