Commit 15064e4a authored by dhaddock's avatar dhaddock Committed by Commit bot

Some browser_tests for Drive search.

First attempt at browsers tests. I've added two tests to cover a regression
issue that came up recently where clicking the search result in the
autocomplete box didn't show all of the results. Pressing enter didn't do
anything either.

I have refactored drive_specific/autocomplete so I could make use of it.

BUG=chromium:440251,chromium:454907
TEST=browser_tests --gtest_filter="*DriveSpecific/FileManagerBrowserTest.Test/{5/6}"

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

Cr-Commit-Position: refs/heads/master@{#319830}
parent efc601eb
......@@ -927,7 +927,9 @@ WRAPPED_INSTANTIATE_TEST_CASE_P(
TestParameter(NOT_IN_GUEST_MODE, "openSidebarOffline"),
TestParameter(NOT_IN_GUEST_MODE, "openSidebarSharedWithMe"),
TestParameter(NOT_IN_GUEST_MODE, "autocomplete"),
TestParameter(NOT_IN_GUEST_MODE, "pinFileOnMobileNetwork")));
TestParameter(NOT_IN_GUEST_MODE, "pinFileOnMobileNetwork"),
TestParameter(NOT_IN_GUEST_MODE, "clickFirstSearchResult"),
TestParameter(NOT_IN_GUEST_MODE, "pressEnterToSearch")));
// Slow tests are disabled on debug build. http://crbug.com/327719
// Fails on official build. http://crbug.com/429294
......
......@@ -4,6 +4,88 @@
'use strict';
/**
* Expected autocomplete results for 'hello'.
* @type {Array<string>}
* @const
*/
var EXPECTED_AUTOCOMPLETE_LIST = [
'\'hello\' - search Drive',
'hello.txt'
];
/**
* Expected files shown in the search results for 'hello'
*
* @type {Array<TestEntryInfo>}
* @const
*/
var SEARCH_RESULTS_ENTRY_SET = [
ENTRIES.hello
];
/**
* Returns the steps to start a search for 'hello' and wait for the
* autocomplete results to appear.
*/
function getStepsForSearchResultsAutoComplete() {
var appId;
var steps =
[
function() {
setupAndWaitUntilReady(null, RootPath.DRIVE, this.next);
},
// Focus the search box.
function(inAppId, list) {
appId = inAppId;
remoteCall.callRemoteTestUtil('fakeEvent',
appId,
['#search-box input', 'focus'],
this.next);
},
// Input a text.
function(result) {
chrome.test.assertTrue(result);
remoteCall.callRemoteTestUtil('inputText',
appId,
['#search-box input', 'hello'],
this.next);
},
// Notify the element of the input.
function() {
remoteCall.callRemoteTestUtil('fakeEvent',
appId,
['#search-box input', 'input'],
this.next);
},
// Wait for the auto complete list getting the expected contents.
function(result) {
chrome.test.assertTrue(result);
repeatUntil(function() {
return remoteCall.callRemoteTestUtil('queryAllElements',
appId,
['#autocomplete-list li']).
then(function(elements) {
var list = elements.map(
function(element) { return element.text; });
return chrome.test.checkDeepEq(EXPECTED_AUTOCOMPLETE_LIST, list) ?
undefined :
pending('Current auto complete list: %j.', list);
});
}).
then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
},
function()
{
this.next(appId);
}
];
return steps;
}
/**
* Tests opening the "Recent" on the sidebar navigation by clicking the icon,
* and verifies the directory contents. We test if there are only files, since
......@@ -112,60 +194,87 @@ testcase.openSidebarSharedWithMe = function() {
* Drive.
*/
testcase.autocomplete = function() {
var EXPECTED_AUTOCOMPLETE_LIST = [
'\'hello\' - search Drive',
'hello.txt',
];
var appId;
StepsRunner.run(getStepsForSearchResultsAutoComplete());
};
StepsRunner.run([
function() {
setupAndWaitUntilReady(null, RootPath.DRIVE, this.next);
},
// Focus the search box.
function(inAppId, list) {
appId = inAppId;
remoteCall.callRemoteTestUtil('fakeEvent',
appId,
['#search-box input', 'focus'],
this.next);
/**
* Tests that clicking the first option in the autocomplete box shows all of
* the results for that query.
*/
testcase.clickFirstSearchResult = function() {
var appId;
var steps = getStepsForSearchResultsAutoComplete();
steps.push(
function(id) {
appId = id;
remoteCall.callRemoteTestUtil('fakeKeyDown',
appId,
['#autocomplete-list', 'Down', false],
this.next);
},
// Input a text.
function(result) {
chrome.test.assertTrue(result);
remoteCall.callRemoteTestUtil('inputText',
remoteCall.waitForElement(appId,
['#autocomplete-list li[selected]']).
then(this.next);
},
function(result) {
remoteCall.callRemoteTestUtil('fakeMouseDown',
appId,
['#search-box input', 'hello'],
['#autocomplete-list li[selected]'],
this.next);
},
// Notify the element of the input.
function() {
function(result)
{
remoteCall.waitForFileListChange(appId, BASIC_DRIVE_ENTRY_SET.length).
then(this.next);
},
function(actualFilesAfter)
{
chrome.test.assertEq(
TestEntryInfo.getExpectedRows(SEARCH_RESULTS_ENTRY_SET).sort(),
actualFilesAfter);
checkIfNoErrorsOccured(this.next);
}
);
StepsRunner.run(steps);
};
/**
* Tests that pressing enter after typing a search shows all of
* the results for that query.
*/
testcase.pressEnterToSearch = function() {
var appId;
var steps = getStepsForSearchResultsAutoComplete();
steps.push(
function(id) {
appId = id;
remoteCall.callRemoteTestUtil('fakeEvent',
appId,
['#search-box input', 'input'],
['#search-box input', 'focus'],
this.next);
},
// Wait for the auto complete list getting the expected contents.
function(result) {
chrome.test.assertTrue(result);
repeatUntil(function() {
return remoteCall.callRemoteTestUtil('queryAllElements',
appId,
['#autocomplete-list li']).
then(function(elements) {
var list = elements.map(
function(element) { return element.text; });
return chrome.test.checkDeepEq(EXPECTED_AUTOCOMPLETE_LIST, list) ?
undefined :
pending('Current auto complete list: %j.', list);
});
}).
remoteCall.callRemoteTestUtil('fakeKeyDown',
appId,
['#search-box input', 'Enter', false],
this.next);
},
function(result) {
remoteCall.waitForFileListChange(appId, BASIC_DRIVE_ENTRY_SET.length).
then(this.next);
},
function() {
function(actualFilesAfter) {
chrome.test.assertEq(
TestEntryInfo.getExpectedRows(SEARCH_RESULTS_ENTRY_SET).sort(),
actualFilesAfter);
checkIfNoErrorsOccured(this.next);
}
]);
);
StepsRunner.run(steps);
};
/**
......
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