1c5b2f5b73622071e8e8662f01875d28234d01e1
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / file_manager_browsertest / file_manager / copy_between_windows.js
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.
4
5 'use strict';
6
7 /**
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.
12  */
13 function openTwoWindows(rootPath1, rootPath2) {
14   return Promise.all([
15     openNewWindow(null, rootPath1),
16     openNewWindow(null, rootPath2)
17   ]).then(function(windowIds) {
18     return Promise.all([
19       waitForElement(windowIds[0], '#detail-table'),
20       waitForElement(windowIds[1], '#detail-table'),
21     ]).then(function() {
22       return windowIds;
23     });
24   });
25 };
26
27 /**
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.
33  */
34 function copyBetweenWindows(windowId1, windowId2, file) {
35   // Select the file.
36   return waitForFiles(windowId1, [file.getExpectedRow()]).
37   then(function() {
38     return callRemoteTestUtil('selectFile', windowId1, [file.nameText]);
39   }).
40   then(function(result) {
41     chrome.test.assertTrue(result);
42     callRemoteTestUtil('execCommand', windowId1, ['copy']);
43   }).
44   then(function() {
45     return waitForFiles(windowId2, []);
46   }).
47   then(function() {
48     // Paste it.
49     return callRemoteTestUtil('execCommand', windowId2, ['paste']);
50   }).
51   then(function() {
52     return waitForFiles(windowId2,
53                         [file.getExpectedRow()],
54                         {ignoreLastModifiedTime: true});
55   });
56 };
57
58 var REMOVABLE_VOLUME_QUERY = '#directory-tree > .tree-item > .tree-row ' +
59     '.volume-icon[volume-type-icon="removable"]';
60
61 testcase.copyBetweenWindowsDriveToLocal = function() {
62   var windowId1;
63   var windowId2;
64   StepsRunner.run([
65       // Make a file in a drive directory.
66       function() {
67         addEntries(['drive'], [ENTRIES.hello], this.next);
68       },
69       // Open windows.
70       function(result) {
71         chrome.test.assertTrue(result);
72         openTwoWindows(RootPath.DRIVE, RootPath.DOWNLOADS).then(this.next);
73       },
74       // Wait for a file in the Drive directory.
75       function(appIds) {
76         windowId1 = appIds[0];
77         windowId2 = appIds[1];
78         waitForFiles(windowId1,
79                      [ENTRIES.hello.getExpectedRow()]).then(this.next);
80       },
81       // Copy a file between windows.
82       function() {
83         copyBetweenWindows(windowId1,
84                            windowId2,
85                            ENTRIES.hello).then(this.next);
86       },
87       function() {
88         checkIfNoErrorsOccured(this.next);
89       }
90   ]);
91 };
92
93 testcase.copyBetweenWindowsDriveToUsb = function() {
94   var windowId1;
95   var windowId2;
96   StepsRunner.run([
97       // Make a file in a drive directory.
98       function() {
99         addEntries(['drive'], [ENTRIES.hello], this.next);
100       },
101       // Open windows.
102       function(result) {
103         chrome.test.assertTrue(result);
104         openTwoWindows(RootPath.DRIVE, RootPath.DRIVE).then(this.next);
105       },
106       // Wait for a file in the Drive directory.
107       function(appIds) {
108         windowId1 = appIds[0];
109         windowId2 = appIds[1];
110         waitForFiles(windowId1,
111                      [ENTRIES.hello.getExpectedRow()]).then(this.next);
112       },
113       // Mount a fake USB volume.
114       function() {
115         chrome.test.sendMessage(JSON.stringify({name: 'mountFakeUsb'}),
116                                 this.next);
117       },
118       // Wait for the mount.
119       function(result) {
120         waitForElement(windowId2, REMOVABLE_VOLUME_QUERY).then(this.next);
121       },
122       // Click the USB volume.
123       function() {
124         callRemoteTestUtil(
125             'fakeMouseClick', windowId2, [REMOVABLE_VOLUME_QUERY], this.next);
126       },
127       // Copy a file between windows.
128       function(appIds) {
129         copyBetweenWindows(windowId1, windowId2, ENTRIES.hello).then(this.next);
130       },
131       function() {
132         checkIfNoErrorsOccured(this.next);
133       }
134     ]);
135 };
136
137 testcase.copyBetweenWindowsLocalToDrive = function() {
138   var windowId1;
139   var windowId2;
140   StepsRunner.run([
141     // Make a file in a local directory.
142     function() {
143       addEntries(['local'], [ENTRIES.hello], this.next);
144     },
145     // Open windows.
146     function(result) {
147       chrome.test.assertTrue(result);
148       openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE).then(this.next);
149     },
150     // Copy a file between windows.
151     function(appIds) {
152       copyBetweenWindows(appIds[0], appIds[1], ENTRIES.hello).then(this.next);
153     },
154     function() {
155       checkIfNoErrorsOccured(this.next);
156     }
157   ]);
158 };
159
160 testcase.copyBetweenWindowsLocalToUsb = function() {
161   var windowId1;
162   var windowId2;
163   StepsRunner.run([
164     // Make a file in a local directory.
165     function() {
166       addEntries(['local'], [ENTRIES.hello], this.next);
167     },
168     // Open windows.
169     function(result) {
170       chrome.test.assertTrue(result);
171       openTwoWindows(RootPath.DOWNLOADS, RootPath.DOWNLOADS).then(this.next);
172     },
173     // Wait for a file in the Downloads directory.
174     function(appIds) {
175       windowId1 = appIds[0];
176       windowId2 = appIds[1];
177       waitForFiles(windowId2, [ENTRIES.hello.getExpectedRow()]).then(this.next);
178     },
179     // Mount a fake USB volume.
180     function() {
181       chrome.test.sendMessage(JSON.stringify({name: 'mountFakeUsb'}),
182                               this.next);
183     },
184     // Wait for the mount.
185     function(result) {
186       waitForElement(windowId2, REMOVABLE_VOLUME_QUERY).then(this.next);
187     },
188     // Click the USB volume.
189     function() {
190       callRemoteTestUtil(
191           'fakeMouseClick', windowId2, [REMOVABLE_VOLUME_QUERY], this.next);
192     },
193     // Copy a file between windows.
194     function() {
195       copyBetweenWindows(windowId1, windowId2, ENTRIES.hello).then(this.next);
196     }
197   ]);
198 };
199
200 testcase.copyBetweenWindowsUsbToDrive = function() {
201   var windowId1;
202   var windowId2;
203   StepsRunner.run([
204     // Open windows.
205     function() {
206       openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE).then(this.next);
207     },
208     // Mount a fake USB.
209     function(appIds) {
210       windowId1 = appIds[0];
211       windowId2 = appIds[1];
212       chrome.test.sendMessage(JSON.stringify({name: 'mountFakeUsb'}),
213                               this.next);
214     },
215     // Add a file to USB.
216     function(result) {
217       chrome.test.assertTrue(JSON.parse(result));
218       addEntries(['usb'], [ENTRIES.hello], this.next);
219     },
220     // Wait for the mount.
221     function(result) {
222       chrome.test.assertTrue(result);
223       waitForElement(windowId1, REMOVABLE_VOLUME_QUERY).then(this.next);
224     },
225     // Click the volume.
226     function() {
227       callRemoteTestUtil(
228           'fakeMouseClick', windowId1, [REMOVABLE_VOLUME_QUERY], this.next);
229     },
230     // Copy a file between windows.
231     function() {
232       copyBetweenWindows(windowId1, windowId2, ENTRIES.hello).then(this.next);
233     }
234   ]);
235 };
236
237 testcase.copyBetweenWindowsUsbToLocal = function() {
238   var windowId1;
239   var windowId2;
240   StepsRunner.run([
241     // Open windows.
242     function() {
243       openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE).then(this.next);
244     },
245     // Mount a fake USB.
246     function(appIds) {
247       windowId1 = appIds[0];
248       windowId2 = appIds[1];
249       chrome.test.sendMessage(JSON.stringify({name: 'mountFakeUsb'}),
250                               this.next);
251     },
252     // Add a file to USB.
253     function(result) {
254       chrome.test.assertTrue(JSON.parse(result));
255       addEntries(['usb'], [ENTRIES.hello], this.next);
256     },
257     // Wait for the mount.
258     function(result) {
259       chrome.test.assertTrue(result);
260       waitForElement(windowId1, REMOVABLE_VOLUME_QUERY).then(this.next);
261     },
262     // Click the volume.
263     function() {
264       callRemoteTestUtil(
265           'fakeMouseClick', windowId1, [REMOVABLE_VOLUME_QUERY], this.next);
266     },
267     // Copy a file between windows.
268     function(appIds) {
269       copyBetweenWindows(windowId1, windowId2, ENTRIES.hello).then(this.next);
270     },
271     function() {
272       checkIfNoErrorsOccured(this.next);
273     }
274   ]);
275 };
276