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() { ...@@ -199,20 +199,26 @@ testcase.createFolderDownloads = function() {
testcase.createFolderNestedDownloads = function() { testcase.createFolderNestedDownloads = function() {
let appId; let appId;
const promise = new Promise(function(resolve) { const promise =
setupAndWaitUntilReady( new Promise(function(resolve) {
null, RootPath.DOWNLOADS, resolve, BASIC_LOCAL_ENTRY_SET, []); setupAndWaitUntilReady(
}).then(function(results) { null, RootPath.DOWNLOADS, resolve, BASIC_LOCAL_ENTRY_SET, []);
appId = results.windowId; })
return expandRoot(appId, TREEITEM_DOWNLOADS); .then(function(results) {
}).then(function() { appId = results.windowId;
return navigateWithDirectoryTree(appId, '/photos', 'Downloads'); return expandRoot(appId, TREEITEM_DOWNLOADS);
}).then(function() { })
return remoteCall.waitForFiles( .then(function() {
appId, [], {ignoreLastModifiedTime: true}); return remoteCall.navigateWithDirectoryTree(
}).then(function() { appId, '/photos', 'Downloads');
return createNewFolder(appId, [], TREEITEM_DOWNLOADS); })
}); .then(function() {
return remoteCall.waitForFiles(
appId, [], {ignoreLastModifiedTime: true});
})
.then(function() {
return createNewFolder(appId, [], TREEITEM_DOWNLOADS);
});
testPromise(promise); testPromise(promise);
}; };
......
...@@ -44,79 +44,6 @@ var ITEMS_IN_DEST_DIR_AFTER_PASTE = ...@@ -44,79 +44,6 @@ var ITEMS_IN_DEST_DIR_AFTER_PASTE =
typeText: 'Folder' typeText: 'Folder'
})]); })]);
/**
* Expands tree item.
*/
function expandTreeItemInDirectoryTree(windowId, query) {
return remoteCall.waitForElement(windowId, query).then(function() {
return remoteCall.callRemoteTestUtil('queryAllElements', windowId,
[`${query}[expanded]`]).then(function(elements) {
// If it's already expanded, do nothing.
if (elements.length > 0)
return;
// Focus to directory tree.
return remoteCall.callRemoteTestUtil(
'focus', windowId, ['#directory-tree']).then(function() {
// Expand download volume.
return remoteCall.callRemoteTestUtil('fakeMouseClick', windowId,
[`${query} .expand-icon`]);
});
});
});
}
/**
* Expands download volume in directory tree.
*/
function expandDownloadVolumeInDirectoryTree(windowId) {
return expandTreeItemInDirectoryTree(
windowId, '[volume-type-for-testing="downloads"]');
}
/**
* Expands directory tree for specified path.
* TODO(yawano): Move this to remote_call.js
*/
function expandDirectoryTreeFor(windowId, path) {
return expandDirectoryTreeForInternal_(windowId, path.split('/'), 0);
}
/**
* Internal function for expanding directory tree for specified path.
*/
function expandDirectoryTreeForInternal_(windowId, components, index) {
if (index >= components.length - 1)
return Promise.resolve();
if (index === 0) {
return expandDownloadVolumeInDirectoryTree(windowId).then(function() {
return expandDirectoryTreeForInternal_(windowId, components, index + 1);
});
}
var path = `/${components.slice(1, index + 1).join('/')}`;
return expandTreeItemInDirectoryTree(
windowId, `[full-path-for-testing="${path}"]`).then(function() {
return expandDirectoryTreeForInternal_(windowId, components, index + 1);
});
}
/**
* Navigates to specified directory on Download volume by using directory tree.
*/
function navigateWithDirectoryTree(windowId, path, rootLabel) {
return expandDirectoryTreeFor(windowId, path).then(function() {
// Select target path.
return remoteCall.callRemoteTestUtil('fakeMouseClick', windowId,
[`[full-path-for-testing="${path}"]`]);
}).then(function() {
// Wait until the Files app is navigated to the path.
return remoteCall.waitUntilCurrentDirectoryIsChanged(
windowId, `/${rootLabel}${path}`);
});
}
/** /**
* Clicks context menu item of id in directory tree. * Clicks context menu item of id in directory tree.
*/ */
...@@ -148,20 +75,26 @@ function clickDirectoryTreeContextMenuItem(windowId, path, id) { ...@@ -148,20 +75,26 @@ function clickDirectoryTreeContextMenuItem(windowId, path, id) {
*/ */
function navigateToDestinationDirectoryAndTestPaste(windowId) { function navigateToDestinationDirectoryAndTestPaste(windowId) {
// Navigates to destination directory. // Navigates to destination directory.
return navigateWithDirectoryTree(windowId, '/destination', 'Downloads') return remoteCall
.then(function() { .navigateWithDirectoryTree(windowId, '/destination', 'Downloads')
// Confirm files before paste. .then(function() {
return remoteCall.waitForFiles(windowId, ITEMS_IN_DEST_DIR_BEFORE_PASTE, // Confirm files before paste.
{ignoreLastModifiedTime: true}); return remoteCall.waitForFiles(
}).then(function() { windowId, ITEMS_IN_DEST_DIR_BEFORE_PASTE,
// Paste {ignoreLastModifiedTime: true});
return remoteCall.callRemoteTestUtil('fakeKeyDown', windowId, })
['body', 'v', 'U+0056' /* v */, true /* ctrl */, false, false]); .then(function() {
}).then(function() { // Paste
// Confirm the photos directory is pasted correctly. return remoteCall.callRemoteTestUtil(
return remoteCall.waitForFiles(windowId, ITEMS_IN_DEST_DIR_AFTER_PASTE, 'fakeKeyDown', windowId,
{ignoreLastModifiedTime: true}); ['body', 'v', 'U+0056' /* v */, true /* ctrl */, false, false]);
}); })
.then(function() {
// Confirm the photos directory is pasted correctly.
return remoteCall.waitForFiles(
windowId, ITEMS_IN_DEST_DIR_AFTER_PASTE,
{ignoreLastModifiedTime: true});
});
} }
/** /**
...@@ -193,7 +126,8 @@ function renameDirectoryFromDirectoryTreeSuccessCase(useKeyboardShortcut) { ...@@ -193,7 +126,8 @@ function renameDirectoryFromDirectoryTreeSuccessCase(useKeyboardShortcut) {
var windowId; var windowId;
return setupForDirectoryTreeContextMenuTest().then(function(id) { return setupForDirectoryTreeContextMenuTest().then(function(id) {
windowId = id; windowId = id;
return navigateWithDirectoryTree(windowId, '/photos', 'Downloads'); return remoteCall.navigateWithDirectoryTree(
windowId, '/photos', 'Downloads');
}).then(function() { }).then(function() {
return renamePhotosDirectoryTo(windowId, 'New photos', useKeyboardShortcut); return renamePhotosDirectoryTo(windowId, 'New photos', useKeyboardShortcut);
}).then(function() { }).then(function() {
...@@ -210,7 +144,8 @@ function renameDirectoryFromDirectoryTreeAndConfirmAlertDialog(newName) { ...@@ -210,7 +144,8 @@ function renameDirectoryFromDirectoryTreeAndConfirmAlertDialog(newName) {
var windowId; var windowId;
return setupForDirectoryTreeContextMenuTest().then(function(id) { return setupForDirectoryTreeContextMenuTest().then(function(id) {
windowId = id; windowId = id;
return navigateWithDirectoryTree(windowId, '/photos', 'Downloads'); return remoteCall.navigateWithDirectoryTree(
windowId, '/photos', 'Downloads');
}).then(function() { }).then(function() {
return renamePhotosDirectoryTo(windowId, newName, false); return renamePhotosDirectoryTo(windowId, newName, false);
}).then(function() { }).then(function() {
...@@ -229,9 +164,10 @@ function createDirectoryFromDirectoryTree( ...@@ -229,9 +164,10 @@ function createDirectoryFromDirectoryTree(
windowId = id; windowId = id;
if (changeCurrentDirectory) if (changeCurrentDirectory)
return navigateWithDirectoryTree(windowId, '/photos', 'Downloads'); return remoteCall.navigateWithDirectoryTree(
windowId, '/photos', 'Downloads');
else else
return expandDownloadVolumeInDirectoryTree(windowId); return remoteCall.expandDownloadVolumeInDirectoryTree(windowId);
}).then(function() { }).then(function() {
if (useKeyboardShortcut) { if (useKeyboardShortcut) {
return remoteCall.callRemoteTestUtil('fakeKeyDown', windowId, return remoteCall.callRemoteTestUtil('fakeKeyDown', windowId,
...@@ -259,7 +195,8 @@ function createDirectoryFromDirectoryTree( ...@@ -259,7 +195,8 @@ function createDirectoryFromDirectoryTree(
windowId, changeCurrentDirectory ? '/Downloads/photos' : '/Downloads'); windowId, changeCurrentDirectory ? '/Downloads/photos' : '/Downloads');
}).then(function() { }).then(function() {
// Confirm that new directory is actually created by navigating to it. // Confirm that new directory is actually created by navigating to it.
return navigateWithDirectoryTree(windowId, '/photos/test', 'Downloads'); return remoteCall.navigateWithDirectoryTree(
windowId, '/photos/test', 'Downloads');
}); });
} }
...@@ -270,7 +207,8 @@ testcase.dirCopyWithContextMenu = function() { ...@@ -270,7 +207,8 @@ testcase.dirCopyWithContextMenu = function() {
var windowId; var windowId;
testPromise(setupForDirectoryTreeContextMenuTest().then(function(id) { testPromise(setupForDirectoryTreeContextMenuTest().then(function(id) {
windowId = id; windowId = id;
return navigateWithDirectoryTree(windowId, '/photos', 'Downloads'); return remoteCall.navigateWithDirectoryTree(
windowId, '/photos', 'Downloads');
}).then(function() { }).then(function() {
return clickDirectoryTreeContextMenuItem(windowId, '/photos', 'copy'); return clickDirectoryTreeContextMenuItem(windowId, '/photos', 'copy');
}).then(function() { }).then(function() {
...@@ -285,7 +223,8 @@ testcase.dirCopyWithKeyboard = function() { ...@@ -285,7 +223,8 @@ testcase.dirCopyWithKeyboard = function() {
var windowId; var windowId;
testPromise(setupForDirectoryTreeContextMenuTest().then(function(id) { testPromise(setupForDirectoryTreeContextMenuTest().then(function(id) {
windowId = id; windowId = id;
return navigateWithDirectoryTree(windowId, '/photos', 'Downloads'); return remoteCall.navigateWithDirectoryTree(
windowId, '/photos', 'Downloads');
}).then(function() { }).then(function() {
// Press Ctrl+C. // Press Ctrl+C.
return remoteCall.callRemoteTestUtil('fakeKeyDown', windowId, return remoteCall.callRemoteTestUtil('fakeKeyDown', windowId,
...@@ -302,7 +241,7 @@ testcase.dirCopyWithoutChangingCurrent = function() { ...@@ -302,7 +241,7 @@ testcase.dirCopyWithoutChangingCurrent = function() {
var windowId; var windowId;
testPromise(setupForDirectoryTreeContextMenuTest().then(function(id) { testPromise(setupForDirectoryTreeContextMenuTest().then(function(id) {
windowId = id; windowId = id;
return expandDownloadVolumeInDirectoryTree(windowId); return remoteCall.expandDownloadVolumeInDirectoryTree(windowId);
}).then(function() { }).then(function() {
return clickDirectoryTreeContextMenuItem(windowId, '/photos', 'copy'); return clickDirectoryTreeContextMenuItem(windowId, '/photos', 'copy');
}).then(function() { }).then(function() {
...@@ -317,7 +256,8 @@ testcase.dirCutWithContextMenu = function() { ...@@ -317,7 +256,8 @@ testcase.dirCutWithContextMenu = function() {
var windowId; var windowId;
testPromise(setupForDirectoryTreeContextMenuTest().then(function(id) { testPromise(setupForDirectoryTreeContextMenuTest().then(function(id) {
windowId = id; windowId = id;
return navigateWithDirectoryTree(windowId, '/photos', 'Downloads'); return remoteCall.navigateWithDirectoryTree(
windowId, '/photos', 'Downloads');
}).then(function() { }).then(function() {
return clickDirectoryTreeContextMenuItem(windowId, '/photos', 'cut'); return clickDirectoryTreeContextMenuItem(windowId, '/photos', 'cut');
}).then(function() { }).then(function() {
...@@ -336,7 +276,8 @@ testcase.dirCutWithKeyboard = function() { ...@@ -336,7 +276,8 @@ testcase.dirCutWithKeyboard = function() {
var windowId; var windowId;
testPromise(setupForDirectoryTreeContextMenuTest().then(function(id) { testPromise(setupForDirectoryTreeContextMenuTest().then(function(id) {
windowId = id; windowId = id;
return navigateWithDirectoryTree(windowId, '/photos', 'Downloads'); return remoteCall.navigateWithDirectoryTree(
windowId, '/photos', 'Downloads');
}).then(function() { }).then(function() {
// Press Ctrl+X. // Press Ctrl+X.
return remoteCall.callRemoteTestUtil('fakeKeyDown', windowId, return remoteCall.callRemoteTestUtil('fakeKeyDown', windowId,
...@@ -357,7 +298,7 @@ testcase.dirCutWithoutChangingCurrent = function() { ...@@ -357,7 +298,7 @@ testcase.dirCutWithoutChangingCurrent = function() {
var windowId; var windowId;
testPromise(setupForDirectoryTreeContextMenuTest().then(function(id) { testPromise(setupForDirectoryTreeContextMenuTest().then(function(id) {
windowId = id; windowId = id;
return expandDownloadVolumeInDirectoryTree(windowId); return remoteCall.expandDownloadVolumeInDirectoryTree(windowId);
}).then(function() { }).then(function() {
return clickDirectoryTreeContextMenuItem(windowId, '/photos', 'cut'); return clickDirectoryTreeContextMenuItem(windowId, '/photos', 'cut');
}).then(function() { }).then(function() {
...@@ -373,38 +314,55 @@ testcase.dirCutWithoutChangingCurrent = function() { ...@@ -373,38 +314,55 @@ testcase.dirCutWithoutChangingCurrent = function() {
*/ */
testcase.dirPasteWithContextMenu = function() { testcase.dirPasteWithContextMenu = function() {
var windowId; var windowId;
testPromise(setupForDirectoryTreeContextMenuTest().then(function(id) { testPromise(
// Copy photos directory as a test data. setupForDirectoryTreeContextMenuTest()
windowId = id; .then(function(id) {
return navigateWithDirectoryTree(windowId, '/photos', 'Downloads'); // Copy photos directory as a test data.
}).then(function() { windowId = id;
return remoteCall.callRemoteTestUtil('fakeKeyDown', windowId, return remoteCall.navigateWithDirectoryTree(
['body', 'c', 'U+0043' /* c */, true /* ctrl */, false, false]); windowId, '/photos', 'Downloads');
}).then(function() { })
return navigateWithDirectoryTree(windowId, '/destination', 'Downloads'); .then(function() {
}).then(function() { return remoteCall.callRemoteTestUtil(
// Confirm files before paste. 'fakeKeyDown', windowId,
return remoteCall.waitForFiles(windowId, ITEMS_IN_DEST_DIR_BEFORE_PASTE, ['body', 'c', 'U+0043' /* c */, true /* ctrl */, false, false]);
{ignoreLastModifiedTime: true}); })
}).then(function() { .then(function() {
return clickDirectoryTreeContextMenuItem( return remoteCall.navigateWithDirectoryTree(
windowId, '/destination', 'paste-into-folder'); windowId, '/destination', 'Downloads');
}).then(function() { })
// Confirm the photos directory is pasted correctly. .then(function() {
return remoteCall.waitForFiles(windowId, ITEMS_IN_DEST_DIR_AFTER_PASTE, // Confirm files before paste.
{ignoreLastModifiedTime: true}); return remoteCall.waitForFiles(
}).then(function() { windowId, ITEMS_IN_DEST_DIR_BEFORE_PASTE,
// Expand the directory tree. {ignoreLastModifiedTime: true});
return remoteCall.waitForElement(windowId, })
'[full-path-for-testing="/destination"] .expand-icon'); .then(function() {
}).then(function() { return clickDirectoryTreeContextMenuItem(
return remoteCall.callRemoteTestUtil('fakeMouseClick', windowId, windowId, '/destination', 'paste-into-folder');
['[full-path-for-testing="/destination"] .expand-icon']); })
}).then(function() { .then(function() {
// Confirm the copied directory is added to the directory tree. // Confirm the photos directory is pasted correctly.
return remoteCall.waitForElement(windowId, return remoteCall.waitForFiles(
'[full-path-for-testing="/destination/photos"]'); windowId, ITEMS_IN_DEST_DIR_AFTER_PASTE,
})); {ignoreLastModifiedTime: true});
})
.then(function() {
// Expand the directory tree.
return remoteCall.waitForElement(
windowId,
'[full-path-for-testing="/destination"] .expand-icon');
})
.then(function() {
return remoteCall.callRemoteTestUtil(
'fakeMouseClick', windowId,
['[full-path-for-testing="/destination"] .expand-icon']);
})
.then(function() {
// Confirm the copied directory is added to the directory tree.
return remoteCall.waitForElement(
windowId, '[full-path-for-testing="/destination/photos"]');
}));
}; };
/** /**
...@@ -414,7 +372,7 @@ testcase.dirPasteWithoutChangingCurrent = function() { ...@@ -414,7 +372,7 @@ testcase.dirPasteWithoutChangingCurrent = function() {
var windowId; var windowId;
testPromise(setupForDirectoryTreeContextMenuTest().then(function(id) { testPromise(setupForDirectoryTreeContextMenuTest().then(function(id) {
windowId = id; windowId = id;
return expandDownloadVolumeInDirectoryTree(windowId); return remoteCall.expandDownloadVolumeInDirectoryTree(windowId);
}).then(function() { }).then(function() {
return clickDirectoryTreeContextMenuItem(windowId, '/photos', 'copy'); return clickDirectoryTreeContextMenuItem(windowId, '/photos', 'copy');
}).then(function() { }).then(function() {
...@@ -456,7 +414,7 @@ testcase.dirRenameWithoutChangingCurrent = function() { ...@@ -456,7 +414,7 @@ testcase.dirRenameWithoutChangingCurrent = function() {
var windowId; var windowId;
testPromise(setupForDirectoryTreeContextMenuTest().then(function(id) { testPromise(setupForDirectoryTreeContextMenuTest().then(function(id) {
windowId = id; windowId = id;
return expandDownloadVolumeInDirectoryTree(windowId); return remoteCall.expandDownloadVolumeInDirectoryTree(windowId);
}).then(function() { }).then(function() {
return remoteCall.waitForElement( return remoteCall.waitForElement(
windowId, '[full-path-for-testing="/photos"]'); windowId, '[full-path-for-testing="/photos"]');
......
...@@ -436,6 +436,104 @@ RemoteCallFilesApp.prototype.waitUntilCurrentDirectoryIsChanged = function( ...@@ -436,6 +436,104 @@ RemoteCallFilesApp.prototype.waitUntilCurrentDirectoryIsChanged = function(
}.bind(this)); }.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. * 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