OLD | NEW |
---|---|
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * Waits until a dialog with an OK button is shown and accepts it. | 8 * Waits until a dialog with an OK button is shown and accepts it. |
9 * | 9 * |
10 * @param {string} windowId Target window ID. | 10 * @param {string} windowId Target window ID. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 ]); | 127 ]); |
128 } | 128 } |
129 | 129 |
130 /** | 130 /** |
131 * Adds check of chrome.test to the end of the given promise. | 131 * Adds check of chrome.test to the end of the given promise. |
132 * @param {Promise} promise Promise. | 132 * @param {Promise} promise Promise. |
133 */ | 133 */ |
134 function testPromise(promise) { | 134 function testPromise(promise) { |
135 promise.then(function() { | 135 promise.then(function() { |
136 return new Promise(checkIfNoErrorsOccured); | 136 return new Promise(checkIfNoErrorsOccured); |
137 }).then(chrome.test.callbackPass(function() { | 137 }).then(chrome.test.callbackPass(function() { |
mtomasz
2014/04/09 03:38:54
Why this change?
hirono
2014/04/09 20:01:13
Because chrome.test.succeed generates a log.
We al
mtomasz
2014/04/09 21:15:19
Please add a comment exactly saying that. Also, pl
hirono
2014/04/09 21:37:06
Done.
| |
138 chrome.test.succeed(); | |
139 }), function(error) { | 138 }), function(error) { |
140 chrome.test.fail(error.stack || error); | 139 chrome.test.fail(error.stack || error); |
141 }); | 140 }); |
142 }; | 141 }; |
143 | 142 |
144 /** | 143 /** |
145 * Test for creating new folder. | 144 * Test for creating new folder. |
146 * @param {string} path Initial path. | 145 * @param {string} path Initial path. |
147 * @param {Array.<TestEntryInfo>} initialEntrySet Initial set of entries. | 146 * @param {Array.<TestEntryInfo>} initialEntrySet Initial set of entries. |
148 * @return {Promise} Promise to be fulfilled on success. | 147 * @return {Promise} Promise to be fulfilled on success. |
(...skipping 27 matching lines...) Expand all Loading... | |
176 }).then(function() { | 175 }).then(function() { |
177 var expectedEntryRows = TestEntryInfo.getExpectedRows(initialEntrySet); | 176 var expectedEntryRows = TestEntryInfo.getExpectedRows(initialEntrySet); |
178 expectedEntryRows.push(['Test Folder Name', '--', 'Folder', '']); | 177 expectedEntryRows.push(['Test Folder Name', '--', 'Folder', '']); |
179 // Wait for the new folder. | 178 // Wait for the new folder. |
180 return waitForFiles(windowId, | 179 return waitForFiles(windowId, |
181 expectedEntryRows, | 180 expectedEntryRows, |
182 {ignoreLastModifiedTime: true}); | 181 {ignoreLastModifiedTime: true}); |
183 }); | 182 }); |
184 }; | 183 }; |
185 | 184 |
185 /** | |
186 * Renames a file. | |
187 * @param {string} windowId ID of window. | |
mtomasz
2014/04/09 03:38:54
nit: window -> the window
hirono
2014/04/09 20:01:13
Done.
| |
188 * @param {string} oldName Old name of a file. | |
189 * @param {string} newName New name of a file. | |
190 * @return {Promise} Promise to be fulfilled on success. | |
191 */ | |
192 function renameFile(windowId, oldName, newName) { | |
193 return callRemoteTestUtil('selectFile', windowId, [oldName]).then(function() { | |
194 // Push Ctrl+Enter. | |
195 return fakeKeyDown(windowId, '#detail-table', 'Enter', true); | |
196 }).then(function() { | |
197 // Wait for rename text field. | |
198 return waitForElement(windowId, 'input.rename'); | |
199 }).then(function() { | |
200 // Type new file name. | |
201 return callRemoteTestUtil( | |
202 'inputText', windowId, ['input.rename', newName]); | |
203 }).then(function() { | |
204 // Push Enter. | |
205 return fakeKeyDown(windowId, 'input.rename', 'Enter', false); | |
206 }).then(function() { | |
207 // Wait until rename completes. | |
mtomasz
2014/04/09 03:38:54
I think this is racy. The class 'provisional' may
mtomasz
2014/04/09 03:42:15
To fix this race, we could eg. wait for the newNam
hirono
2014/04/09 20:01:13
This is race. But we cannot fix it by waiting newN
mtomasz
2014/04/09 21:15:19
Yes, that would cause a test timeout, so the test
| |
208 return waitForElementLost(windowId, '#detail-table .provisional'); | |
209 }); | |
210 } | |
211 | |
212 /** | |
213 * Test for renaming a file. | |
214 * @param {string} path Initial path. | |
215 * @param {Array.<TestEntryInfo>} initialEntrySet Initial set of entries. | |
216 * @return {Promise} Promise to be fulfilled on success. | |
217 */ | |
218 function testRenameFile(path, initialEntrySet) { | |
219 var windowId; | |
220 | |
221 // Make expected rows. | |
222 var initialExpectedEntryRows = TestEntryInfo.getExpectedRows(initialEntrySet); | |
223 var expectedEntryRows = TestEntryInfo.getExpectedRows(initialEntrySet); | |
224 for (var i = 0; i < expectedEntryRows.length; i++) { | |
225 if (expectedEntryRows[i][0] === 'hello.txt') | |
226 break; | |
227 } | |
228 expectedEntryRows[i][0] = 'New File Name.txt'; | |
mtomasz
2014/04/09 03:38:54
This works, but it is not readable. Can we move it
hirono
2014/04/09 20:01:13
Done.
| |
229 | |
230 // Open window. | |
mtomasz
2014/04/09 03:38:54
nit: window -> a window
hirono
2014/04/09 20:01:13
Done.
| |
231 return new Promise(function(callback) { | |
232 setupAndWaitUntilReady(null, path, callback); | |
233 }).then(function(inWindowId) { | |
234 windowId = inWindowId; | |
235 return waitForFiles(windowId, initialExpectedEntryRows); | |
236 }).then(function(){ | |
237 return renameFile(windowId, 'hello.txt', 'New File Name.txt'); | |
238 }).then(function() { | |
239 // Wait for the new file name. | |
240 return waitForFiles(windowId, | |
241 expectedEntryRows, | |
242 {ignoreLastModifiedTime: true}); | |
243 }).then(function() { | |
244 return renameFile(windowId, 'New File Name.txt', '.hidden file'); | |
245 }).then(function() { | |
246 // The error dialog is shown. | |
247 return waitAndAcceptDialog(windowId); | |
248 }).then(function() { | |
249 // The name does not changed. | |
mtomasz
2014/04/09 03:38:54
does not changed -> did not change OR has not chan
hirono
2014/04/09 20:01:13
Done.
| |
250 return waitForFiles(windowId, | |
251 expectedEntryRows, | |
252 {ignoreLastModifiedTime: true}); | |
253 }); | |
254 }; | |
255 | |
186 testcase.keyboardCopyDownloads = function() { | 256 testcase.keyboardCopyDownloads = function() { |
187 keyboardCopy(RootPath.DOWNLOADS); | 257 keyboardCopy(RootPath.DOWNLOADS); |
188 }; | 258 }; |
189 | 259 |
190 testcase.keyboardDeleteDownloads = function() { | 260 testcase.keyboardDeleteDownloads = function() { |
191 keyboardDelete(RootPath.DOWNLOADS); | 261 keyboardDelete(RootPath.DOWNLOADS); |
192 }; | 262 }; |
193 | 263 |
194 testcase.keyboardCopyDrive = function() { | 264 testcase.keyboardCopyDrive = function() { |
195 keyboardCopy(RootPath.DRIVE); | 265 keyboardCopy(RootPath.DRIVE); |
196 }; | 266 }; |
197 | 267 |
198 testcase.keyboardDeleteDrive = function() { | 268 testcase.keyboardDeleteDrive = function() { |
199 keyboardDelete(RootPath.DRIVE); | 269 keyboardDelete(RootPath.DRIVE); |
200 }; | 270 }; |
201 | 271 |
202 testcase.createNewFolderDownloads = function() { | 272 testcase.createNewFolderDownloads = function() { |
203 testPromise(createNewFolder(RootPath.DOWNLOADS, BASIC_LOCAL_ENTRY_SET)); | 273 testPromise(createNewFolder(RootPath.DOWNLOADS, BASIC_LOCAL_ENTRY_SET)); |
204 }; | 274 }; |
205 | 275 |
206 testcase.createNewFolderDrive = function() { | 276 testcase.createNewFolderDrive = function() { |
207 testPromise(createNewFolder(RootPath.DRIVE, BASIC_DRIVE_ENTRY_SET)); | 277 testPromise(createNewFolder(RootPath.DRIVE, BASIC_DRIVE_ENTRY_SET)); |
208 }; | 278 }; |
279 | |
280 testcase.renameFileDownloads = function() { | |
281 testPromise(testRenameFile(RootPath.DOWNLOADS, BASIC_LOCAL_ENTRY_SET)); | |
282 }; | |
283 | |
284 testcase.renameFileDrive = function() { | |
285 testPromise(testRenameFile(RootPath.DRIVE, BASIC_DRIVE_ENTRY_SET)); | |
286 }; | |
OLD | NEW |