Index: chrome/test/data/extensions/api_test/file_manager_browsertest/keyboard_operations.js |
diff --git a/chrome/test/data/extensions/api_test/file_manager_browsertest/keyboard_operations.js b/chrome/test/data/extensions/api_test/file_manager_browsertest/keyboard_operations.js |
index 8709bec3bdfd3ea46442db673fa89ecbb2ff0de6..286102d3970d49831cfa17be72c8dba8307edaf4 100644 |
--- a/chrome/test/data/extensions/api_test/file_manager_browsertest/keyboard_operations.js |
+++ b/chrome/test/data/extensions/api_test/file_manager_browsertest/keyboard_operations.js |
@@ -135,7 +135,8 @@ function testPromise(promise) { |
promise.then(function() { |
return new Promise(checkIfNoErrorsOccured); |
}).then(chrome.test.callbackPass(function() { |
- chrome.test.succeed(); |
+ // The callbacPass is necessary to avoid prematurely finishing tests. |
+ // Don't put chrome.test.succeed() here to avoid doubled success log. |
}), function(error) { |
chrome.test.fail(error.stack || error); |
}); |
@@ -183,6 +184,79 @@ function createNewFolder(path, initialEntrySet) { |
}); |
}; |
+/** |
+ * Renames a file. |
+ * @param {string} windowId ID of the window. |
+ * @param {string} oldName Old name of a file. |
+ * @param {string} newName New name of a file. |
+ * @return {Promise} Promise to be fulfilled on success. |
+ */ |
+function renameFile(windowId, oldName, newName) { |
+ return callRemoteTestUtil('selectFile', windowId, [oldName]).then(function() { |
+ // Push Ctrl+Enter. |
+ return fakeKeyDown(windowId, '#detail-table', 'Enter', true); |
+ }).then(function() { |
+ // Wait for rename text field. |
+ return waitForElement(windowId, 'input.rename'); |
+ }).then(function() { |
+ // Type new file name. |
+ return callRemoteTestUtil('inputText', windowId, ['input.rename', newName]); |
+ }).then(function() { |
+ // Push Enter. |
+ return fakeKeyDown(windowId, 'input.rename', 'Enter', false); |
+ }); |
+} |
+ |
+/** |
+ * Test for renaming a file. |
+ * @param {string} path Initial path. |
+ * @param {Array.<TestEntryInfo>} initialEntrySet Initial set of entries. |
+ * @return {Promise} Promise to be fulfilled on success. |
+ */ |
+function testRenameFile(path, initialEntrySet) { |
+ var windowId; |
+ |
+ // Make expected rows. |
+ var initialExpectedEntryRows = TestEntryInfo.getExpectedRows(initialEntrySet); |
+ var expectedEntryRows = TestEntryInfo.getExpectedRows(initialEntrySet); |
+ for (var i = 0; i < expectedEntryRows.length; i++) { |
+ if (expectedEntryRows[i][0] === 'hello.txt') { |
+ expectedEntryRows[i][0] = 'New File Name.txt'; |
+ break; |
+ } |
+ } |
+ chrome.test.assertTrue( |
+ i != expectedEntryRows.length, 'hello.txt is not found.'); |
+ |
+ // Open a window. |
+ return new Promise(function(callback) { |
+ setupAndWaitUntilReady(null, path, callback); |
+ }).then(function(inWindowId) { |
+ windowId = inWindowId; |
+ return waitForFiles(windowId, initialExpectedEntryRows); |
+ }).then(function(){ |
+ return renameFile(windowId, 'hello.txt', 'New File Name.txt'); |
+ }).then(function() { |
+ // Wait until rename completes. |
+ return waitForElementLost(windowId, '#detail-table [renaming]'); |
+ }).then(function() { |
+ // Wait for the new file name. |
+ return waitForFiles(windowId, |
+ expectedEntryRows, |
+ {ignoreLastModifiedTime: true}); |
+ }).then(function() { |
+ return renameFile(windowId, 'New File Name.txt', '.hidden file'); |
+ }).then(function() { |
+ // The error dialog is shown. |
+ return waitAndAcceptDialog(windowId); |
+ }).then(function() { |
+ // The name did not change. |
+ return waitForFiles(windowId, |
+ expectedEntryRows, |
+ {ignoreLastModifiedTime: true}); |
+ }); |
+}; |
+ |
testcase.keyboardCopyDownloads = function() { |
keyboardCopy(RootPath.DOWNLOADS); |
}; |
@@ -206,3 +280,11 @@ testcase.createNewFolderDownloads = function() { |
testcase.createNewFolderDrive = function() { |
testPromise(createNewFolder(RootPath.DRIVE, BASIC_DRIVE_ENTRY_SET)); |
}; |
+ |
+testcase.renameFileDownloads = function() { |
+ testPromise(testRenameFile(RootPath.DOWNLOADS, BASIC_LOCAL_ENTRY_SET)); |
+}; |
+ |
+testcase.renameFileDrive = function() { |
+ testPromise(testRenameFile(RootPath.DRIVE, BASIC_DRIVE_ENTRY_SET)); |
+}; |