Commit 0bb8ab89 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Migrate some directory tree test helpers into remote_call.js

Bug: 883628
Change-Id: I5f4d81dd1a1d269a33091748def79d20941f1eca
Reviewed-on: https://chromium-review.googlesource.com/1229638Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592247}
parent 8e4d512b
......@@ -199,20 +199,26 @@ testcase.createFolderDownloads = function() {
testcase.createFolderNestedDownloads = function() {
let appId;
const promise = new Promise(function(resolve) {
setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, resolve, BASIC_LOCAL_ENTRY_SET, []);
}).then(function(results) {
appId = results.windowId;
return expandRoot(appId, TREEITEM_DOWNLOADS);
}).then(function() {
return navigateWithDirectoryTree(appId, '/photos', 'Downloads');
}).then(function() {
return remoteCall.waitForFiles(
appId, [], {ignoreLastModifiedTime: true});
}).then(function() {
return createNewFolder(appId, [], TREEITEM_DOWNLOADS);
});
const promise =
new Promise(function(resolve) {
setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, resolve, BASIC_LOCAL_ENTRY_SET, []);
})
.then(function(results) {
appId = results.windowId;
return expandRoot(appId, TREEITEM_DOWNLOADS);
})
.then(function() {
return remoteCall.navigateWithDirectoryTree(
appId, '/photos', 'Downloads');
})
.then(function() {
return remoteCall.waitForFiles(
appId, [], {ignoreLastModifiedTime: true});
})
.then(function() {
return createNewFolder(appId, [], TREEITEM_DOWNLOADS);
});
testPromise(promise);
};
......
......@@ -436,6 +436,104 @@ RemoteCallFilesApp.prototype.waitUntilCurrentDirectoryIsChanged = function(
}.bind(this));
};
/**
* Expands tree item.
*/
RemoteCallFilesApp.prototype.expandTreeItemInDirectoryTree = function(
windowId, query) {
return this.waitForElement(windowId, query)
.then(() => {
return this.callRemoteTestUtil(
'queryAllElements', windowId, [`${query}[expanded]`]);
})
.then(elements => {
// If it's already expanded, do nothing.
if (elements.length > 0)
return;
// Focus to directory tree.
return this.callRemoteTestUtil('focus', windowId, ['#directory-tree'])
.then(() => {
// Expand directory volume.
return this.callRemoteTestUtil(
'fakeMouseClick', windowId, [`${query} .expand-icon`]);
});
});
};
/**
* Expands directory tree for specified path.
*/
RemoteCallFilesApp.prototype.expandDirectoryTreeFor = function(
windowId, path, volumeType = 'downloads') {
return this.expandDirectoryTreeForInternal_(
windowId, path.split('/'), 0, volumeType);
};
/**
* Internal function for expanding directory tree for specified path.
*/
RemoteCallFilesApp.prototype.expandDirectoryTreeForInternal_ = function(
windowId, components, index, volumeType) {
if (index >= components.length - 1)
return Promise.resolve();
if (index === 0) {
return this.expandVolumeInDirectoryTree(windowId, volumeType).then(() => {
return this.expandDirectoryTreeForInternal_(
windowId, components, index + 1, volumeType);
});
}
const path = `/${components.slice(1, index + 1).join('/')}`;
return this
.expandTreeItemInDirectoryTree(
windowId, `[full-path-for-testing="${path}"]`)
.then(() => {
return this.expandDirectoryTreeForInternal_(
windowId, components, index + 1, volumeType);
});
};
/**
* Expands download volume in directory tree.
*/
RemoteCallFilesApp.prototype.expandDownloadVolumeInDirectoryTree = function(
windowId) {
return this.expandVolumeInDirectoryTree(windowId, 'downloads');
};
/**
* Expands download volume in directory tree.
*/
RemoteCallFilesApp.prototype.expandVolumeInDirectoryTree = function(
windowId, volumeType) {
return this.expandTreeItemInDirectoryTree(
windowId, `[volume-type-for-testing="${volumeType}"]`);
};
/**
* Navigates to specified directory on the specified volume by using directory
* tree.
*/
RemoteCallFilesApp.prototype.navigateWithDirectoryTree = function(
windowId, path, rootLabel, volumeType = 'downloads') {
return this.expandDirectoryTreeFor(windowId, path, volumeType)
.then(() => {
// Select target path.
return this.callRemoteTestUtil(
'fakeMouseClick', windowId, [`[full-path-for-testing="${path}"]`]);
})
.then(() => {
if (rootLabel === 'My Drive') {
path = path.replace(/^\/root\//, '/');
}
// Wait until the Files app is navigated to the path.
return this.waitUntilCurrentDirectoryIsChanged(
windowId, `/${rootLabel}${path}`);
});
};
/**
* Class to manipulate the window in the remote extension.
*
......
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