1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 * Test function to copy from the specified source to the specified destination.
9 * @param {TestEntryInfo} targetFile TestEntryInfo of target file to be copied.
10 * @param {string} srcName Type of source volume. e.g. downloads, drive,
11 * drive_recent, drive_shared_with_me, drive_offline.
12 * @param {Array.<TestEntryInfo>} srcEntries Expected initial contents in the
14 * @param {string} dstName Type of destination volume.
15 * @param {Array.<TestEntryInfo>} dstEntries Expected initial contents in the
18 function copyBetweenVolumes(targetFile,
23 var srcContents = TestEntryInfo.getExpectedRows(srcEntries).sort();
24 var dstContents = TestEntryInfo.getExpectedRows(dstEntries).sort();
28 // Set up File Manager.
30 setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
32 // Select the source volume.
35 remoteCall.callRemoteTestUtil(
36 'selectVolume', appId, [srcName], this.next);
38 // Wait for the expected files to appear in the file list.
40 chrome.test.assertTrue(result);
41 remoteCall.waitForFiles(appId, srcContents).then(this.next);
43 // Select the source file.
45 remoteCall.callRemoteTestUtil(
46 'selectFile', appId, [targetFile.nameText], this.next);
50 chrome.test.assertTrue(result);
51 remoteCall.callRemoteTestUtil('execCommand', appId, ['copy'], this.next);
53 // Select the destination volume.
55 chrome.test.assertTrue(result);
56 remoteCall.callRemoteTestUtil(
57 'selectVolume', appId, [dstName], this.next);
59 // Wait for the expected files to appear in the file list.
61 chrome.test.assertTrue(result);
62 remoteCall.waitForFiles(appId, dstContents).then(this.next);
66 remoteCall.callRemoteTestUtil('execCommand', appId, ['paste'], this.next);
68 // Wait for the file list to change.
70 chrome.test.assertTrue(result);
72 srcName == 'drive_shared_with_me' ||
73 srcName == 'drive_offline' ||
74 dstName == 'drive_shared_with_me' ||
75 dstName == 'drive_offline';
76 var dstContentsAfterPaste = dstContents.slice();
77 var pasteFile = targetFile.getExpectedRow();
78 for (var i = 0; i < dstContentsAfterPaste.length; i++) {
79 if (dstContentsAfterPaste[i][0] === pasteFile[0]) {
80 // Replace the last '.' in filename with ' (1).'.
81 // e.g. 'my.note.txt' -> 'my.note (1).txt'
82 pasteFile[0] = pasteFile[0].replace(/\.(?=[^\.]+$)/, ' (1).');
86 dstContentsAfterPaste.push(pasteFile);
87 remoteCall.waitForFiles(appId, dstContentsAfterPaste, {
88 ignoreFileSize: ignoreFileSize,
89 ignoreLastModifiedTime: true
92 // Check the last contents of file list.
94 checkIfNoErrorsOccured(this.next);
100 * Tests copy from drive's root to local's downloads.
102 testcase.transferFromDriveToDownloads = copyBetweenVolumes.bind(
106 BASIC_DRIVE_ENTRY_SET,
108 BASIC_LOCAL_ENTRY_SET);
111 * Tests copy from local's downloads to drive's root.
113 testcase.transferFromDownloadsToDrive = copyBetweenVolumes.bind(
117 BASIC_LOCAL_ENTRY_SET,
119 BASIC_DRIVE_ENTRY_SET);
122 * Tests copy from drive's shared_with_me to local's downloads.
124 testcase.transferFromSharedToDownloads = copyBetweenVolumes.bind(
126 ENTRIES.testSharedDocument,
127 'drive_shared_with_me',
128 SHARED_WITH_ME_ENTRY_SET,
130 BASIC_LOCAL_ENTRY_SET);
133 * Tests copy from drive's shared_with_me to drive's root.
135 testcase.transferFromSharedToDrive = copyBetweenVolumes.bind(
137 ENTRIES.testSharedDocument,
138 'drive_shared_with_me',
139 SHARED_WITH_ME_ENTRY_SET,
141 BASIC_DRIVE_ENTRY_SET);
144 * Tests copy from drive's recent to local's downloads.
146 testcase.transferFromRecentToDownloads = copyBetweenVolumes.bind(
152 BASIC_LOCAL_ENTRY_SET);
155 * Tests copy from drive's recent to drive's root.
157 testcase.transferFromRecentToDrive = copyBetweenVolumes.bind(
163 BASIC_DRIVE_ENTRY_SET);
166 * Tests copy from drive's offline to local's downloads.
168 testcase.transferFromOfflineToDownloads = copyBetweenVolumes.bind(
170 ENTRIES.testDocument,
174 BASIC_LOCAL_ENTRY_SET);
177 * Tests copy from drive's offline to drive's root.
179 testcase.transferFromOfflineToDrive = copyBetweenVolumes.bind(
181 ENTRIES.testDocument,
185 BASIC_DRIVE_ENTRY_SET);