Commit 956dde61 authored by yoshiki's avatar yoshiki Committed by Commit bot

[Files.app] Add a test to check tabfocus

This patch adds tests of transition of tabfocus in Files.app.

BUG=469061

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

Cr-Commit-Position: refs/heads/master@{#321957}
parent c44add2d
......@@ -1100,6 +1100,17 @@ INSTANTIATE_TEST_CASE_P(
FileManagerBrowserTest,
::testing::Values(TestParameter(NOT_IN_GUEST_MODE, "searchBoxFocus")));
INSTANTIATE_TEST_CASE_P(TabindexFocus,
FileManagerBrowserTest,
::testing::Values(TestParameter(NOT_IN_GUEST_MODE,
"tabindexFocus")));
INSTANTIATE_TEST_CASE_P(
TabindexFocusDirectorySelected,
FileManagerBrowserTest,
::testing::Values(TestParameter(NOT_IN_GUEST_MODE,
"tabindexFocusDirectorySelected")));
// Fails on official build. http://crbug.com/429294
#if !defined(NDEBUG) || defined(OFFICIAL_BUILD)
#define MAYBE_OpenFileDialog DISABLED_OpenFileDialog
......
......@@ -7,6 +7,41 @@
*/
var test = test || {};
/**
* Extract the information of the given element.
* @param {Element} element Element to be extracted.
* @param {Window} contentWindow Window to be tested.
* @param {Array.<string>=} opt_styleNames List of CSS property name to be
* obtained.
* @return {{attributes:Object.<string, string>, text:string,
* styles:Object.<string, string>, hidden:boolean}} Element
* information that contains contentText, attribute names and
* values, hidden attribute, and style names and values.
*/
function extractElementInfo(element, contentWindow, opt_styleNames) {
var attributes = {};
for (var i = 0; i < element.attributes.length; i++) {
attributes[element.attributes[i].nodeName] =
element.attributes[i].nodeValue;
}
var styles = {};
var styleNames = opt_styleNames || [];
var computedStyles = contentWindow.getComputedStyle(element);
for (var i = 0; i < styleNames.length; i++) {
styles[styleNames[i]] = computedStyles[styleNames[i]];
}
var text = element.textContent;
return {
attributes: attributes,
text: text,
value: element.value,
styles: styles,
// The hidden attribute is not in the element.attributes even if
// element.hasAttribute('hidden') is true.
hidden: !!element.hidden
};
}
/**
* Namespace for test utility functions.
*
......@@ -147,30 +182,34 @@ test.util.sync.queryAllElements = function(
return Array.prototype.map.call(
doc.querySelectorAll(targetQuery),
function(element) {
var attributes = {};
for (var i = 0; i < element.attributes.length; i++) {
attributes[element.attributes[i].nodeName] =
element.attributes[i].nodeValue;
}
var styles = {};
var styleNames = opt_styleNames || [];
var computedStyles = contentWindow.getComputedStyle(element);
for (var i = 0; i < styleNames.length; i++) {
styles[styleNames[i]] = computedStyles[styleNames[i]];
}
var text = element.textContent;
return {
attributes: attributes,
text: text,
value: element.value,
styles: styles,
// The hidden attribute is not in the element.attributes even if
// element.hasAttribute('hidden') is true.
hidden: !!element.hidden
};
return extractElementInfo(element, contentWindow, opt_styleNames);
});
};
/**
* Get the information of the active element.
*
* @param {Window} contentWindow Window to be tested.
* @param {string} targetQuery Query to specify the element.
* @param {?string} iframeQuery Iframe selector or null if no iframe.
* @param {Array.<string>=} opt_styleNames List of CSS property name to be
* obtained.
* @return {{attributes:Object.<string, string>, text:string,
* styles:Object.<string, string>, hidden:boolean}=} Element
* information that contains contentText, attribute names and
* values, hidden attribute, and style names and values. If there is no
* active element, returns null.
*/
test.util.sync.getActiveElement = function(
contentWindow, targetQuery, iframeQuery, opt_styleNames) {
var doc = test.util.sync.getDocument_(
contentWindow, iframeQuery || undefined);
if (!doc || !doc.activeElement)
return null;
return extractElementInfo(doc.activeElement, contentWindow, opt_styleNames);
};
/**
* Assigns the text to the input element.
* @param {Window} contentWindow Window to be tested.
......
......@@ -196,6 +196,7 @@ Banners.prototype.prepareAndShowWelcomeBanner_ = function(type, messageId) {
more.href = str('GOOGLE_DRIVE_OVERVIEW_URL');
}
more.tabIndex = '19'; // See: go/filesapp-tabindex.
more.id = 'drive-welcome-link';
more.target = '_blank';
var dismiss;
......
......@@ -30,8 +30,7 @@ testcase.searchBoxFocus = function() {
function(result) {
chrome.test.assertTrue(result);
remoteCall.waitForElement(appId, ['#search-box input:focus']).
then(this.next);
},
then(this.next); },
// Press the Esc key.
function(element) {
remoteCall.callRemoteTestUtil('fakeKeyDown',
......@@ -50,3 +49,106 @@ testcase.searchBoxFocus = function() {
}
]);
};
/**
* Tests the tab focus behavior of Files.app when no file is selected.
*/
testcase.tabindexFocus = function() {
var appId;
StepsRunner.run([
// Set up File Manager.
function() {
setupAndWaitUntilReady(null, RootPath.DRIVE, this.next);
},
// Check that the file list has the focus on launch.
function(inAppId) {
appId = inAppId;
remoteCall.waitForElement(appId, ['#file-list:focus']).then(this.next);
},
// Press the Tab key.
function(element) {
remoteCall.callRemoteTestUtil('getActiveElement',
appId,
[],
this.next);
}, function(element) {
chrome.test.assertEq('list', element.attributes['class']);
remoteCall.checkNextTabFocus(appId, 'search-button').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'view-button').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'gear-button').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'directory-tree').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'drive-welcome-link').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'file-list').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
checkIfNoErrorsOccured(this.next);
}
]);
};
/**
* Tests the tab focus behavior of Files.app when a directory is selected.
*/
testcase.tabindexFocusDirectorySelected = function() {
var appId;
StepsRunner.run([
// Set up File Manager.
function() {
setupAndWaitUntilReady(null, RootPath.DRIVE, this.next);
},
// Check that the file list has the focus on launch.
function(inAppId) {
appId = inAppId;
remoteCall.waitForElement(appId, ['#file-list:focus']).then(this.next);
},
// Press the Tab key.
function(element) {
remoteCall.callRemoteTestUtil('getActiveElement',
appId,
[],
this.next);
}, function(element) {
chrome.test.assertEq('list', element.attributes['class']);
// Select the directory named 'photos'.
remoteCall.callRemoteTestUtil(
'selectFile', appId, ['photos']).then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'share-button').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'delete-button').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'search-button').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'view-button').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'gear-button').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'directory-tree').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'drive-welcome-link').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
remoteCall.checkNextTabFocus(appId, 'file-list').then(this.next);
}, function(result) {
chrome.test.assertTrue(result);
checkIfNoErrorsOccured(this.next);
}
]);
};
......@@ -331,6 +331,37 @@ RemoteCallFilesApp.prototype.waitUntilTaskExecutes =
}.bind(this));
};
/**
* Check if the next tabforcus'd element has the given ID or not.
* @param {string} windowId Target window ID.
* @param {string} elementId String of 'id' attribute which the next tabfocus'd
* element should have.
* @return {Promise} Promise to be fulfilled with the result.
*/
RemoteCallFilesApp.prototype.checkNextTabFocus =
function(windowId, elementId) {
return remoteCall.callRemoteTestUtil('fakeKeyDown',
windowId,
['body', 'U+0009', false]).then(
function(result) {
chrome.test.assertTrue(result);
return remoteCall.callRemoteTestUtil('getActiveElement',
windowId,
[]);
}).then(function(element) {
if (!element || !element.attributes['id'])
return false;
if (element.attributes['id'] === elementId) {
return true;
} else {
console.error('The ID of the element should be "' + elementId +
'", but "' + element.attributes['id'] + '"');
return false;
}
});
};
/**
* Waits until the current directory is changed.
* @param {string} windowId Target window ID.
......
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