Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6802)

Unified Diff: chrome/test/data/extensions/api_test/file_manager_browsertest/test_cases.js

Issue 16097003: drive: Stop using FilePathWatcher from FileManagerBrowserTest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment fix Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/extensions/file_manager/file_manager_browsertest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/extensions/api_test/file_manager_browsertest/test_cases.js
diff --git a/chrome/test/data/extensions/api_test/file_manager_browsertest/test_cases.js b/chrome/test/data/extensions/api_test/file_manager_browsertest/test_cases.js
index 1f5e5057aeee159b9c16e009f5839e87e413eb34..affbbf58bcde17a4fd94565eccd952023314a9df 100644
--- a/chrome/test/data/extensions/api_test/file_manager_browsertest/test_cases.js
+++ b/chrome/test/data/extensions/api_test/file_manager_browsertest/test_cases.js
@@ -116,6 +116,33 @@ var EXPECTED_FILES_IN_SHARED_WITH_ME = [
];
/**
+ * Returns the name of the given file list entry.
+ * @param {Array.<string>} file An entry in a file list.
+ * @return {string} Name of the file.
+ */
+function getFileName(fileListEntry) {
+ return fileListEntry[0];
+}
+
+/**
+ * Returns the size of the given file list entry.
+ * @param {Array.<string>} An entry in a file list.
+ * @return {string} Size of the file.
+ */
+function getFileSize(fileListEntry) {
+ return fileListEntry[1];
+}
+
+/**
+ * Returns the type of the given file list entry.
+ * @param {Array.<string>} An entry in a file list.
+ * @return {string} Type of the file.
+ */
+function getFileType(fileListEntry) {
+ return fileListEntry[2];
+}
+
+/**
* Namespace for test cases.
*/
var testcase = {};
@@ -221,16 +248,57 @@ testcase.intermediate.galleryOpen = function(path) {
* @param {string} path Directory path to be tested.
*/
testcase.intermediate.keyboardCopy = function(path, callback) {
- setupAndWaitUntilReady(path, function(appId) {
- callRemoteTestUtil('copyFile', appId, ['world.ogv'], function(result) {
- chrome.test.assertFalse(!result);
- callRemoteTestUtil('waitForFileListChange',
- appId,
- [getExpectedFilesBefore(path == '/drive/root').length],
- checkIfNoErrorsOccured.bind(null,
- chrome.test.succeed));
- });
- });
+ // Returns true if |fileList| contains a copy of |filename|.
+ var isCopyPresent = function(filename, fileList) {
+ var originalEntry;
+ for (var i = 0; i < fileList.length; i++) {
+ if (getFileName(fileList[i]) == filename)
+ originalEntry = fileList[i];
+ }
+ if (!originalEntry)
+ return false;
+
+ var baseName = filename.substring(0, filename.lastIndexOf('.'));
+ var extension = filename.substring(filename.lastIndexOf('.'));
+ var filenamePattern = new RegExp('^' + baseName + '.+' + extension + '$');
+ for (var i = 0; i < fileList.length; i++) {
+ // Check size, type and file name pattern to find a copy.
+ if (getFileSize(fileList[i]) == getFileSize(originalEntry) &&
+ getFileType(fileList[i]) == getFileType(originalEntry) &&
+ filenamePattern.exec(getFileName(fileList[i])))
+ return true;
+ }
+ return false;
+ }
+
+ var filename = 'world.ogv';
+ var appId, fileListBefore;
+ var steps = [
+ // Set up File Manager.
+ function() {
+ setupAndWaitUntilReady(path, steps.shift());
+ },
+ // Copy the file.
+ function(inAppId, inFileListBefore) {
+ appId = inAppId;
+ fileListBefore = inFileListBefore;
+ chrome.test.assertFalse(isCopyPresent(filename, fileListBefore));
+ callRemoteTestUtil('copyFile', appId, [filename], steps.shift());
+ },
+ // Wait for a file list change.
+ function(result) {
+ chrome.test.assertTrue(result);
+ callRemoteTestUtil('waitForFileListChange', appId,
+ [fileListBefore.length], steps.shift());
+ },
+ // Verify the result.
+ function(fileList) {
+ chrome.test.assertTrue(isCopyPresent(filename, fileList));
+ checkIfNoErrorsOccured(chrome.test.succeed);
+ }
+ ];
+ steps = steps.map(function(f) { return chrome.test.callbackPass(f); });
+ steps.shift()();
};
/**
@@ -238,18 +306,47 @@ testcase.intermediate.keyboardCopy = function(path, callback) {
* @param {string} path Directory path to be tested.
*/
testcase.intermediate.keyboardDelete = function(path) {
- setupAndWaitUntilReady(path, function(appId) {
- callRemoteTestUtil('deleteFile', appId, ['world.ogv'], function(result) {
- chrome.test.assertFalse(!result);
- callRemoteTestUtil('waitAndAcceptDialog', appId, [], function() {
- callRemoteTestUtil(
- 'waitForFileListChange',
- appId,
- [getExpectedFilesBefore(path == '/drive/root').length],
- checkIfNoErrorsOccured.bind(null, chrome.test.succeed));
- });
- });
- });
+ // Returns true if |fileList| contains |filename|.
+ var isFilePresent = function(filename, fileList) {
+ for (var i = 0; i < fileList.length; i++) {
+ if (getFileName(fileList[i]) == filename)
+ return true;
+ }
+ return false;
+ }
+
+ var filename = 'world.ogv';
+ var appId, fileListBefore;
+ var steps = [
+ // Set up File Manager.
+ function() {
+ setupAndWaitUntilReady(path, steps.shift());
+ },
+ // Delete the file.
+ function(inAppId, inFileListBefore) {
+ appId = inAppId;
+ fileListBefore = inFileListBefore;
+ chrome.test.assertTrue(isFilePresent(filename, fileListBefore));
+ callRemoteTestUtil('deleteFile', appId, [filename], steps.shift());
+ },
+ // Reply to a dialog.
+ function(result) {
+ chrome.test.assertTrue(result);
+ callRemoteTestUtil('waitAndAcceptDialog', appId, [], steps.shift());
+ },
+ // Wait for a file list change.
+ function() {
+ callRemoteTestUtil('waitForFileListChange', appId,
+ [fileListBefore.length], steps.shift());
+ },
+ // Verify the result.
+ function(fileList) {
+ chrome.test.assertFalse(isFilePresent(filename, fileList));
+ checkIfNoErrorsOccured(chrome.test.succeed);
+ }
+ ];
+ steps = steps.map(function(f) { return chrome.test.callbackPass(f); });
+ steps.shift()();
};
testcase.fileDisplayDownloads = function() {
« no previous file with comments | « chrome/browser/chromeos/extensions/file_manager/file_manager_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698