Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / file_browser / mount_test / test.js
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_manager_private_apitest.cc
6 var expectedVolume1 = {
7   volumeId: 'removable:mount_path1',
8   volumeLabel: 'mount_path1',
9   sourcePath: 'device_path1',
10   volumeType: 'removable',
11   deviceType: 'usb',
12   devicePath: 'system_path_prefix1',
13   isParentDevice: false,
14   isReadOnly: false,
15   hasMedia: false,
16   profile: {profileId: "", displayName: "", isCurrentProfile: true}
17 };
18
19 var expectedVolume2 = {
20   volumeId: 'removable:mount_path2',
21   volumeLabel: 'mount_path2',
22   sourcePath: 'device_path2',
23   volumeType: 'removable',
24   deviceType: 'mobile',
25   devicePath: 'system_path_prefix2',
26   isParentDevice: true,
27   isReadOnly: true,
28   hasMedia: true,
29   profile: {profileId: "", displayName: "", isCurrentProfile: true}
30 };
31
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',
39   isParentDevice: true,
40   isReadOnly: false,
41   hasMedia: false,
42   profile: {profileId: "", displayName: "", isCurrentProfile: true}
43 };
44
45 var expectedDownloadsVolume = {
46   volumeId: /^downloads:Downloads[^\/]*$/,
47   volumeLabel: '',
48   volumeType: 'downloads',
49   isReadOnly: false,
50   hasMedia: false,
51   profile: {profileId: "", displayName: "", isCurrentProfile: true}
52 };
53
54 var expectedDriveVolume = {
55   volumeId: /^drive:drive[^\/]*$/,
56   volumeLabel: '',
57   sourcePath: /^\/special\/drive[^\/]*$/,
58   volumeType: 'drive',
59   isReadOnly: false,
60   hasMedia: false,
61   profile: {profileId: "", displayName: "", isCurrentProfile: true}
62 };
63
64 var expectedArchiveVolume = {
65   volumeId: 'archive:archive_mount_path',
66   volumeLabel: 'archive_mount_path',
67   sourcePath: /removable\/mount_path3\/archive.zip$/,
68   volumeType: 'archive',
69   isReadOnly: true,
70   hasMedia: false,
71   profile: {profileId: "", displayName: "", isCurrentProfile: true}
72 };
73
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,
80   expectedDriveVolume,
81   expectedVolume1,
82   expectedVolume2,
83   expectedVolume3,
84 ];
85
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] + '".');
92         return false;
93       }
94     } else if (expected[key] instanceof Object) {
95       if (!validateObject(received[key], expected[key], name + "." + key))
96         return false;
97     } else if (received[key] != expected[key]) {
98       console.warn('Expected "' + key + '" ' + name + ' property to be: "' +
99                   expected[key] + '"' + ', but got: "' + received[key] +
100                   '" instead.');
101       return false;
102     }
103   }
104
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]);
112     }
113
114     console.warn('Unexpected properties found: ' + unexpectedKeys);
115     return false;
116   }
117   return true;
118 }
119
120 chrome.test.runTests([
121   function removeMount() {
122     chrome.fileManagerPrivate.removeMount('archive:archive_mount_path');
123
124     // We actually check this one on C++ side. If MountLibrary.RemoveMount
125     // doesn't get called, test will fail.
126     chrome.test.succeed();
127   },
128
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(
136                 validateObject(
137                     result[i], expectedVolumeList[i], 'volumeMetadata'),
138                 'getMountPoints result[' + i + '] not as expected');
139           }
140     }));
141   }
142 ]);