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 * Constants for selectors.
10 var TREEITEM_DRIVE = '#directory-tree > div:nth-child(1) > .tree-children ' +
11 '> div:nth-child(1) ';
12 var TREEITEM_A = TREEITEM_DRIVE + '> .tree-children > div:nth-child(1) ';
13 var TREEITEM_B = TREEITEM_A + '> .tree-children > div:nth-child(1) ';
14 var TREEITEM_C = TREEITEM_B + '> .tree-children > div:nth-child(1) ';
15 var TREEITEM_D = TREEITEM_DRIVE + '> .tree-children > div:nth-child(2) ';
16 var TREEITEM_E = TREEITEM_D + '> .tree-children > div:nth-child(1) ';
17 var EXPAND_ICON = '> .tree-row > .expand-icon';
18 var VOLUME_ICON = '> .tree-row > .volume-icon';
19 var EXPANDED_SUBTREE = '> .tree-children[expanded]';
22 * Entry set which is used for this test.
23 * @type {Array.<TestEntryInfo>}
36 * Constants for each folders.
37 * @type {Array.<Object>}
42 contents: [ENTRIES.directoryA.getExpectedRow(),
43 ENTRIES.directoryD.getExpectedRow()],
45 navItem: '#tree-item-autogen-id-2',
46 treeItem: TREEITEM_DRIVE
49 contents: [ENTRIES.directoryB.getExpectedRow()],
51 navItem: '#tree-item-autogen-id-13',
55 contents: [ENTRIES.directoryC.getExpectedRow()],
62 navItem: '#tree-item-autogen-id-13',
66 contents: [ENTRIES.directoryE.getExpectedRow()],
68 navItem: '#tree-item-autogen-id-12',
72 contents: [ENTRIES.directoryF.getExpectedRow()],
79 * Opens two file manager windows.
80 * @return {Promise} Promise fulfilled with an array containing two window IDs.
82 function openWindows() {
84 openNewWindow(null, RootPath.DRIVE),
85 openNewWindow(null, RootPath.DRIVE)
86 ]).then(function(windowIds) {
88 remoteCall.waitForElement(windowIds[0], '#detail-table'),
89 remoteCall.waitForElement(windowIds[1], '#detail-table')
97 * Expands tree item on the directory tree by clicking expand icon.
98 * @param {string} windowId ID of target window.
99 * @param {Object} directory Directory whose tree item should be expanded.
100 * @return {Promise} Promise fulfilled on success.
102 function expandTreeItem(windowId, directory) {
103 return remoteCall.waitForElement(
104 windowId, directory.treeItem + EXPAND_ICON).then(function() {
105 return remoteCall.callRemoteTestUtil(
106 'fakeMouseClick', windowId, [directory.treeItem + EXPAND_ICON]);
107 }).then(function(result) {
108 chrome.test.assertTrue(result);
109 return remoteCall.waitForElement(windowId,
110 directory.treeItem + EXPANDED_SUBTREE);
115 * Expands whole directory tree.
116 * @param {string} windowId ID of target window.
117 * @return {Promise} Promise fulfilled on success.
119 function expandDirectoryTree(windowId) {
120 return expandTreeItem(windowId, DIRECTORY.Drive).then(function() {
121 return expandTreeItem(windowId, DIRECTORY.A);
123 return expandTreeItem(windowId, DIRECTORY.B);
125 return expandTreeItem(windowId, DIRECTORY.D);
130 * Makes |directory| the current directory.
131 * @param {string} windowId ID of target window.
132 * @param {Object} directory Directory which should be a current directory.
133 * @return {Promise} Promise fulfilled on success.
135 function navigateToDirectory(windowId, directory) {
136 return remoteCall.waitForElement(
137 windowId, directory.treeItem + VOLUME_ICON).then(function() {
138 return remoteCall.callRemoteTestUtil(
139 'fakeMouseClick', windowId, [directory.treeItem + VOLUME_ICON]);
140 }).then(function(result) {
141 chrome.test.assertTrue(result);
142 return remoteCall.waitForFiles(windowId, directory.contents);
147 * Creates folder shortcut to |directory|.
148 * The current directory must be a parent of the |directory|.
149 * @param {string} windowId ID of target window.
150 * @param {Object} directory Directory of shortcut to be created.
151 * @return {Promise} Promise fulfilled on success.
153 function createShortcut(windowId, directory) {
154 return remoteCall.callRemoteTestUtil(
155 'selectFile', windowId, [directory.name]).then(function(result) {
156 chrome.test.assertTrue(result);
157 return remoteCall.waitForElement(windowId, ['.table-row[selected]']);
159 return remoteCall.callRemoteTestUtil(
160 'fakeMouseRightClick', windowId, ['.table-row[selected]']);
161 }).then(function(result) {
162 chrome.test.assertTrue(result);
163 return remoteCall.waitForElement(
164 windowId, '#file-context-menu:not([hidden])');
166 return remoteCall.waitForElement(
167 windowId, '[command="#create-folder-shortcut"]');
169 return remoteCall.callRemoteTestUtil(
170 'fakeMouseClick', windowId, ['[command="#create-folder-shortcut"]']);
171 }).then(function(result) {
172 chrome.test.assertTrue(result);
173 return remoteCall.waitForElement(windowId, directory.navItem);
178 * Removes folder shortcut to |directory|.
179 * The current directory must be a parent of the |directory|.
180 * @param {string} windowId ID of target window.
181 * @param {Object} directory Directory of shortcut ot be removed.
182 * @return {Promise} Promise fullfilled on success.
184 function removeShortcut(windowId, directory) {
185 return remoteCall.callRemoteTestUtil(
186 'fakeMouseRightClick',
188 [directory.navItem]).then(function(result) {
189 chrome.test.assertTrue(result);
190 return remoteCall.waitForElement(
191 windowId, '#roots-context-menu:not([hidden])');
193 return remoteCall.waitForElement(
194 windowId, '[command="#remove-folder-shortcut"]');
196 return remoteCall.callRemoteTestUtil(
197 'fakeMouseClick', windowId, ['[command="#remove-folder-shortcut"]']);
198 }).then(function(result) {
199 chrome.test.assertTrue(result);
200 return remoteCall.waitForElementLost(windowId, directory.navItem);
205 * Waits until the current directory become |currentDir| and folder shortcut to
206 * |shortcutDir| is selected.
207 * @param {string} windowId ID of target window.
208 * @param {Object} currentDir Directory which should be a current directory.
209 * @param {Object} shortcutDir Directory whose shortcut should be selected.
210 * @return {Promise} Promise fullfilled on success.
212 function expectSelection(windowId, currentDir, shortcutDir) {
213 return remoteCall.waitForFiles(windowId, currentDir.contents).
215 return remoteCall.waitForElement(
216 windowId, shortcutDir.navItem + '[selected]');
221 * Clicks folder shortcut to |directory|.
222 * @param {string} windowId ID of target window.
223 * @param {Object} directory Directory whose shortcut will be clicked.
224 * @return {Promise} Promise fullfilled with result of fakeMouseClick.
226 function clickShortcut(windowId, directory) {
227 return remoteCall.waitForElement(windowId, directory.navItem).
229 return remoteCall.callRemoteTestUtil(
230 'fakeMouseClick', windowId, [directory.navItem]);
235 * Creates some shortcuts and traverse them and some other directories.
237 testcase.traverseFolderShortcuts = function() {
240 // Set up each window.
242 addEntries(['drive'], ENTRY_SET, this.next);
245 chrome.test.assertTrue(result);
246 openNewWindow(null, RootPath.DRIVE).then(this.next);
248 function(inWindowId) {
249 windowId = inWindowId;
250 remoteCall.waitForElement(windowId, '#detail-table').then(this.next);
253 expandDirectoryTree(windowId).then(this.next);
256 remoteCall.waitForFiles(windowId, DIRECTORY.Drive.contents).
260 // Create shortcut to D
262 createShortcut(windowId, DIRECTORY.D).then(this.next);
265 // Create sortcut to C
267 navigateToDirectory(windowId, DIRECTORY.B).then(this.next);
270 createShortcut(windowId, DIRECTORY.C).then(this.next);
273 // Click shortcut to drive.
274 // Current directory should be Drive root.
275 // Shortcut to Drive root should be selected.
277 clickShortcut(windowId, DIRECTORY.Drive).then(this.next);
281 windowId, DIRECTORY.Drive, DIRECTORY.Drive).then(this.next);
284 // Press Ctrl+4 to select 4th shortcut.
285 // Current directory should be D.
286 // Shortcut to C should be selected.
288 remoteCall.callRemoteTestUtil('fakeKeyDown', windowId,
289 ['#file-list', 'U+0034', true], this.next);
292 chrome.test.assertTrue(result);
293 expectSelection(windowId, DIRECTORY.D, DIRECTORY.D).then(this.next);
296 // Press UP to select 3rd shortcut.
297 // Current directory should be C.
298 // Shortcut to C should be selected.
300 remoteCall.callRemoteTestUtil('fakeKeyDown', windowId,
301 ['#directory-tree', 'Up', false], this.next);
304 chrome.test.assertTrue(result);
305 expectSelection(windowId, DIRECTORY.C, DIRECTORY.C).then(this.next);
309 checkIfNoErrorsOccured(this.next);
315 * Adds and removes shortcuts from other window and check if the active
316 * directories and selected navigation items are correct.
318 testcase.addRemoveFolderShortcuts = function() {
322 // Set up each window.
324 addEntries(['drive'], ENTRY_SET, this.next);
327 chrome.test.assertTrue(result);
328 openWindows().then(this.next);
330 function(windowIds) {
331 windowId1 = windowIds[0];
332 windowId2 = windowIds[1];
333 expandDirectoryTree(windowId1).then(this.next);
336 expandDirectoryTree(windowId2).then(this.next);
339 remoteCall.waitForFiles(windowId1, DIRECTORY.Drive.contents).
343 remoteCall.waitForFiles(windowId2, DIRECTORY.Drive.contents).
347 // Create shortcut to D
349 createShortcut(windowId1, DIRECTORY.D).then(this.next);
353 // Current directory should be D.
354 // Shortcut to D should be selected.
356 clickShortcut(windowId1, DIRECTORY.D).then(this.next);
359 expectSelection(windowId1, DIRECTORY.D, DIRECTORY.D).then(this.next);
362 // Create shortcut to A in another window.
364 createShortcut(windowId2, DIRECTORY.A).then(this.next);
367 // The index of shortcut to D is changed.
368 // Current directory should remain D.
369 // Shortcut to D should keep selected.
371 expectSelection(windowId1, DIRECTORY.D, DIRECTORY.D).then(this.next);
374 // Remove shortcut to D in another window.
376 removeShortcut(windowId2, DIRECTORY.D).then(this.next);
379 // Directory D in the directory tree should be selected.
381 remoteCall.waitForElement(windowId1, TREEITEM_D + '[selected]').
386 checkIfNoErrorsOccured(this.next);