Commit e95aca92 authored by hirono's avatar hirono Committed by Commit bot

Files.app: Stop to use autogen IDs of TreeItems to identify tree items.

The IDs are generated by counter, so sometime different IDs were assigned to the
items and it causes flakiness of browser tests.

BUG=512669
TEST=None

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

Cr-Commit-Position: refs/heads/master@{#339848}
parent 319562c8
......@@ -129,8 +129,7 @@ WRAPPED_INSTANTIATE_TEST_CASE_P(
#if defined(DISABLE_SLOW_FILESAPP_TESTS) || defined(OFFICIAL_BUILD)
#define MAYBE_KeyboardOperations DISABLED_KeyboardOperations
#else
// Flaky on other builds. http://crbug.com/512669
#define MAYBE_KeyboardOperations DISABLED_KeyboardOperations
#define MAYBE_KeyboardOperations KeyboardOperations
#endif
WRAPPED_INSTANTIATE_TEST_CASE_P(
MAYBE_KeyboardOperations,
......
......@@ -139,6 +139,24 @@ test.util.async.selectVolume = function(contentWindow, iconName, callback) {
steps.checkQuery();
};
/**
* Obtains visible tree items.
*
* @param {Window} contentWindow Window to be tested.
* @return {!Array<string>} List of visible item names.
*/
test.util.sync.getTreeItems = function(contentWindow) {
var items = contentWindow.document.querySelectorAll(
'#directory-tree .tree-item');
var result = [];
for (var i = 0; i < items.length; i++) {
if (items[i].matches('.tree-children:not([expanded]) *'))
continue;
result.push(items[i].querySelector('.entry-name').textContent);
}
return result;
};
/**
* Executes Javascript code on a webview and returns the result.
*
......
......@@ -4,16 +4,6 @@
'use strict';
/**
* Constants for interacting with the directory tree on the LHS of Files.
* When we are not in guest mode, we fill Google Drive with the basic entry set
* which causes an extra tree-item to be added.
*/
var PHOTOS_FOLDER;
var PHOTOS_FOLDER_GUEST = '#tree-item-autogen-id-6';
var PHOTOS_FOLDER_DOWNLOADS = '#tree-item-autogen-id-7';
var PHOTOS_FOLDER_DRIVE = '#tree-item-autogen-id-8';
/**
* Waits until a dialog with an OK button is shown and accepts it.
*
......@@ -34,6 +24,55 @@ function waitAndAcceptDialog(windowId) {
});
}
/**
* Obtains visible tree items.
*
* @param {string} windowId Window ID.
* @return {!Promise<!Array<string>>} List of visible item names.
*/
function getTreeItems(windowId) {
return remoteCall.callRemoteTestUtil('getTreeItems', windowId, []);
};
/**
* Waits until the directory item appears.
*
* @param {string} windowId Window ID.
* @param {string} name Name of item.
* @return {!Promise}
*/
function waitForDirectoryItem(windowId, name) {
return repeatUntil(function() {
return getTreeItems(windowId).then(function(items) {
if (items.indexOf(name) !== -1) {
return true;
} else {
return pending('Tree item %s is not found.', name);
}
});
});
}
/**
* Waits until the directory item disappears.
*
* @param {string} windowId Window ID.
* @param {string} name Name of item.
* @return {!Promise}
*/
function waitForDirectoryItemLost(windowId, name) {
return repeatUntil(function() {
return getTreeItems(windowId).then(function(items) {
console.log(items);
if (items.indexOf(name) === -1) {
return true;
} else {
return pending('Tree item %s is still exists.', name);
}
});
});
}
/**
* Tests copying a file to the same directory and waits until the file lists
* changes.
......@@ -122,7 +161,7 @@ function keyboardDelete(path, treeItem) {
},
function() {
// Check that the directory appears in the LHS tree
remoteCall.waitForElement(appId, PHOTOS_FOLDER).then(this.next);
waitForDirectoryItem(appId, directoryName).then(this.next);
},
// Wait for a file list change.
function() {
......@@ -154,7 +193,7 @@ function keyboardDelete(path, treeItem) {
},
function() {
// Check that the directory is removed from the LHS tree
remoteCall.waitForElementLost(appId, PHOTOS_FOLDER).then(this.next);
waitForDirectoryItemLost(appId, directoryName).then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
......@@ -293,10 +332,6 @@ testcase.keyboardCopyDownloads = function() {
};
testcase.keyboardDeleteDownloads = function() {
if (chrome.extension.inIncognitoContext)
PHOTOS_FOLDER = PHOTOS_FOLDER_GUEST;
else
PHOTOS_FOLDER = PHOTOS_FOLDER_DOWNLOADS;
keyboardDelete(RootPath.DOWNLOADS, TREEITEM_DOWNLOADS);
};
......@@ -305,13 +340,9 @@ testcase.keyboardCopyDrive = function() {
};
testcase.keyboardDeleteDrive = function() {
PHOTOS_FOLDER = PHOTOS_FOLDER_DRIVE;
keyboardDelete(RootPath.DRIVE, TREEITEM_DRIVE);
};
testcase.createNewFolderAndCheckFocus = function() {
};
testcase.renameFileDownloads = function() {
testPromise(testRenameFile(RootPath.DOWNLOADS, BASIC_LOCAL_ENTRY_SET));
};
......
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