| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // These have to be sync'd with file_browser_private_apitest.cc | 5 // These have to be sync'd with file_browser_private_apitest.cc |
| 6 var expectedVolume1 = { | 6 var expectedVolume1 = { |
| 7 devicePath: 'device_path1', | 7 devicePath: 'device_path1', |
| 8 mountPath: 'removable/mount_path1', | 8 mountPath: 'removable/mount_path1', |
| 9 systemPath: 'system_path1', | 9 systemPath: 'system_path1', |
| 10 filePath: 'file_path1', | 10 filePath: 'file_path1', |
| 11 deviceLabel: 'device_label1', | 11 deviceLabel: 'device_label1', |
| 12 driveLabel: 'drive_label1', | 12 driveLabel: 'drive_label1', |
| 13 deviceType: 'usb', | 13 deviceType: 'usb', |
| 14 totalSize: 1073741824, | 14 totalSize: 1073741824, |
| 15 isParent: false, | 15 isParent: false, |
| 16 isReadOnly: false, | 16 isReadOnly: false, |
| 17 hasMedia: false, | 17 hasMedia: false, |
| 18 isOnBootDevice: false | 18 isOnBootDevice: false |
| 19 }; | 19 }; |
| 20 | 20 |
| 21 var expectedVolume2 = { | 21 var expectedVolume2 = { |
| 22 devicePath: 'device_path2', | 22 devicePath: 'device_path2', |
| 23 mountPath: 'removable/mount_path2', | 23 mountPath: 'removable/mount_path2', |
| 24 systemPath: 'system_path2', | 24 systemPath: 'system_path2', |
| 25 filePath: 'file_path2', | 25 filePath: 'file_path2', |
| 26 deviceLabel: 'device_label2', | 26 deviceLabel: 'device_label2', |
| 27 driveLabel: 'drive_label2', | 27 driveLabel: 'drive_label2', |
| 28 deviceType: 'mobile', | 28 deviceType: 'mobile', |
| 29 totalSize: 47723, | 29 totalSize: 47723, |
| 30 isParent: true, | 30 isParent: true, |
| 31 isReadOnly: true, | 31 isReadOnly: true, |
| 32 hasMedia: true, | 32 hasMedia: true, |
| 33 isOnBootDevice: true | 33 isOnBootDevice: true |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 var expectedVolume3 = { | 36 var expectedVolume3 = { |
| 37 devicePath: 'device_path3', | 37 devicePath: 'device_path3', |
| 38 mountPath: 'removable/mount_path3', | 38 mountPath: 'removable/mount_path3', |
| 39 systemPath: 'system_path3', | 39 systemPath: 'system_path3', |
| 40 filePath: 'file_path3', | 40 filePath: 'file_path3', |
| 41 deviceLabel: 'device_label3', | 41 deviceLabel: 'device_label3', |
| 42 driveLabel: 'drive_label3', | 42 driveLabel: 'drive_label3', |
| 43 deviceType: 'optical', | 43 deviceType: 'optical', |
| 44 totalSize: 0, | 44 totalSize: 0, |
| 45 isParent: true, | 45 isParent: true, |
| 46 isReadOnly: false, | 46 isReadOnly: false, |
| 47 hasMedia: false, | 47 hasMedia: false, |
| 48 isOnBootDevice: true | 48 isOnBootDevice: true |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 // List of expected mount points. | 51 // List of expected mount points. |
| 52 // We have to treat archives specially because their sourceUrl is set to | 52 // We have to treat archives specially because their sourceUrl is set to |
| 53 // filesystem url. To make it easier to define expectation for archives, | 53 // filesystem url. To make it easier to define expectation for archives, |
| 54 // instead of sourceUrl, we set sourcePath that will be converted to filesystem | 54 // instead of sourceUrl, we set sourcePath that will be converted to filesystem |
| (...skipping 30 matching lines...) Expand all Loading... |
| 85 function treatMountPointException(received, expected, key) { | 85 function treatMountPointException(received, expected, key) { |
| 86 if (key != 'sourcePath') | 86 if (key != 'sourcePath') |
| 87 return { wasValidated: false, success: false }; | 87 return { wasValidated: false, success: false }; |
| 88 var expectedSourceUrl = createFileUrl(expected[key]); | 88 var expectedSourceUrl = createFileUrl(expected[key]); |
| 89 var success = (expectedSourceUrl == received['sourceUrl']); | 89 var success = (expectedSourceUrl == received['sourceUrl']); |
| 90 if (!success) | 90 if (!success) |
| 91 console.warn("Expected mount point's sourceUrl to be '" + | 91 console.warn("Expected mount point's sourceUrl to be '" + |
| 92 expectedSourceUrl + "' but got '" + received['sourceUrl'] + | 92 expectedSourceUrl + "' but got '" + received['sourceUrl'] + |
| 93 "' instead."); | 93 "' instead."); |
| 94 return { wasValidated: true, success: success }; | 94 return { wasValidated: true, success: success }; |
| 95 }; | 95 } |
| 96 | 96 |
| 97 function validateObject(received, expected, name, treatException) { | 97 function validateObject(received, expected, name, treatException) { |
| 98 for (var key in expected) { | 98 for (var key in expected) { |
| 99 var validated = treatException && | 99 var validated = treatException && |
| 100 treatException(received, expected, key); | 100 treatException(received, expected, key); |
| 101 if (validated && validated.wasValidated) { | 101 if (validated && validated.wasValidated) { |
| 102 if (validated.success) { | 102 if (validated.success) { |
| 103 continue; | 103 continue; |
| 104 } else { | 104 } else { |
| 105 return false; | 105 return false; |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 if (received[key] != expected[key]) { | 108 if (received[key] != expected[key]) { |
| 109 console.warn('Expected "' + key + '" ' + name + ' property to be: "' + | 109 console.warn('Expected "' + key + '" ' + name + ' property to be: "' + |
| 110 expected[key] + '"' + ', but got: "' + received[key] + | 110 expected[key] + '"' + ', but got: "' + received[key] + |
| 111 '" instead.'); | 111 '" instead.'); |
| 112 return false; | 112 return false; |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 if (Object.keys(expected).length != Object.keys(received).length) { | 115 if (Object.keys(expected).length != Object.keys(received).length) { |
| 116 console.warn("Unexpected property found in returned volume"); | 116 console.warn('Unexpected property found in returned volume'); |
| 117 return false; | 117 return false; |
| 118 } | 118 } |
| 119 return true; | 119 return true; |
| 120 }; | 120 } |
| 121 | 121 |
| 122 function createFileUrl(fileName) { | 122 function createFileUrl(fileName) { |
| 123 var testExtensionId = "ddammdhioacbehjngdmkjcjbnfginlla"; | 123 var testExtensionId = 'ddammdhioacbehjngdmkjcjbnfginlla'; |
| 124 var fileUrl = "filesystem:chrome-extension://" + testExtensionId + | 124 var fileUrl = 'filesystem:chrome-extension://' + testExtensionId + |
| 125 "/external/" + fileName; | 125 '/external/' + fileName; |
| 126 return fileUrl; | 126 return fileUrl; |
| 127 }; | 127 } |
| 128 | 128 |
| 129 chrome.test.runTests([ | 129 chrome.test.runTests([ |
| 130 function removeMount() { | 130 function removeMount() { |
| 131 // The ID of this extension. | 131 // The ID of this extension. |
| 132 var fileUrl = createFileUrl("tmp/test_file.zip"); | 132 var fileUrl = createFileUrl('archive/archive_mount_path'); |
| 133 | 133 |
| 134 chrome.fileBrowserPrivate.removeMount(fileUrl); | 134 chrome.fileBrowserPrivate.removeMount(fileUrl); |
| 135 | 135 |
| 136 // We actually check this one on C++ side. If MountLibrary.RemoveMount | 136 // We actually check this one on C++ side. If MountLibrary.RemoveMount |
| 137 // doesn't get called, test will fail. | 137 // doesn't get called, test will fail. |
| 138 chrome.test.succeed(); | 138 chrome.test.succeed(); |
| 139 }, | 139 }, |
| 140 | 140 |
| 141 function getVolumeMetadataValid1() { | 141 function getVolumeMetadataValid1() { |
| 142 chrome.fileBrowserPrivate.getVolumeMetadata( | 142 chrome.fileBrowserPrivate.getVolumeMetadata( |
| 143 createFileUrl(expectedVolume1.mountPath), | 143 createFileUrl(expectedVolume1.mountPath), |
| 144 chrome.test.callbackPass(function(result) { | 144 chrome.test.callbackPass(function(result) { |
| 145 chrome.test.assertTrue( | 145 chrome.test.assertTrue( |
| 146 validateObject(result, expectedVolume1, 'volume'), | 146 validateObject(result, expectedVolume1, 'volume'), |
| 147 "getVolumeMetadata result for first volume not as expected"); | 147 'getVolumeMetadata result for first volume not as expected'); |
| 148 })); | 148 })); |
| 149 }, | 149 }, |
| 150 | 150 |
| 151 function getVolumeMetadataValid2() { | 151 function getVolumeMetadataValid2() { |
| 152 chrome.fileBrowserPrivate.getVolumeMetadata( | 152 chrome.fileBrowserPrivate.getVolumeMetadata( |
| 153 createFileUrl(expectedVolume2.mountPath), | 153 createFileUrl(expectedVolume2.mountPath), |
| 154 chrome.test.callbackPass(function(result) { | 154 chrome.test.callbackPass(function(result) { |
| 155 chrome.test.assertTrue( | 155 chrome.test.assertTrue( |
| 156 validateObject(result, expectedVolume2, 'volume'), | 156 validateObject(result, expectedVolume2, 'volume'), |
| 157 "getVolumeMetadata result for second volume not as expected"); | 157 'getVolumeMetadata result for second volume not as expected'); |
| 158 })); | 158 })); |
| 159 }, | 159 }, |
| 160 | 160 |
| 161 function getVolumeMetadataValid3() { | 161 function getVolumeMetadataValid3() { |
| 162 chrome.fileBrowserPrivate.getVolumeMetadata( | 162 chrome.fileBrowserPrivate.getVolumeMetadata( |
| 163 createFileUrl(expectedVolume3.mountPath), | 163 createFileUrl(expectedVolume3.mountPath), |
| 164 chrome.test.callbackPass(function(result) { | 164 chrome.test.callbackPass(function(result) { |
| 165 chrome.test.assertTrue( | 165 chrome.test.assertTrue( |
| 166 validateObject(result, expectedVolume3, 'volume'), | 166 validateObject(result, expectedVolume3, 'volume'), |
| 167 "getVolumeMetadata result for third volume not as expected"); | 167 'getVolumeMetadata result for third volume not as expected'); |
| 168 })); | 168 })); |
| 169 }, | 169 }, |
| 170 | 170 |
| 171 function getVolumeMetadataNonExistentPath() { | 171 function getVolumeMetadataNonExistentPath() { |
| 172 chrome.fileBrowserPrivate.getVolumeMetadata( | 172 chrome.fileBrowserPrivate.getVolumeMetadata( |
| 173 createFileUrl("removable/non_existent_device_path"), | 173 createFileUrl('removable/non_existent_device_path'), |
| 174 chrome.test.callbackPass(function(result) { | 174 chrome.test.callbackPass(function(result) { |
| 175 chrome.test.assertEq(undefined, result); | 175 chrome.test.assertEq(undefined, result); |
| 176 })); | 176 })); |
| 177 }, | 177 }, |
| 178 | 178 |
| 179 | 179 |
| 180 function getVolumeMetadataArchive() { | 180 function getVolumeMetadataArchive() { |
| 181 chrome.fileBrowserPrivate.getVolumeMetadata( | 181 chrome.fileBrowserPrivate.getVolumeMetadata( |
| 182 createFileUrl("archive/archive_mount_path"), | 182 createFileUrl('archive/archive_mount_path'), |
| 183 chrome.test.callbackPass(function(result) { | 183 chrome.test.callbackPass(function(result) { |
| 184 chrome.test.assertEq(undefined, result); | 184 chrome.test.assertEq(undefined, result); |
| 185 })); | 185 })); |
| 186 }, | 186 }, |
| 187 | 187 |
| 188 function getVolumeMetadataInvalidPath() { | 188 function getVolumeMetadataInvalidPath() { |
| 189 chrome.fileBrowserPrivate.getVolumeMetadata( | 189 chrome.fileBrowserPrivate.getVolumeMetadata( |
| 190 "some path", | 190 'some path', |
| 191 chrome.test.callbackFail("Invalid mount path.")); | 191 chrome.test.callbackFail('Invalid mount path.')); |
| 192 }, | 192 }, |
| 193 | 193 |
| 194 function getMountPointsTest() { | 194 function getMountPointsTest() { |
| 195 chrome.fileBrowserPrivate.getMountPoints( | 195 chrome.fileBrowserPrivate.getMountPoints( |
| 196 chrome.test.callbackPass(function(result) { | 196 chrome.test.callbackPass(function(result) { |
| 197 chrome.test.assertEq(result.length, expectedMountPoints.length, | 197 chrome.test.assertEq(result.length, expectedMountPoints.length, |
| 198 'getMountPoints returned wrong number of mount points.'); | 198 'getMountPoints returned wrong number of mount points.'); |
| 199 for (var i = 0; i < expectedMountPoints.length; i++) { | 199 for (var i = 0; i < expectedMountPoints.length; i++) { |
| 200 chrome.test.assertTrue( | 200 chrome.test.assertTrue( |
| 201 validateObject(result[i], expectedMountPoints[i], 'mountPoint', | 201 validateObject(result[i], expectedMountPoints[i], 'mountPoint', |
| 202 treatMountPointException), | 202 treatMountPointException), |
| 203 'getMountPoints result[' + i +'] not as expected'); | 203 'getMountPoints result[' + i + '] not as expected'); |
| 204 } | 204 } |
| 205 })); | 205 })); |
| 206 } | 206 } |
| 207 ]); | 207 ]); |
| OLD | NEW |