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