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.
5 // These have to be sync'd with file_manager_private_apitest.cc
6 var expectedVolume1 = {
7 volumeId: 'removable:mount_path1',
8 volumeLabel: 'mount_path1',
9 sourcePath: 'device_path1',
10 volumeType: 'removable',
12 devicePath: 'system_path_prefix1',
13 isParentDevice: false,
19 profile: {profileId: '', displayName: '', isCurrentProfile: true},
22 var expectedVolume2 = {
23 volumeId: 'removable:mount_path2',
24 volumeLabel: 'mount_path2',
25 sourcePath: 'device_path2',
26 volumeType: 'removable',
28 devicePath: 'system_path_prefix2',
33 // This is not an MTP device, so it's watchable.
34 // TODO(mtomasz): Add a test for a real MTP device.
37 profile: {profileId: '', displayName: '', isCurrentProfile: true}
40 var expectedVolume3 = {
41 volumeId: 'removable:mount_path3',
42 volumeLabel: 'mount_path3',
43 sourcePath: 'device_path3',
44 volumeType: 'removable',
45 deviceType: 'optical',
46 devicePath: 'system_path_prefix3',
53 profile: {profileId: '', displayName: '', isCurrentProfile: true}
56 var expectedDownloadsVolume = {
57 volumeId: /^downloads:Downloads[^\/]*$/,
59 volumeType: 'downloads',
65 profile: {profileId: '', displayName: '', isCurrentProfile: true}
68 var expectedDriveVolume = {
69 volumeId: /^drive:drive[^\/]*$/,
71 sourcePath: /^\/special\/drive[^\/]*$/,
78 profile: {profileId: '', displayName: '', isCurrentProfile: true}
81 var expectedArchiveVolume = {
82 volumeId: 'archive:archive_mount_path',
83 volumeLabel: 'archive_mount_path',
84 sourcePath: /removable\/mount_path3\/archive.zip$/,
85 volumeType: 'archive',
91 profile: {profileId: '', displayName: '', isCurrentProfile: true}
94 var expectedProvidedVolume = {
95 volumeId: 'provided:',
97 volumeType: 'provided',
102 extensionId: 'testing-extension-id',
104 mountContext: 'auto',
106 profile: {profileId: '', displayName: '', isCurrentProfile: true}
109 // List of expected mount points.
110 // NOTE: this has to be synced with values in file_manager_private_apitest.cc
111 // and values sorted by volumeId.
112 var expectedVolumeList = [
113 expectedArchiveVolume,
114 expectedDownloadsVolume,
116 expectedProvidedVolume,
122 function validateObject(received, expected, name) {
123 for (var key in expected) {
124 if (expected[key] instanceof RegExp) {
125 if (!expected[key].test(received[key])) {
126 console.warn('Expected "' + key + '" ' + name + ' property to match: ' +
127 expected[key] + ', but got: "' + received[key] + '".');
130 } else if (expected[key] instanceof Object) {
131 if (!validateObject(received[key], expected[key], name + "." + key))
133 } else if (received[key] != expected[key]) {
134 console.warn('Expected "' + key + '" ' + name + ' property to be: "' +
135 expected[key] + '"' + ', but got: "' + received[key] +
141 var expectedKeys = Object.keys(expected);
142 var receivedKeys = Object.keys(received);
143 if (expectedKeys.length !== receivedKeys.length) {
144 var unexpectedKeys = [];
145 for (var i = 0; i < receivedKeys.length; i++) {
146 if (!(receivedKeys[i] in expected))
147 unexpectedKeys.push(receivedKeys[i]);
150 console.warn('Unexpected properties found: ' + unexpectedKeys);
156 chrome.test.runTests([
157 function removeMount() {
158 chrome.fileManagerPrivate.removeMount('archive:archive_mount_path');
160 // We actually check this one on C++ side. If MountLibrary.RemoveMount
161 // doesn't get called, test will fail.
162 chrome.test.succeed();
165 function getVolumeMetadataList() {
166 chrome.fileManagerPrivate.getVolumeMetadataList(
167 chrome.test.callbackPass(function(result) {
168 chrome.test.assertEq(expectedVolumeList.length, result.length,
169 'getMountPoints returned wrong number of mount points.');
170 for (var i = 0; i < expectedVolumeList.length; i++) {
171 chrome.test.assertTrue(
173 result[i], expectedVolumeList[i], 'volumeMetadata'),
174 'getMountPoints result[' + i + '] not as expected');