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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * @enum {string} | 8 * @enum {string} |
| 9 * @const | 9 * @const |
| 10 */ | 10 */ |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 var TestEntryInfo = function(type, | 40 var TestEntryInfo = function(type, |
| 41 sourceFileName, | 41 sourceFileName, |
| 42 targetName, | 42 targetName, |
| 43 mimeType, | 43 mimeType, |
| 44 sharedOption, | 44 sharedOption, |
| 45 lastModifiedTime, | 45 lastModifiedTime, |
| 46 nameText, | 46 nameText, |
| 47 sizeText, | 47 sizeText, |
| 48 typeText) { | 48 typeText) { |
| 49 this.type = type; | 49 this.type = type; |
| 50 this.sourceFileName = sourceFileName; | 50 this.sourceFileName = sourceFileName || ''; |
| 51 this.targetName = targetName; | 51 this.targetName = targetName; |
| 52 this.mimeType = mimeType; | 52 this.mimeType = mimeType || ''; |
| 53 this.sharedOption = sharedOption; | 53 this.sharedOption = sharedOption; |
| 54 this.lastModifiedTime = lastModifiedTime; | 54 this.lastModifiedTime = lastModifiedTime; |
| 55 this.nameText = nameText; | 55 this.nameText = nameText; |
| 56 this.sizeText = sizeText; | 56 this.sizeText = sizeText; |
| 57 this.typeText = typeText; | 57 this.typeText = typeText; |
| 58 Object.freeze(this); | 58 Object.freeze(this); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 /** | 61 /** |
| 62 * Obtains a expected row contents of the file in the file list. | 62 * Obtains a expected row contents of the file in the file list. |
| 63 */ | 63 */ |
| 64 TestEntryInfo.prototype.getExpectedRow = function() { | 64 TestEntryInfo.prototype.getExpectedRow = function() { |
| 65 return [this.nameText, this.sizeText, this.typeText, this.lastModifiedTime]; | 65 return [this.nameText, this.sizeText, this.typeText, this.lastModifiedTime]; |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 /** | 68 /** |
| 69 * Expected files before tests are performed. Entries for Local tests. | |
| 70 * @type {Array.<Array.<string>>} | |
| 71 * @const | |
| 72 */ | |
| 73 var EXPECTED_FILES_BEFORE_LOCAL = [ | |
| 74 ['hello.txt', '51 bytes', 'Plain text', 'Sep 4, 1998 12:34 PM'], | |
| 75 ['world.ogv', '59 KB', 'OGG video', 'Jul 4, 2012 10:35 AM'], | |
| 76 ['My Desktop Background.png', '272 bytes', 'PNG image', | |
| 77 'Jan 18, 2038 1:02 AM'], | |
| 78 ['Beautiful Song.ogg', '14 KB', 'OGG audio', 'Nov 12, 2086 12:00 PM'], | |
| 79 ['photos', '--', 'Folder', 'Jan 1, 1980 11:59 PM'] | |
| 80 // ['.warez', '--', 'Folder', 'Oct 26, 1985 1:39 PM'] # should be hidden | |
| 81 ].sort(); | |
| 82 | |
| 83 /** | |
| 84 * Expected files before tests are performed. Entries for Drive tests. | |
| 85 * @type {Array.<Array.<string>>} | |
| 86 * @const | |
| 87 */ | |
| 88 var EXPECTED_FILES_BEFORE_DRIVE = [ | |
| 89 ['hello.txt', '51 bytes', 'Plain text', 'Sep 4, 1998 12:34 PM'], | |
| 90 ['world.ogv', '59 KB', 'OGG video', 'Jul 4, 2012 10:35 AM'], | |
| 91 ['My Desktop Background.png', '272 bytes', 'PNG image', | |
| 92 'Jan 18, 2038 1:02 AM'], | |
| 93 ['Beautiful Song.ogg', '14 KB', 'OGG audio', 'Nov 12, 2086 12:00 PM'], | |
| 94 ['photos', '--', 'Folder', 'Jan 1, 1980 11:59 PM'], | |
| 95 ['Test Document.gdoc','--','Google document','Apr 10, 2013 4:20 PM'], | |
| 96 ['Test Shared Document.gdoc','--','Google document','Mar 20, 2013 10:40 PM'] | |
| 97 ].sort(); | |
| 98 | |
| 99 /** | |
| 100 * Filesystem entries used by the test cases. | 69 * Filesystem entries used by the test cases. |
| 101 * @type {Object.<string, TestEntryInfo>} | 70 * @type {Object.<string, TestEntryInfo>} |
| 102 * @const | 71 * @const |
| 103 */ | 72 */ |
| 104 var ENTRIES = { | 73 var ENTRIES = { |
| 74 hello: new TestEntryInfo( | |
| 75 EntryType.FILE, 'text.txt', 'hello.txt', | |
| 76 'text/plain', SharedOption.NONE, 'Sep 4, 1998 12:34 PM', | |
| 77 'hello.txt', '51 bytes', 'Plain text'), | |
| 78 | |
| 79 world: new TestEntryInfo( | |
| 80 EntryType.FILE, 'video.ogv', 'world.ogv', | |
| 81 'text/plain', SharedOption.NONE, 'Jul 4, 2012 10:35 AM', | |
| 82 'world.ogv', '59 KB', 'OGG video'), | |
| 83 | |
| 84 desktop: new TestEntryInfo( | |
| 85 EntryType.FILE, 'image.png', 'My Desktop Background.png', | |
| 86 'text/plain', SharedOption.NONE, 'Jan 18, 2038 1:02 AM', | |
| 87 'My Desktop Background.png', '272 bytes', 'PNG image'), | |
| 88 | |
| 89 beautiful: new TestEntryInfo( | |
| 90 EntryType.FILE, 'music.ogg', 'Beautiful Song.ogg', | |
| 91 'text/plain', SharedOption.NONE, 'Nov 12, 2086 12:00 PM', | |
| 92 'Beautiful Song.ogg', '14 KB', 'OGG audio'), | |
| 93 | |
| 94 photos: new TestEntryInfo( | |
| 95 EntryType.DIRECTORY, null, 'photos', | |
| 96 null, SharedOption.NONE, 'Jan 1, 1980 11:59 PM', | |
| 97 'photos', '--', 'Folder'), | |
| 98 | |
| 99 testDocument: new TestEntryInfo( | |
| 100 EntryType.FILE, null, 'Test Document', | |
| 101 'application/vnd.google-apps.document', | |
| 102 SharedOption.NONE, 'Apr 10, 2013 4:20 PM', | |
| 103 'Test Document.gdoc', '--', 'Google document'), | |
| 104 | |
| 105 testSharedDocument: new TestEntryInfo( | |
| 106 EntryType.FILE, null, 'Test Shared Document', | |
| 107 'application/vnd.google-apps.document', | |
| 108 SharedOption.SHARED, 'Mar 20, 2013 10:40 PM', | |
| 109 'Test Shared Document.gdoc', '--', 'Google document'), | |
| 110 | |
| 105 newlyAdded: new TestEntryInfo( | 111 newlyAdded: new TestEntryInfo( |
| 106 EntryType.FILE, 'music.ogg', 'newly added file.ogg', | 112 EntryType.FILE, 'music.ogg', 'newly added file.ogg', |
| 107 'audio/ogg', SharedOption.NONE, 'Sep 4, 1998 12:00 AM', | 113 'audio/ogg', SharedOption.NONE, 'Sep 4, 1998 12:00 AM', |
| 108 'newly added file.ogg', '14 KB', 'OGG audio') | 114 'newly added file.ogg', '14 KB', 'OGG audio') |
| 109 }; | 115 }; |
| 110 | 116 |
| 111 /** | 117 /** |
| 118 * Basic entry set for the local volume. | |
| 119 * @type {Array.<TestEntryInfo>} | |
| 120 * @const | |
| 121 */ | |
| 122 var BASIC_LOCAL_ENTRY_SET = [ | |
| 123 ENTRIES.hello, | |
| 124 ENTRIES.world, | |
| 125 ENTRIES.desktop, | |
| 126 ENTRIES.beautiful, | |
| 127 ENTRIES.photos | |
| 128 ]; | |
| 129 | |
| 130 /** | |
| 131 * Basic entry set for the drive volume. | |
| 132 * | |
| 133 * TODO(hirono): Add a case for an entry cached by DriveCache. For testing | |
|
hashimoto
2013/09/17 08:55:36
nit: "DriveCache" is meant to indicate the C++ cla
hirono
2013/09/17 09:05:26
Done.
Actually this is just copied haruki-san's To
| |
| 134 * Drive, create more entries with Drive specific attributes. | |
| 135 * | |
| 136 * @type {Array.<TestEntryInfo>} | |
| 137 * @const | |
| 138 */ | |
| 139 var BASIC_DRIVE_ENTRY_SET = [ | |
| 140 ENTRIES.hello, | |
| 141 ENTRIES.world, | |
| 142 ENTRIES.desktop, | |
| 143 ENTRIES.beautiful, | |
| 144 ENTRIES.photos, | |
| 145 ENTRIES.testDocument, | |
| 146 ENTRIES.testSharedDocument | |
| 147 ]; | |
| 148 | |
| 149 /** | |
| 150 * Expected files before tests are performed. Entries for Local tests. | |
| 151 * TODO(hirono): Remove the constant. | |
| 152 * @type {Array.<Array.<string>>} | |
| 153 * @const | |
| 154 */ | |
| 155 var EXPECTED_FILES_BEFORE_LOCAL = BASIC_LOCAL_ENTRY_SET.map(function(entry) { | |
| 156 return entry.getExpectedRow(); | |
| 157 }).sort(); | |
| 158 | |
| 159 /** | |
| 160 * Expected files before tests are performed. Entries for Drive tests. | |
| 161 * TODO(hirono): Remove the constant. | |
| 162 * @type {Array.<Array.<string>>} | |
| 163 * @const | |
| 164 */ | |
| 165 var EXPECTED_FILES_BEFORE_DRIVE = BASIC_DRIVE_ENTRY_SET.map(function(entry) { | |
| 166 return entry.getExpectedRow(); | |
| 167 }).sort(); | |
| 168 | |
| 169 /** | |
| 112 * @param {boolean} isDrive True if the test is for Drive. | 170 * @param {boolean} isDrive True if the test is for Drive. |
| 113 * @return {Array.<Array.<string>>} A sorted list of expected entries at the | 171 * @return {Array.<Array.<string>>} A sorted list of expected entries at the |
| 114 * initial state. | 172 * initial state. |
| 115 */ | 173 */ |
| 116 function getExpectedFilesBefore(isDrive) { | 174 function getExpectedFilesBefore(isDrive) { |
| 117 return isDrive ? | 175 return isDrive ? |
| 118 EXPECTED_FILES_BEFORE_DRIVE : | 176 EXPECTED_FILES_BEFORE_DRIVE : |
| 119 EXPECTED_FILES_BEFORE_LOCAL; | 177 EXPECTED_FILES_BEFORE_LOCAL; |
| 120 } | 178 } |
| 121 | 179 |
| 122 /** | 180 /** |
| 123 * Opens a Files.app's main window and waits until it is initialized. | 181 * Opens a Files.app's main window and waits until it is initialized. |
| 124 * | 182 * |
| 183 * TODO(hirono): Add parameters to specify the entry set to be prepared. | |
| 184 * | |
| 125 * @param {string} path Directory to be opened. | 185 * @param {string} path Directory to be opened. |
| 126 * @param {function(string, Array.<Array.<string>>)} Callback with the app id | 186 * @param {function(string, Array.<Array.<string>>)} Callback with the app id |
| 127 * and with the file list. | 187 * and with the file list. |
| 128 */ | 188 */ |
| 129 function setupAndWaitUntilReady(path, callback) { | 189 function setupAndWaitUntilReady(path, callback) { |
| 130 callRemoteTestUtil('openMainWindow', null, [path], function(appId) { | 190 var appId; |
| 131 callRemoteTestUtil('waitForFileListChange', appId, [0], function(files) { | 191 var steps = [ |
| 132 callback(appId, files); | 192 function() { |
| 133 }); | 193 callRemoteTestUtil('openMainWindow', null, [path], steps.shift()); |
| 134 }); | 194 }, |
| 195 function(inAppId) { | |
| 196 appId = inAppId; | |
| 197 addEntries(['local'], BASIC_LOCAL_ENTRY_SET, steps.shift()); | |
| 198 }, | |
| 199 function(success) { | |
| 200 chrome.test.assertTrue(success); | |
| 201 addEntries(['drive'], BASIC_DRIVE_ENTRY_SET, steps.shift()); | |
| 202 }, | |
| 203 function(success) { | |
| 204 chrome.test.assertTrue(success); | |
| 205 callRemoteTestUtil('waitForFileListChange', appId, [0], steps.shift()); | |
| 206 }, | |
| 207 function(fileList) { | |
| 208 callback(appId, fileList); | |
| 209 } | |
| 210 ]; | |
| 211 steps.shift()(); | |
| 135 } | 212 } |
| 136 | 213 |
| 137 /** | 214 /** |
| 138 * Verifies if there are no Javascript errors in any of the app windows. | 215 * Verifies if there are no Javascript errors in any of the app windows. |
| 139 * @param {function()} Completion callback. | 216 * @param {function()} Completion callback. |
| 140 */ | 217 */ |
| 141 function checkIfNoErrorsOccured(callback) { | 218 function checkIfNoErrorsOccured(callback) { |
| 142 callRemoteTestUtil('getErrorCount', null, [], function(count) { | 219 callRemoteTestUtil('getErrorCount', null, [], function(count) { |
| 143 chrome.test.assertEq(0, count); | 220 chrome.test.assertEq(0, count); |
| 144 callback(); | 221 callback(); |
| 145 }); | 222 }); |
| 146 } | 223 } |
| 147 | 224 |
| 148 /** | 225 /** |
| 149 * Expected files shown in "Recent". Directories (e.g. 'photos') are not in this | 226 * Expected files shown in "Recent". Directories (e.g. 'photos') are not in this |
| 150 * list as they are not expected in "Recent". | 227 * list as they are not expected in "Recent". |
| 151 * | 228 * |
| 229 * TODO(hirono): Remove the constant. | |
| 230 * | |
| 152 * @type {Array.<Array.<string>>} | 231 * @type {Array.<Array.<string>>} |
| 153 * @const | 232 * @const |
| 154 */ | 233 */ |
| 155 var EXPECTED_FILES_IN_RECENT = [ | 234 var EXPECTED_FILES_IN_RECENT = [ |
| 156 ['hello.txt', '51 bytes', 'Plain text', 'Sep 4, 1998 12:34 PM'], | 235 ['hello.txt', '51 bytes', 'Plain text', 'Sep 4, 1998 12:34 PM'], |
| 157 ['world.ogv', '59 KB', 'OGG video', 'Jul 4, 2012 10:35 AM'], | 236 ['world.ogv', '59 KB', 'OGG video', 'Jul 4, 2012 10:35 AM'], |
| 158 ['My Desktop Background.png', '272 bytes', 'PNG image', | 237 ['My Desktop Background.png', '272 bytes', 'PNG image', |
| 159 'Jan 18, 2038 1:02 AM'], | 238 'Jan 18, 2038 1:02 AM'], |
| 160 ['Beautiful Song.ogg', '14 KB', 'OGG audio', 'Nov 12, 2086 12:00 PM'], | 239 ['Beautiful Song.ogg', '14 KB', 'OGG audio', 'Nov 12, 2086 12:00 PM'], |
| 161 ['Test Document.gdoc','--','Google document','Apr 10, 2013 4:20 PM'], | 240 ['Test Document.gdoc','--','Google document','Apr 10, 2013 4:20 PM'], |
| 162 ['Test Shared Document.gdoc','--','Google document','Mar 20, 2013 10:40 PM'] | 241 ['Test Shared Document.gdoc','--','Google document','Mar 20, 2013 10:40 PM'] |
| 163 ].sort(); | 242 ].sort(); |
| 164 | 243 |
| 165 /** | 244 /** |
| 166 * Expected files shown in "Offline", which should have the files | 245 * Expected files shown in "Offline", which should have the files |
| 167 * "available offline". Google Documents, Google Spreadsheets, and the files | 246 * "available offline". Google Documents, Google Spreadsheets, and the files |
| 168 * cached locally are "available offline". | 247 * cached locally are "available offline". |
| 248 * | |
| 249 * TODO(hirono): Remove the constant. | |
| 250 * | |
| 169 * @type {Array.<Array.<string>>} | 251 * @type {Array.<Array.<string>>} |
| 170 * @const | 252 * @const |
| 171 */ | 253 */ |
| 172 var EXPECTED_FILES_IN_OFFLINE = [ | 254 var EXPECTED_FILES_IN_OFFLINE = [ |
| 173 ['Test Document.gdoc','--','Google document','Apr 10, 2013 4:20 PM'], | 255 ['Test Document.gdoc','--','Google document','Apr 10, 2013 4:20 PM'], |
| 174 ['Test Shared Document.gdoc','--','Google document','Mar 20, 2013 10:40 PM'] | 256 ['Test Shared Document.gdoc','--','Google document','Mar 20, 2013 10:40 PM'] |
| 175 ]; | 257 ]; |
| 176 | 258 |
| 177 /** | 259 /** |
| 178 * Expected files shown in "Shared with me", which should be the entries labeled | 260 * Expected files shown in "Shared with me", which should be the entries labeled |
| 179 * with "shared-with-me". | 261 * with "shared-with-me". |
| 262 * | |
| 263 * TODO(hirono): Remove the constant. | |
| 264 * | |
| 180 * @type {Array.<Array.<string>>} | 265 * @type {Array.<Array.<string>>} |
| 181 * @const | 266 * @const |
| 182 */ | 267 */ |
| 183 var EXPECTED_FILES_IN_SHARED_WITH_ME = [ | 268 var EXPECTED_FILES_IN_SHARED_WITH_ME = [ |
| 184 ['Test Shared Document.gdoc','--','Google document','Mar 20, 2013 10:40 PM'] | 269 ['Test Shared Document.gdoc','--','Google document','Mar 20, 2013 10:40 PM'] |
| 185 ]; | 270 ]; |
| 186 | 271 |
| 187 /** | 272 /** |
| 188 * Returns the name of the given file list entry. | 273 * Returns the name of the given file list entry. |
| 189 * @param {Array.<string>} file An entry in a file list. | 274 * @param {Array.<string>} file An entry in a file list. |
| (...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1273 appId2, | 1358 appId2, |
| 1274 [650, 490], | 1359 [650, 490], |
| 1275 this.next); | 1360 this.next); |
| 1276 }, | 1361 }, |
| 1277 // Check for errors. | 1362 // Check for errors. |
| 1278 function() { | 1363 function() { |
| 1279 checkIfNoErrorsOccured(this.next); | 1364 checkIfNoErrorsOccured(this.next); |
| 1280 } | 1365 } |
| 1281 ]); | 1366 ]); |
| 1282 }; | 1367 }; |
| OLD | NEW |