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 * Opens two window of given root paths.
9 * @param {string} rootPath1 Root path of the first window.
10 * @param {string} rootPath2 Root path of the second window.
11 * @return {Promise} Promise fulfilled with an array containing two window IDs.
13 function openTwoWindows(rootPath1, rootPath2) {
15 openNewWindow(null, rootPath1),
16 openNewWindow(null, rootPath2)
17 ]).then(function(windowIds) {
19 remoteCall.waitForElement(windowIds[0], '#detail-table'),
20 remoteCall.waitForElement(windowIds[1], '#detail-table'),
28 * Copies a file between two windows.
29 * @param {string} windowId1 ID of the source window.
30 * @param {string} windowId2 ID of the destination window.
31 * @param {TestEntryInfo} file Test entry info to be copied.
32 * @return {Promise} Promise fulfilled on success.
34 function copyBetweenWindows(windowId1, windowId2, file) {
36 return remoteCall.waitForFiles(windowId1, [file.getExpectedRow()]).
38 return remoteCall.callRemoteTestUtil('selectFile',
42 then(function(result) {
43 chrome.test.assertTrue(result);
44 remoteCall.callRemoteTestUtil('execCommand', windowId1, ['copy']);
47 return remoteCall.waitForFiles(windowId2, []);
51 return remoteCall.callRemoteTestUtil('execCommand', windowId2, ['paste']);
54 return remoteCall.waitForFiles(windowId2,
55 [file.getExpectedRow()],
56 {ignoreLastModifiedTime: true});
60 var REMOVABLE_VOLUME_QUERY = '#directory-tree > .tree-item > .tree-row ' +
61 '.volume-icon[volume-type-icon="removable"]';
63 testcase.copyBetweenWindowsDriveToLocal = function() {
67 // Make a file in a drive directory.
69 addEntries(['drive'], [ENTRIES.hello], this.next);
73 chrome.test.assertTrue(result);
74 openTwoWindows(RootPath.DRIVE, RootPath.DOWNLOADS).then(this.next);
76 // Wait for a file in the Drive directory.
78 windowId1 = appIds[0];
79 windowId2 = appIds[1];
80 remoteCall.waitForFiles(
82 [ENTRIES.hello.getExpectedRow()]).then(this.next);
84 // Copy a file between windows.
86 copyBetweenWindows(windowId1,
88 ENTRIES.hello).then(this.next);
91 checkIfNoErrorsOccured(this.next);
96 testcase.copyBetweenWindowsDriveToUsb = function() {
100 // Make a file in a drive directory.
102 addEntries(['drive'], [ENTRIES.hello], this.next);
106 chrome.test.assertTrue(result);
107 openTwoWindows(RootPath.DRIVE, RootPath.DRIVE).then(this.next);
109 // Wait for a file in the Drive directory.
111 windowId1 = appIds[0];
112 windowId2 = appIds[1];
113 remoteCall.waitForFiles(
115 [ENTRIES.hello.getExpectedRow()]).then(this.next);
117 // Mount a fake USB volume.
119 chrome.test.sendMessage(JSON.stringify({name: 'mountFakeUsb'}),
122 // Wait for the mount.
124 remoteCall.waitForElement(windowId2, REMOVABLE_VOLUME_QUERY).
127 // Click the USB volume.
129 remoteCall.callRemoteTestUtil(
130 'fakeMouseClick', windowId2, [REMOVABLE_VOLUME_QUERY], this.next);
132 // Copy a file between windows.
134 copyBetweenWindows(windowId1, windowId2, ENTRIES.hello).then(this.next);
137 checkIfNoErrorsOccured(this.next);
142 testcase.copyBetweenWindowsLocalToDrive = function() {
146 // Make a file in a local directory.
148 addEntries(['local'], [ENTRIES.hello], this.next);
152 chrome.test.assertTrue(result);
153 openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE).then(this.next);
155 // Copy a file between windows.
157 copyBetweenWindows(appIds[0], appIds[1], ENTRIES.hello).then(this.next);
160 checkIfNoErrorsOccured(this.next);
165 testcase.copyBetweenWindowsLocalToUsb = function() {
169 // Make a file in a local directory.
171 addEntries(['local'], [ENTRIES.hello], this.next);
175 chrome.test.assertTrue(result);
176 openTwoWindows(RootPath.DOWNLOADS, RootPath.DOWNLOADS).then(this.next);
178 // Wait for a file in the Downloads directory.
180 windowId1 = appIds[0];
181 windowId2 = appIds[1];
182 remoteCall.waitForFiles(windowId2, [ENTRIES.hello.getExpectedRow()]).
185 // Mount a fake USB volume.
187 chrome.test.sendMessage(JSON.stringify({name: 'mountFakeUsb'}),
190 // Wait for the mount.
192 remoteCall.waitForElement(windowId2, REMOVABLE_VOLUME_QUERY).
195 // Click the USB volume.
197 remoteCall.callRemoteTestUtil(
198 'fakeMouseClick', windowId2, [REMOVABLE_VOLUME_QUERY], this.next);
200 // Copy a file between windows.
202 copyBetweenWindows(windowId1, windowId2, ENTRIES.hello).then(this.next);
207 testcase.copyBetweenWindowsUsbToDrive = function() {
213 openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE).then(this.next);
217 windowId1 = appIds[0];
218 windowId2 = appIds[1];
219 chrome.test.sendMessage(JSON.stringify({name: 'mountFakeUsb'}),
222 // Add a file to USB.
224 addEntries(['usb'], [ENTRIES.hello], this.next);
226 // Wait for the mount.
228 chrome.test.assertTrue(result);
229 remoteCall.waitForElement(windowId1, REMOVABLE_VOLUME_QUERY).
234 remoteCall.callRemoteTestUtil(
235 'fakeMouseClick', windowId1, [REMOVABLE_VOLUME_QUERY], this.next);
237 // Copy a file between windows.
239 copyBetweenWindows(windowId1, windowId2, ENTRIES.hello).then(this.next);
244 testcase.copyBetweenWindowsUsbToLocal = function() {
250 openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE).then(this.next);
254 windowId1 = appIds[0];
255 windowId2 = appIds[1];
256 chrome.test.sendMessage(JSON.stringify({name: 'mountFakeUsb'}),
259 // Add a file to USB.
261 addEntries(['usb'], [ENTRIES.hello], this.next);
263 // Wait for the mount.
265 chrome.test.assertTrue(result);
266 remoteCall.waitForElement(windowId1, REMOVABLE_VOLUME_QUERY).
271 remoteCall.callRemoteTestUtil(
272 'fakeMouseClick', windowId1, [REMOVABLE_VOLUME_QUERY], this.next);
274 // Copy a file between windows.
276 copyBetweenWindows(windowId1, windowId2, ENTRIES.hello).then(this.next);
279 checkIfNoErrorsOccured(this.next);