Upstream version 7.36.149.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 'use strict';
6
7 /**
8  * Runs all of the test cases, one by one.
9  */
10 chrome.test.runTests([
11   // Tests whether mounting succeeds, when a non-empty name is provided.
12   function goodDisplayName() {
13     var onTestSuccess = chrome.test.callbackPass(function() {});
14     chrome.fileSystemProvider.mount(
15       'test file system',
16       function(fileSystemId) {
17         chrome.test.assertEq('number', typeof(fileSystemId));
18         chrome.test.assertEq(1, fileSystemId);
19         onTestSuccess();
20       },
21       function(error) {
22         chrome.test.fail();
23       }
24     );
25   },
26
27   // Verifies that mounting fails, when an empty string is provided as a name.
28   function emptyDisplayName() {
29     var onTestSuccess = chrome.test.callbackPass(function() {});
30     chrome.fileSystemProvider.mount(
31       '',
32       function(fileSystemId) {
33         chrome.test.fail();
34       },
35       function(error) {
36         chrome.test.assertEq('SecurityError', error.name);
37         onTestSuccess();
38       }
39     );
40   },
41
42   // End to end test. Mounts a volume using fileSystemProvider.mount(), then
43   // checks if the mounted volume is added to VolumeManager, by querying
44   // fileBrowserPrivate.getVolumeMetadataList().
45   function successfulMount() {
46     var onTestSuccess = chrome.test.callbackPass(function() {});
47     chrome.fileSystemProvider.mount(
48       'caramel-candy.zip',
49       function(fileSystemId) {
50           chrome.test.assertTrue(fileSystemId > 0);
51         chrome.fileBrowserPrivate.getVolumeMetadataList(function(volumeList) {
52           var found = volumeList.filter(function(volumeInfo) {
53             return volumeInfo.volumeId ==
54                 'provided:' + chrome.runtime.id + '-' + fileSystemId + '-user';
55           });
56           chrome.test.assertEq(1, found.length);
57           onTestSuccess();
58         });
59       },
60       function(error) {
61         chrome.test.fail();
62       });
63   },
64
65   // Checks is limit for mounted file systems per profile works correctly.
66   // Tries to create more than allowed number of file systems. All of the mount
67   // requests should succeed, except the last one which should fail with a
68   // security error.
69   function stressMountTest() {
70     var onTestSuccess = chrome.test.callbackPass(function() {});
71     var ALREADY_MOUNTED_FILE_SYSTEMS = 2;  // By previous tests.
72     var MAX_FILE_SYSTEMS = 16;
73     var index = 0;
74     var tryNextOne = function() {
75       index++;
76       if (index < MAX_FILE_SYSTEMS - ALREADY_MOUNTED_FILE_SYSTEMS + 1) {
77         chrome.fileSystemProvider.mount(
78             index + 'th file system',
79             function(fileSystemId) {
80               chrome.test.assertTrue(fileSystemId > 0);
81               tryNextOne();
82             },
83             chrome.test.fail);
84       } else {
85         chrome.fileSystemProvider.mount(
86             'over the limit fs',
87             chrome.test.fail,
88             function(error) {
89               chrome.test.assertEq('SecurityError', error.name);
90               onTestSuccess();
91             });
92       }
93     };
94     tryNextOne();
95   }
96 ]);