Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 /** | 5 /** |
| 6 * Expected files before tests are performed. Entries for Local tests. | 6 * Expected files before tests are performed. Entries for Local tests. |
| 7 * @type {Array.<Array.<string>>} | 7 * @type {Array.<Array.<string>>} |
| 8 * @const | 8 * @const |
| 9 */ | 9 */ |
| 10 var EXPECTED_FILES_BEFORE_LOCAL = [ | 10 var EXPECTED_FILES_BEFORE_LOCAL = [ |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 * Expected files shown in "Shared with me", which should be the entries labeled | 109 * Expected files shown in "Shared with me", which should be the entries labeled |
| 110 * with "shared-with-me". | 110 * with "shared-with-me". |
| 111 * @type {Array.<Array.<string>>} | 111 * @type {Array.<Array.<string>>} |
| 112 * @const | 112 * @const |
| 113 */ | 113 */ |
| 114 var EXPECTED_FILES_IN_SHARED_WITH_ME = [ | 114 var EXPECTED_FILES_IN_SHARED_WITH_ME = [ |
| 115 ['Test Shared Document.gdoc','--','Google document','Mar 20, 2013 10:40 PM'] | 115 ['Test Shared Document.gdoc','--','Google document','Mar 20, 2013 10:40 PM'] |
| 116 ]; | 116 ]; |
| 117 | 117 |
| 118 /** | 118 /** |
| 119 * Returns the name of the given file list entry. | |
| 120 * @param {Array.<string>} file An entry in a flie list. | |
| 121 * @return {string} Name of the file. | |
| 122 */ | |
| 123 function getFileName(fileListEntry) { | |
| 124 return fileListEntry[0]; | |
| 125 } | |
| 126 | |
| 127 /** | |
| 128 * Returns the size of the given file list entry. | |
| 129 * @param {Array.<string>} An entry in a flie list. | |
|
mtomasz
2013/05/28 02:33:41
nit: flie -> file
hashimoto
2013/05/28 05:08:12
Done for all three occurrences.
| |
| 130 * @return {string} Size of the file. | |
| 131 */ | |
| 132 function getFileSize(fileListEntry) { | |
| 133 return fileListEntry[1]; | |
| 134 } | |
| 135 | |
| 136 /** | |
| 137 * Returns the type of the given file list entry. | |
| 138 * @param {Array.<string>} An entry in a flie list. | |
| 139 * @return {string} Type of the file. | |
| 140 */ | |
| 141 function getFileType(fileListEntry) { | |
| 142 return fileListEntry[2]; | |
| 143 } | |
| 144 | |
| 145 /** | |
| 119 * Namespace for test cases. | 146 * Namespace for test cases. |
| 120 */ | 147 */ |
| 121 var testcase = {}; | 148 var testcase = {}; |
| 122 | 149 |
| 123 /** | 150 /** |
| 124 * Namespace for intermediate test cases. | 151 * Namespace for intermediate test cases. |
| 125 * */ | 152 * */ |
| 126 testcase.intermediate = {}; | 153 testcase.intermediate = {}; |
| 127 | 154 |
| 128 /** | 155 /** |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 steps.shift()(); | 241 steps.shift()(); |
| 215 }; | 242 }; |
| 216 | 243 |
| 217 /** | 244 /** |
| 218 * Tests copying a file to the same directory and waits until the file lists | 245 * Tests copying a file to the same directory and waits until the file lists |
| 219 * changes. | 246 * changes. |
| 220 * | 247 * |
| 221 * @param {string} path Directory path to be tested. | 248 * @param {string} path Directory path to be tested. |
| 222 */ | 249 */ |
| 223 testcase.intermediate.keyboardCopy = function(path, callback) { | 250 testcase.intermediate.keyboardCopy = function(path, callback) { |
| 224 setupAndWaitUntilReady(path, function(appId) { | 251 setupAndWaitUntilReady(path, function(appId, files) { |
| 225 callRemoteTestUtil('copyFile', appId, ['world.ogv'], function(result) { | 252 // Returns true if |fileList| contains a copy of |filename|. |
| 226 chrome.test.assertFalse(!result); | 253 function isCopyPresent(filename, fileList) { |
|
mtomasz
2013/05/28 02:33:41
Inline functions are not recommended in Files.app.
hashimoto
2013/05/28 05:08:12
Done.
| |
| 227 callRemoteTestUtil('waitForFileListChange', | 254 var original_entry; |
| 228 appId, | 255 for (var i = 0; i < fileList.length; ++i) { |
|
mtomasz
2013/05/28 02:33:41
In Files.app i++ is much more common than ++i.
++i
hashimoto
2013/05/28 05:08:12
Done for all three.
| |
| 229 [getExpectedFilesBefore(path == '/drive/root').length], | 256 if (getFileName(fileList[i]) == filename) |
| 230 checkIfNoErrorsOccured.bind(null, | 257 original_entry = fileList[i]; |
| 231 chrome.test.succeed)); | 258 } |
| 259 if (!original_entry) | |
| 260 return false; | |
| 261 | |
| 262 var base_name = filename.substring(0, filename.lastIndexOf('.')); | |
| 263 var extension = filename.substr(filename.lastIndexOf('.')); | |
| 264 var filename_pattern = | |
| 265 new RegExp('^' + base_name + '.+' + extension + '$'); | |
|
mtomasz
2013/05/28 02:33:41
in JS camel case: baseName instead of base_name.
hashimoto
2013/05/28 05:08:12
Done.
| |
| 266 for (var i = 0; i < fileList.length; ++i) { | |
| 267 // Check size, type and file name pattern to find a copy. | |
| 268 if (getFileSize(fileList[i]) == getFileSize(original_entry) && | |
| 269 getFileType(fileList[i]) == getFileType(original_entry) && | |
| 270 filename_pattern.exec(getFileName(fileList[i]))) | |
| 271 return true; | |
| 272 } | |
| 273 return false; | |
| 274 } | |
| 275 | |
| 276 var filename = 'world.ogv'; | |
| 277 chrome.test.assertFalse(isCopyPresent(filename, files)); | |
| 278 | |
| 279 callRemoteTestUtil('copyFile', appId, [filename], function(result) { | |
| 280 chrome.test.assertTrue(result); | |
|
mtomasz
2013/05/28 02:33:41
How about calling waitForFileListChange and then a
hashimoto
2013/05/28 05:08:12
Done.
| |
| 281 function waitForCopyCompletion() { | |
| 282 callRemoteTestUtil('getFileList', appId, [], function(fileList) { | |
| 283 if (isCopyPresent(filename, fileList)) { | |
| 284 checkIfNoErrorsOccured(chrome.test.succeed); | |
| 285 return; | |
| 286 } | |
| 287 window.setTimeout(waitForCopyCompletion, 50); | |
| 288 }); | |
| 289 } | |
| 290 waitForCopyCompletion(); | |
| 232 }); | 291 }); |
| 233 }); | 292 }); |
| 234 }; | 293 }; |
| 235 | 294 |
| 236 /** | 295 /** |
| 237 * Tests deleting a file and and waits until the file lists changes. | 296 * Tests deleting a file and and waits until the file lists changes. |
| 238 * @param {string} path Directory path to be tested. | 297 * @param {string} path Directory path to be tested. |
| 239 */ | 298 */ |
| 240 testcase.intermediate.keyboardDelete = function(path) { | 299 testcase.intermediate.keyboardDelete = function(path) { |
| 241 setupAndWaitUntilReady(path, function(appId) { | 300 setupAndWaitUntilReady(path, function(appId, files) { |
|
mtomasz
2013/05/28 02:33:41
@hirono introduced a great pattern for complex mul
hashimoto
2013/05/28 05:08:12
Done.
| |
| 242 callRemoteTestUtil('deleteFile', appId, ['world.ogv'], function(result) { | 301 // Returns true if |fileList| contains |filename|. |
| 243 chrome.test.assertFalse(!result); | 302 function isFilePresent(filename, fileList) { |
| 303 for (var i = 0; i < fileList.length; ++i) { | |
| 304 if (getFileName(fileList[i]) == filename) | |
| 305 return true; | |
| 306 } | |
| 307 return false; | |
| 308 } | |
| 309 | |
| 310 var filename = 'world.ogv'; | |
| 311 chrome.test.assertTrue(isFilePresent(filename, files)); | |
| 312 | |
| 313 callRemoteTestUtil('deleteFile', appId, [filename], function(result) { | |
| 314 chrome.test.assertTrue(result); | |
| 244 callRemoteTestUtil('waitAndAcceptDialog', appId, [], function() { | 315 callRemoteTestUtil('waitAndAcceptDialog', appId, [], function() { |
| 245 callRemoteTestUtil( | 316 function waitForDeleteCompletion() { |
|
mtomasz
2013/05/28 02:33:41
I think we can use waitForFileListChange here for
hashimoto
2013/05/28 05:08:12
Done.
| |
| 246 'waitForFileListChange', | 317 callRemoteTestUtil('getFileList', appId, [], function(fileList) { |
| 247 appId, | 318 if (!isFilePresent(filename, fileList)) { |
| 248 [getExpectedFilesBefore(path == '/drive/root').length], | 319 checkIfNoErrorsOccured(chrome.test.succeed); |
| 249 checkIfNoErrorsOccured.bind(null, chrome.test.succeed)); | 320 return; |
| 321 } | |
| 322 window.setTimeout(waitForDeleteCompletion, 50); | |
| 323 }); | |
| 324 } | |
| 325 waitForDeleteCompletion(); | |
| 250 }); | 326 }); |
| 251 }); | 327 }); |
| 252 }); | 328 }); |
| 253 }; | 329 }; |
| 254 | 330 |
| 255 testcase.fileDisplayDownloads = function() { | 331 testcase.fileDisplayDownloads = function() { |
| 256 testcase.intermediate.fileDisplay('/Downloads'); | 332 testcase.intermediate.fileDisplay('/Downloads'); |
| 257 }; | 333 }; |
| 258 | 334 |
| 259 testcase.galleryOpenDownloads = function() { | 335 testcase.galleryOpenDownloads = function() { |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 567 /** | 643 /** |
| 568 * Tests copy from drive's offline to drive's root. | 644 * Tests copy from drive's offline to drive's root. |
| 569 */ | 645 */ |
| 570 testcase.transferFromOfflineToDrive = function() { | 646 testcase.transferFromOfflineToDrive = function() { |
| 571 testcase.intermediate.copyBetweenVolumes('Test Document.gdoc', | 647 testcase.intermediate.copyBetweenVolumes('Test Document.gdoc', |
| 572 'drive_offline', | 648 'drive_offline', |
| 573 EXPECTED_FILES_IN_OFFLINE, | 649 EXPECTED_FILES_IN_OFFLINE, |
| 574 'drive', | 650 'drive', |
| 575 EXPECTED_FILES_BEFORE_DRIVE); | 651 EXPECTED_FILES_BEFORE_DRIVE); |
| 576 }; | 652 }; |
| OLD | NEW |