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 * Selects the first item in the file list.
9 * @param {string} windowId ID of the target window.
10 * @return {Promise} Promise to be fulfilled on success.
12 function selectFirstListItem(windowId) {
13 return Promise.resolve().then(function() {
14 // Ensure no selected item.
15 return waitForElementLost(windowId,
16 'div.detail-table > list > li[selected]');
19 return callRemoteTestUtil('fakeKeyDown',
22 ['#file-list', 'Down', true]);
24 // Wait for selection.
25 return waitForElement(windowId, 'div.detail-table > list > li[selected]');
27 // Ensure that only the first item is selected.
28 return callRemoteTestUtil(
31 ['div.detail-table > list > li[selected]']);
32 }).then(function(elements) {
33 chrome.test.assertEq(1, elements.length);
34 chrome.test.assertEq('detail-table-1', elements[0].attributes['id']);
40 * @param {string} windowId ID of the target window.
41 * @param {string} path Initial path.
42 * @param {Array.<TestEntryInfo>} initialEntrySet Initial set of entries.
43 * @return {Promise} Promise to be fulfilled on success.
45 function createNewFolder(windowId, path, initialEntrySet) {
46 var newFoloderListItemId = null;
47 return Promise.resolve(
50 return callRemoteTestUtil('fakeKeyDown',
53 ['#file-list', 'U+0045', true]);
55 // Wait for rename text field.
56 return waitForElement(windowId, 'li[renaming] input.rename');
58 return callRemoteTestUtil(
61 ['div.detail-table > list > li[selected]']);
62 }).then(function(elements) {
63 // Ensure that only the new directory is selected and being renamed.
64 chrome.test.assertEq(1, elements.length);
65 chrome.test.assertTrue('renaming' in elements[0].attributes);
66 newFoloderListItemId = elements[0].attributes['id'];
68 // Type new folder name.
69 return callRemoteTestUtil(
70 'inputText', windowId, ['input.rename', 'Test Folder Name']);
73 return callRemoteTestUtil('fakeKeyDown',
75 ['input.rename', 'Enter', false]);
77 // Wait until rename completes.
78 return waitForElementLost(windowId, 'input.rename');
80 var expectedEntryRows = TestEntryInfo.getExpectedRows(initialEntrySet);
81 expectedEntryRows.push(['Test Folder Name', '--', 'Folder', '']);
82 // Wait for the new folder.
83 return waitForFiles(windowId,
85 {ignoreLastModifiedTime: true});
87 // Ensure that only the created directory is selected.
88 return callRemoteTestUtil(
91 ['div.detail-table > list > li[selected]']);
92 }).then(function(elements) {
93 chrome.test.assertEq(1, elements.length);
94 chrome.test.assertEq(newFoloderListItemId, elements[0].attributes['id']);
98 testcase.createNewFolderAfterSelectFile = function() {
99 var PATH = RootPath.DOWNLOADS;
101 var promise = new Promise(function(callback) {
102 setupAndWaitUntilReady(null, PATH, callback);
103 }).then(function(inWindowId) {
104 windowId = inWindowId;
105 return selectFirstListItem(windowId);
107 return createNewFolder(windowId, PATH, BASIC_LOCAL_ENTRY_SET);
110 testPromise(promise);
113 testcase.createNewFolderDownloads = function() {
114 var PATH = RootPath.DOWNLOADS;
115 var promise = new Promise(function(callback) {
116 setupAndWaitUntilReady(null, PATH, callback);
117 }).then(function(windowId) {
118 return createNewFolder(windowId, PATH, BASIC_LOCAL_ENTRY_SET);
121 testPromise(promise);
124 testcase.createNewFolderDrive = function() {
125 var PATH = RootPath.DRIVE;
126 var promise = new Promise(function(callback) {
127 setupAndWaitUntilReady(null, PATH, callback);
128 }).then(function(windowId) {
129 return createNewFolder(windowId, PATH, BASIC_DRIVE_ENTRY_SET);
132 testPromise(promise);