Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / file_manager_browsertest / 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 waitForElementLost(windowId,
16                               'div.detail-table > list > li[selected]');
17   }).then(function() {
18     // Push Down.
19     return callRemoteTestUtil('fakeKeyDown',
20                               windowId,
21                               // Down
22                               ['#file-list', 'Down', true]);
23   }).then(function() {
24     // Wait for selection.
25     return waitForElement(windowId, 'div.detail-table > list > li[selected]');
26   }).then(function() {
27     // Ensure that only the first item is selected.
28     return callRemoteTestUtil(
29         'queryAllElements',
30         windowId,
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']);
35   });
36 }
37
38 /**
39  * Creates new folder.
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.
44  */
45 function createNewFolder(windowId, path, initialEntrySet) {
46   var newFoloderListItemId = null;
47   return Promise.resolve(
48   ).then(function() {
49     // Push Ctrl + E.
50     return callRemoteTestUtil('fakeKeyDown',
51                               windowId,
52                               // Ctrl + E
53                               ['#file-list', 'U+0045', true]);
54   }).then(function() {
55     // Wait for rename text field.
56     return waitForElement(windowId, 'li[renaming] input.rename');
57   }).then(function() {
58     return callRemoteTestUtil(
59         'queryAllElements',
60         windowId,
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'];
67   }).then(function() {
68     // Type new folder name.
69     return callRemoteTestUtil(
70         'inputText', windowId, ['input.rename', 'Test Folder Name']);
71   }).then(function() {
72     // Push Enter.
73     return callRemoteTestUtil('fakeKeyDown',
74                               windowId,
75                               ['input.rename', 'Enter', false]);
76   }).then(function() {
77     // Wait until rename completes.
78     return waitForElementLost(windowId, 'input.rename');
79   }).then(function() {
80     var expectedEntryRows = TestEntryInfo.getExpectedRows(initialEntrySet);
81     expectedEntryRows.push(['Test Folder Name', '--', 'Folder', '']);
82     // Wait for the new folder.
83     return waitForFiles(windowId,
84                         expectedEntryRows,
85                         {ignoreLastModifiedTime: true});
86   }).then(function() {
87     // Ensure that only the created directory is selected.
88     return callRemoteTestUtil(
89         'queryAllElements',
90         windowId,
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']);
95   });
96 };
97
98 testcase.createNewFolderAfterSelectFile = function() {
99   var PATH = RootPath.DOWNLOADS;
100   var windowId = null;
101   var promise = new Promise(function(callback) {
102     setupAndWaitUntilReady(null, PATH, callback);
103   }).then(function(inWindowId) {
104     windowId = inWindowId;
105     return selectFirstListItem(windowId);
106   }).then(function() {
107     return createNewFolder(windowId, PATH, BASIC_LOCAL_ENTRY_SET);
108   });
109
110   testPromise(promise);
111 };
112
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);
119   });
120
121   testPromise(promise);
122 };
123
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);
130   });
131
132   testPromise(promise);
133 };