Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / file_system_provider / mount / test.js
1 // Copyright 2013 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 chrome.test.runTests([
6   function goodDisplayName() {
7     chrome.fileSystemProvider.mount(
8       'test file system',
9       function(fileSystemId) {
10         chrome.test.assertEq('number', typeof(fileSystemId));
11         chrome.test.assertTrue(fileSystemId == 1);
12         chrome.test.succeed();
13       },
14       function(error) {
15         chrome.test.fail();
16       }
17     );
18   },
19
20   function emptyDisplayName() {
21     chrome.fileSystemProvider.mount(
22       '',
23       function(fileSystemId) {
24         chrome.test.fail();
25       },
26       function(error) {
27         chrome.test.assertEq('SecurityError', error.name);
28         chrome.test.succeed();
29       }
30     );
31   },
32
33   function successfulMount() {
34     chrome.fileSystemProvider.mount(
35       'caramel-candy.zip',
36       function(fileSystemId) {
37           chrome.test.assertTrue(fileSystemId > 0);
38         chrome.fileBrowserPrivate.getVolumeMetadataList(function(volumeList) {
39           var found = volumeList.filter(function(volumeInfo) {
40             return volumeInfo.volumeId ==
41                 'provided:' + chrome.runtime.id + '-' + fileSystemId + '-user';
42           });
43           chrome.test.assertEq(1, found.length);
44           chrome.test.succeed();
45         });
46       },
47       function(error) {
48         chrome.test.fail();
49       });
50   },
51
52   function stressMountTest() {
53     // Try to create more than allowed number of file systems. All of the mount
54     // requests should succeed, except the last one which should fail with a
55     // security error.
56     var ALREADY_MOUNTED_FILE_SYSTEMS = 2;  // By previous tests.
57     var MAX_FILE_SYSTEMS = 16;
58     var index = 0;
59     var tryNextOne = function() {
60       index++;
61       if (index < MAX_FILE_SYSTEMS - ALREADY_MOUNTED_FILE_SYSTEMS + 1) {
62         chrome.fileSystemProvider.mount(
63             index + 'th file system',
64             function(fileSystemId) {
65               chrome.test.assertTrue(fileSystemId > 0);
66               tryNextOne();
67             },
68             chrome.test.fail);
69       } else {
70         chrome.fileSystemProvider.mount(
71             'over the limit fs',
72             chrome.test.fail,
73             function(error) {
74               chrome.test.assertEq('SecurityError', error.name);
75               chrome.test.succeed();
76             });
77       }
78     };
79     tryNextOne();
80   }
81 ]);