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,
16 profile: {profileId: "", displayName: "", isCurrentProfile: true}
19 var expectedVolume2 = {
20 volumeId: 'removable:mount_path2',
21 volumeLabel: 'mount_path2',
22 sourcePath: 'device_path2',
23 volumeType: 'removable',
25 devicePath: 'system_path_prefix2',
29 profile: {profileId: "", displayName: "", isCurrentProfile: true}
32 var expectedVolume3 = {
33 volumeId: 'removable:mount_path3',
34 volumeLabel: 'mount_path3',
35 sourcePath: 'device_path3',
36 volumeType: 'removable',
37 deviceType: 'optical',
38 devicePath: 'system_path_prefix3',
42 profile: {profileId: "", displayName: "", isCurrentProfile: true}
45 var expectedDownloadsVolume = {
46 volumeId: /^downloads:Downloads[^\/]*$/,
48 volumeType: 'downloads',
51 profile: {profileId: "", displayName: "", isCurrentProfile: true}
54 var expectedDriveVolume = {
55 volumeId: /^drive:drive[^\/]*$/,
57 sourcePath: /^\/special\/drive[^\/]*$/,
61 profile: {profileId: "", displayName: "", isCurrentProfile: true}
64 var expectedArchiveVolume = {
65 volumeId: 'archive:archive_mount_path',
66 volumeLabel: 'archive_mount_path',
67 sourcePath: /removable\/mount_path3\/archive.zip$/,
68 volumeType: 'archive',
71 profile: {profileId: "", displayName: "", isCurrentProfile: true}
74 // List of expected mount points.
75 // NOTE: this has to be synced with values in file_manager_private_apitest.cc
76 // and values sorted by volumeId.
77 var expectedVolumeList = [
78 expectedArchiveVolume,
79 expectedDownloadsVolume,
86 function validateObject(received, expected, name) {
87 for (var key in expected) {
88 if (expected[key] instanceof RegExp) {
89 if (!expected[key].test(received[key])) {
90 console.warn('Expected "' + key + '" ' + name + ' property to match: ' +
91 expected[key] + ', but got: "' + received[key] + '".');
94 } else if (expected[key] instanceof Object) {
95 if (!validateObject(received[key], expected[key], name + "." + key))
97 } else if (received[key] != expected[key]) {
98 console.warn('Expected "' + key + '" ' + name + ' property to be: "' +
99 expected[key] + '"' + ', but got: "' + received[key] +
105 var expectedKeys = Object.keys(expected);
106 var receivedKeys = Object.keys(received);
107 if (expectedKeys.length !== receivedKeys.length) {
108 var unexpectedKeys = [];
109 for (var i = 0; i < receivedKeys.length; i++) {
110 if (!(receivedKeys[i] in expected))
111 unexpectedKeys.push(receivedKeys[i]);
114 console.warn('Unexpected properties found: ' + unexpectedKeys);
120 chrome.test.runTests([
121 function removeMount() {
122 chrome.fileManagerPrivate.removeMount('archive:archive_mount_path');
124 // We actually check this one on C++ side. If MountLibrary.RemoveMount
125 // doesn't get called, test will fail.
126 chrome.test.succeed();
129 function getVolumeMetadataList() {
130 chrome.fileManagerPrivate.getVolumeMetadataList(
131 chrome.test.callbackPass(function(result) {
132 chrome.test.assertEq(expectedVolumeList.length, result.length,
133 'getMountPoints returned wrong number of mount points.');
134 for (var i = 0; i < expectedVolumeList.length; i++) {
135 chrome.test.assertTrue(
137 result[i], expectedVolumeList[i], 'volumeMetadata'),
138 'getMountPoints result[' + i + '] not as expected');