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 waitForElement(windowIds[0], '#detail-table'),
20 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 waitForFiles(windowId1, [file.getExpectedRow()]).
38 return callRemoteTestUtil('selectFile', windowId1, [file.nameText]);
40 then(function(result) {
41 chrome.test.assertTrue(result);
42 callRemoteTestUtil('execCommand', windowId1, ['copy']);
45 return waitForFiles(windowId2, []);
49 return callRemoteTestUtil('execCommand', windowId2, ['paste']);
52 return waitForFiles(windowId2,
53 [file.getExpectedRow()],
54 {ignoreLastModifiedTime: true});
58 var REMOVABLE_VOLUME_QUERY = '#directory-tree > .tree-item > .tree-row ' +
59 '.volume-icon[volume-type-icon="removable"]';
61 testcase.copyBetweenWindowsDriveToLocal = function() {
65 // Make a file in a drive directory.
67 addEntries(['drive'], [ENTRIES.hello], this.next);
71 chrome.test.assertTrue(result);
72 openTwoWindows(RootPath.DRIVE, RootPath.DOWNLOADS).then(this.next);
74 // Wait for a file in the Drive directory.
76 windowId1 = appIds[0];
77 windowId2 = appIds[1];
78 waitForFiles(windowId1,
79 [ENTRIES.hello.getExpectedRow()]).then(this.next);
81 // Copy a file between windows.
83 copyBetweenWindows(windowId1,
85 ENTRIES.hello).then(this.next);
88 checkIfNoErrorsOccured(this.next);
93 testcase.copyBetweenWindowsDriveToUsb = function() {
97 // Make a file in a drive directory.
99 addEntries(['drive'], [ENTRIES.hello], this.next);
103 chrome.test.assertTrue(result);
104 openTwoWindows(RootPath.DRIVE, RootPath.DRIVE).then(this.next);
106 // Wait for a file in the Drive directory.
108 windowId1 = appIds[0];
109 windowId2 = appIds[1];
110 waitForFiles(windowId1,
111 [ENTRIES.hello.getExpectedRow()]).then(this.next);
113 // Mount a fake USB volume.
115 chrome.test.sendMessage(JSON.stringify({name: 'mountFakeUsb'}),
118 // Wait for the mount.
120 waitForElement(windowId2, REMOVABLE_VOLUME_QUERY).then(this.next);
122 // Click the USB volume.
125 'fakeMouseClick', windowId2, [REMOVABLE_VOLUME_QUERY], this.next);
127 // Copy a file between windows.
129 copyBetweenWindows(windowId1, windowId2, ENTRIES.hello).then(this.next);
132 checkIfNoErrorsOccured(this.next);
137 testcase.copyBetweenWindowsLocalToDrive = function() {
141 // Make a file in a local directory.
143 addEntries(['local'], [ENTRIES.hello], this.next);
147 chrome.test.assertTrue(result);
148 openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE).then(this.next);
150 // Copy a file between windows.
152 copyBetweenWindows(appIds[0], appIds[1], ENTRIES.hello).then(this.next);
155 checkIfNoErrorsOccured(this.next);
160 testcase.copyBetweenWindowsLocalToUsb = function() {
164 // Make a file in a local directory.
166 addEntries(['local'], [ENTRIES.hello], this.next);
170 chrome.test.assertTrue(result);
171 openTwoWindows(RootPath.DOWNLOADS, RootPath.DOWNLOADS).then(this.next);
173 // Wait for a file in the Downloads directory.
175 windowId1 = appIds[0];
176 windowId2 = appIds[1];
177 waitForFiles(windowId2, [ENTRIES.hello.getExpectedRow()]).then(this.next);
179 // Mount a fake USB volume.
181 chrome.test.sendMessage(JSON.stringify({name: 'mountFakeUsb'}),
184 // Wait for the mount.
186 waitForElement(windowId2, REMOVABLE_VOLUME_QUERY).then(this.next);
188 // Click the USB volume.
191 'fakeMouseClick', windowId2, [REMOVABLE_VOLUME_QUERY], this.next);
193 // Copy a file between windows.
195 copyBetweenWindows(windowId1, windowId2, ENTRIES.hello).then(this.next);
200 testcase.copyBetweenWindowsUsbToDrive = function() {
206 openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE).then(this.next);
210 windowId1 = appIds[0];
211 windowId2 = appIds[1];
212 chrome.test.sendMessage(JSON.stringify({name: 'mountFakeUsb'}),
215 // Add a file to USB.
217 chrome.test.assertTrue(JSON.parse(result));
218 addEntries(['usb'], [ENTRIES.hello], this.next);
220 // Wait for the mount.
222 chrome.test.assertTrue(result);
223 waitForElement(windowId1, REMOVABLE_VOLUME_QUERY).then(this.next);
228 'fakeMouseClick', windowId1, [REMOVABLE_VOLUME_QUERY], this.next);
230 // Copy a file between windows.
232 copyBetweenWindows(windowId1, windowId2, ENTRIES.hello).then(this.next);
237 testcase.copyBetweenWindowsUsbToLocal = function() {
243 openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE).then(this.next);
247 windowId1 = appIds[0];
248 windowId2 = appIds[1];
249 chrome.test.sendMessage(JSON.stringify({name: 'mountFakeUsb'}),
252 // Add a file to USB.
254 chrome.test.assertTrue(JSON.parse(result));
255 addEntries(['usb'], [ENTRIES.hello], this.next);
257 // Wait for the mount.
259 chrome.test.assertTrue(result);
260 waitForElement(windowId1, REMOVABLE_VOLUME_QUERY).then(this.next);
265 'fakeMouseClick', windowId1, [REMOVABLE_VOLUME_QUERY], this.next);
267 // Copy a file between windows.
269 copyBetweenWindows(windowId1, windowId2, ENTRIES.hello).then(this.next);
272 checkIfNoErrorsOccured(this.next);