38c3a39199a2c69c3365edededde5c88a3a5a619
[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();
14     chrome.fileSystemProvider.mount(
15         {fileSystemId: 'file-system-id', displayName: 'file-system-name'},
16         function() {
17           onTestSuccess();
18         },
19         function(error) {
20           chrome.test.fail();
21         });
22   },
23
24   // Verifies that mounting fails, when an empty string is provided as a name.
25   function emptyDisplayName() {
26     var onTestSuccess = chrome.test.callbackPass();
27     chrome.fileSystemProvider.mount(
28         {fileSystemId: 'file-system-id', displayName: ''},
29         function() {
30           chrome.test.fail();
31         },
32         function(error) {
33           chrome.test.assertEq('SecurityError', error.name);
34           onTestSuccess();
35         });
36   },
37   // Verifies that mounting fails, when an empty string is provided as an Id
38   function emptyFileSystemId() {
39     var onTestSuccess = chrome.test.callbackPass();
40     chrome.fileSystemProvider.mount(
41         {fileSystemId: '', displayName: 'File System Name'},
42         function() {
43           chrome.test.fail();
44         },
45         function(error) {
46           chrome.test.assertEq('SecurityError', error.name);
47           onTestSuccess();
48         }
49       );
50   },
51
52   // End to end test. Mounts a volume using fileSystemProvider.mount(), then
53   // checks if the mounted volume is added to VolumeManager, by querying
54   // fileBrowserPrivate.getVolumeMetadataList().
55   function successfulMount() {
56     var onTestSuccess = chrome.test.callbackPass();
57     var fileSystemId = 'caramel-candy';
58     chrome.fileSystemProvider.mount(
59         {fileSystemId: fileSystemId, displayName: 'caramel-candy.zip'},
60         function() {
61           chrome.fileBrowserPrivate.getVolumeMetadataList(function(volumeList) {
62             var found = false;
63             volumeList.forEach(function(volumeInfo) {
64               if (volumeInfo.extensionId == chrome.runtime.id &&
65                   volumeInfo.fileSystemId == fileSystemId) {
66                 found = true;
67               }
68             });
69             chrome.test.assertTrue(found);
70             onTestSuccess();
71           });
72         },
73         function(error) {
74           chrome.test.fail();
75         });
76   },
77
78   // Checks is limit for mounted file systems per profile works correctly.
79   // Tries to create more than allowed number of file systems. All of the mount
80   // requests should succeed, except the last one which should fail with a
81   // security error.
82   function stressMountTest() {
83     var onTestSuccess = chrome.test.callbackPass();
84     var ALREADY_MOUNTED_FILE_SYSTEMS = 2;  // By previous tests.
85     var MAX_FILE_SYSTEMS = 16;
86     var index = 0;
87     var tryNextOne = function() {
88       index++;
89       if (index < MAX_FILE_SYSTEMS - ALREADY_MOUNTED_FILE_SYSTEMS + 1) {
90         var fileSystemId = index + '-stress-test';
91         chrome.fileSystemProvider.mount(
92             {fileSystemId: fileSystemId, displayName: index + 'th File System'},
93             function() {
94               tryNextOne();
95             },
96             function(error) {
97               chrome.test.fail(error.name);
98             });
99       } else {
100         chrome.fileSystemProvider.mount(
101             {
102               fileSystemId: 'over-the-limit-fs-id',
103               displayName: 'Over The Limit File System'
104             },
105             function() {
106               chrome.test.fail();
107             },
108             function(error) {
109               chrome.test.assertEq('SecurityError', error.name);
110               onTestSuccess();
111             });
112       }
113     };
114     tryNextOne();
115   }
116 ]);