Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / file_manager_browsertest / file_manager / create_new_folder.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  * 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.
11  */
12 function selectFirstListItem(windowId) {
13   return Promise.resolve().then(function() {
14     // Ensure no selected item.
15     return remoteCall.waitForElementLost(
16         windowId,
17         'div.detail-table > list > li[selected]');
18   }).then(function() {
19     // Push Down.
20     return remoteCall.callRemoteTestUtil('fakeKeyDown',
21                                          windowId,
22                                          // Down
23                                          ['#file-list', 'Down', true]);
24   }).then(function() {
25     // Wait for selection.
26     return remoteCall.waitForElement(windowId,
27                                      'div.detail-table > list > li[selected]');
28   }).then(function() {
29     // Ensure that only the first item is selected.
30     return remoteCall.callRemoteTestUtil(
31         'queryAllElements',
32         windowId,
33         ['div.detail-table > list > li[selected]']);
34   }).then(function(elements) {
35     chrome.test.assertEq(1, elements.length);
36     chrome.test.assertEq('detail-table-1', elements[0].attributes['id']);
37   });
38 }
39
40 /**
41  * Creates new folder.
42  * @param {string} windowId ID of the target window.
43  * @param {string} path Initial path.
44  * @param {Array.<TestEntryInfo>} initialEntrySet Initial set of entries.
45  * @return {Promise} Promise to be fulfilled on success.
46  */
47 function createNewFolder(windowId, path, initialEntrySet) {
48   return Promise.resolve(
49   ).then(function() {
50     // Push Ctrl + E.
51     return remoteCall.callRemoteTestUtil('fakeKeyDown',
52                                          windowId,
53                                          // Ctrl + E
54                                          ['#file-list', 'U+0045', true]);
55   }).then(function() {
56     // Wait for rename text field.
57     return remoteCall.waitForElement(windowId, 'li[renaming] input.rename');
58   }).then(function() {
59     return remoteCall.callRemoteTestUtil(
60         'queryAllElements',
61         windowId,
62         ['div.detail-table > list > li[selected]']);
63   }).then(function(elements) {
64     // Ensure that only the new directory is selected and being renamed.
65     chrome.test.assertEq(1, elements.length);
66     chrome.test.assertTrue('renaming' in elements[0].attributes);
67   }).then(function() {
68     // Type new folder name.
69     return remoteCall.callRemoteTestUtil(
70         'inputText', windowId, ['input.rename', 'Test Folder Name']);
71   }).then(function() {
72     // Push Enter.
73     return remoteCall.callRemoteTestUtil(
74         'fakeKeyDown',
75         windowId,
76         ['input.rename', 'Enter', false]);
77   }).then(function() {
78     // Wait until rename completes.
79     return remoteCall.waitForElementLost(windowId, 'input.rename');
80   }).then(function() {
81     var expectedEntryRows = TestEntryInfo.getExpectedRows(initialEntrySet);
82     expectedEntryRows.push(['Test Folder Name', '--', 'Folder', '']);
83     // Wait for the new folder.
84     return remoteCall.waitForFiles(windowId,
85                                    expectedEntryRows,
86                                    {ignoreLastModifiedTime: true});
87   }).then(function() {
88     // Wait until the new created folder is selected.
89     var nameSpanQuery = 'div.detail-table > list > ' +
90                         'li[selected]:not([renaming]) span.entry-name';
91
92     return repeatUntil(function() {
93       var selectedNameRetrievePromise = remoteCall.callRemoteTestUtil(
94             'queryAllElements',
95             windowId,
96             ['div.detail-table > list > li[selected] span.entry-name']);
97
98       return selectedNameRetrievePromise.then(function(elements) {
99         if (elements.length !== 1) {
100           return pending('Selection is not ready (elements: %j)', elements);
101         } else if (elements[0].text !== 'Test Folder Name') {
102           return pending('Selected item is wrong. (actual: %s)',
103                          elements[0].text);
104         } else {
105           return true;
106         }
107       });
108     });
109   });
110 };
111
112 testcase.createNewFolderAfterSelectFile = function() {
113   var PATH = RootPath.DOWNLOADS;
114   var windowId = null;
115   var promise = new Promise(function(callback) {
116     setupAndWaitUntilReady(null, PATH, callback);
117   }).then(function(inWindowId) {
118     windowId = inWindowId;
119     return selectFirstListItem(windowId);
120   }).then(function() {
121     return createNewFolder(windowId, PATH, BASIC_LOCAL_ENTRY_SET);
122   });
123
124   testPromise(promise);
125 };
126
127 testcase.createNewFolderDownloads = function() {
128   var PATH = RootPath.DOWNLOADS;
129   var promise = new Promise(function(callback) {
130     setupAndWaitUntilReady(null, PATH, callback);
131   }).then(function(windowId) {
132     return createNewFolder(windowId, PATH, BASIC_LOCAL_ENTRY_SET);
133   });
134
135   testPromise(promise);
136 };
137
138 testcase.createNewFolderDrive = function() {
139   var PATH = RootPath.DRIVE;
140   var promise = new Promise(function(callback) {
141     setupAndWaitUntilReady(null, PATH, callback);
142   }).then(function(windowId) {
143     return createNewFolder(windowId, PATH, BASIC_DRIVE_ENTRY_SET);
144   });
145
146   testPromise(promise);
147 };