OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // These have to be sync'd with file_browser_private_apitest.cc | |
6 var expectedVolume1 = { | |
7 devicePath: 'device_path1', | |
8 mountPath: 'removable/mount_path1', | |
9 systemPath: 'system_path1', | |
10 filePath: 'file_path1', | |
11 deviceLabel: 'device_label1', | |
12 driveLabel: 'drive_label1', | |
13 deviceType: 'usb', | |
14 totalSize: 1073741824, | |
15 isParent: false, | |
16 isReadOnly: false, | |
17 hasMedia: false, | |
18 isOnBootDevice: false | |
19 }; | |
20 | |
21 var expectedVolume2 = { | |
22 devicePath: 'device_path2', | |
23 mountPath: 'removable/mount_path2', | |
24 systemPath: 'system_path2', | |
25 filePath: 'file_path2', | |
26 deviceLabel: 'device_label2', | |
27 driveLabel: 'drive_label2', | |
28 deviceType: 'mobile', | |
29 totalSize: 47723, | |
30 isParent: true, | |
31 isReadOnly: true, | |
32 hasMedia: true, | |
33 isOnBootDevice: true | |
34 }; | |
35 | |
36 var expectedVolume3 = { | |
37 devicePath: 'device_path3', | |
38 mountPath: 'removable/mount_path3', | |
39 systemPath: 'system_path3', | |
40 filePath: 'file_path3', | |
41 deviceLabel: 'device_label3', | |
42 driveLabel: 'drive_label3', | |
43 deviceType: 'optical', | |
44 totalSize: 0, | |
45 isParent: true, | |
46 isReadOnly: false, | |
47 hasMedia: false, | |
48 isOnBootDevice: true | |
49 }; | |
50 | |
51 var expectedDownloadsVolume = { | |
52 mountPath: 'Downloads', | |
53 isReadOnly: false, | |
54 }; | |
55 | |
56 // List of expected mount points. | |
57 // NOTE: this has to be synced with values in file_browser_private_apitest.cc | |
58 // and values sorted by mountPath. | |
59 var expectedMountPoints = [ | |
60 { | |
61 mountPath: 'Downloads', | |
62 mountCondition: '' | |
63 }, | |
64 { | |
65 sourcePath: 'archive_path', | |
66 mountPath: 'archive/archive_mount_path', | |
67 mountType: 'file', | |
68 mountCondition: '' | |
69 }, | |
70 { | |
71 sourcePath: 'device_path1', | |
72 mountPath: 'removable/mount_path1', | |
73 mountType: 'device', | |
74 mountCondition: '' | |
75 }, | |
76 { | |
77 sourcePath: 'device_path2', | |
78 mountPath: 'removable/mount_path2', | |
79 mountType: 'device', | |
80 mountCondition: '' | |
81 }, | |
82 { | |
83 sourcePath: 'device_path3', | |
84 mountPath: 'removable/mount_path3', | |
85 mountType: 'device', | |
86 mountCondition: '' | |
87 } | |
88 ]; | |
89 | |
90 function validateObject(received, expected, name) { | |
91 for (var key in expected) { | |
92 if (received[key] != expected[key]) { | |
93 console.warn('Expected "' + key + '" ' + name + ' property to be: "' + | |
94 expected[key] + '"' + ', but got: "' + received[key] + | |
95 '" instead.'); | |
96 return false; | |
97 } | |
98 } | |
99 if (Object.keys(expected).length != Object.keys(received).length) { | |
100 console.warn('Unexpected property found in returned volume'); | |
101 return false; | |
102 } | |
103 return true; | |
104 } | |
105 | |
106 function createFileUrl(fileName) { | |
107 var testExtensionId = 'ddammdhioacbehjngdmkjcjbnfginlla'; | |
108 var fileUrl = 'filesystem:chrome-extension://' + testExtensionId + | |
109 '/external/' + fileName; | |
110 return fileUrl; | |
111 } | |
112 | |
113 chrome.test.runTests([ | |
114 function removeMount() { | |
115 // The ID of this extension. | |
116 var fileUrl = createFileUrl('archive/archive_mount_path'); | |
117 | |
118 chrome.fileBrowserPrivate.removeMount(fileUrl); | |
119 | |
120 // We actually check this one on C++ side. If MountLibrary.RemoveMount | |
121 // doesn't get called, test will fail. | |
122 chrome.test.succeed(); | |
123 }, | |
124 | |
125 function getVolumeMetadataValid1() { | |
126 chrome.fileBrowserPrivate.getVolumeMetadata( | |
127 createFileUrl(expectedVolume1.mountPath), | |
128 chrome.test.callbackPass(function(result) { | |
129 chrome.test.assertTrue( | |
130 validateObject(result, expectedVolume1, 'volume'), | |
131 'getVolumeMetadata result for first volume not as expected'); | |
132 })); | |
133 }, | |
134 | |
135 function getVolumeMetadataValid2() { | |
136 chrome.fileBrowserPrivate.getVolumeMetadata( | |
137 createFileUrl(expectedVolume2.mountPath), | |
138 chrome.test.callbackPass(function(result) { | |
139 chrome.test.assertTrue( | |
140 validateObject(result, expectedVolume2, 'volume'), | |
141 'getVolumeMetadata result for second volume not as expected'); | |
142 })); | |
143 }, | |
144 | |
145 function getVolumeMetadataValid3() { | |
146 chrome.fileBrowserPrivate.getVolumeMetadata( | |
147 createFileUrl(expectedVolume3.mountPath), | |
148 chrome.test.callbackPass(function(result) { | |
149 chrome.test.assertTrue( | |
150 validateObject(result, expectedVolume3, 'volume'), | |
151 'getVolumeMetadata result for third volume not as expected'); | |
152 })); | |
153 }, | |
154 | |
155 function getVolumeMetadataDownloads() { | |
156 chrome.fileBrowserPrivate.getVolumeMetadata( | |
157 createFileUrl(expectedDownloadsVolume.mountPath), | |
158 chrome.test.callbackPass(function(result) { | |
159 chrome.test.assertTrue( | |
160 validateObject(result, expectedDownloadsVolume, 'volume'), | |
161 'getVolumeMetadata result for downloads volume not as expected'); | |
162 })); | |
163 }, | |
164 | |
165 function getVolumeMetadataNonExistentPath() { | |
166 chrome.fileBrowserPrivate.getVolumeMetadata( | |
167 createFileUrl('removable/non_existent_device_path'), | |
168 chrome.test.callbackPass(function(result) { | |
169 chrome.test.assertEq(undefined, result); | |
170 })); | |
171 }, | |
172 | |
173 function getVolumeMetadataArchive() { | |
174 chrome.fileBrowserPrivate.getVolumeMetadata( | |
175 createFileUrl('archive/archive_mount_path'), | |
176 chrome.test.callbackPass(function(result) { | |
177 chrome.test.assertEq(undefined, result); | |
178 })); | |
179 }, | |
180 | |
181 function getVolumeMetadataInvalidPath() { | |
182 chrome.fileBrowserPrivate.getVolumeMetadata( | |
183 'some path', | |
184 chrome.test.callbackFail('Invalid mount path.')); | |
185 }, | |
186 | |
187 function getMountPointsTest() { | |
188 chrome.fileBrowserPrivate.getMountPoints( | |
189 chrome.test.callbackPass(function(result) { | |
190 chrome.test.assertEq(result.length, expectedMountPoints.length, | |
191 'getMountPoints returned wrong number of mount points.'); | |
192 for (var i = 0; i < expectedMountPoints.length; i++) { | |
193 chrome.test.assertTrue( | |
194 validateObject(result[i], expectedMountPoints[i], 'mountPoint'), | |
195 'getMountPoints result[' + i + '] not as expected'); | |
196 } | |
197 })); | |
198 } | |
199 ]); | |
OLD | NEW |