Upstream version 9.38.198.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();
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
38   // Verifies that mounting fails, when an empty string is provided as an Id
39   function emptyFileSystemId() {
40     var onTestSuccess = chrome.test.callbackPass();
41     chrome.fileSystemProvider.mount(
42         {fileSystemId: '', displayName: 'File System Name'},
43         function() {
44           chrome.test.fail();
45         },
46         function(error) {
47           chrome.test.assertEq('SecurityError', error.name);
48           onTestSuccess();
49         }
50       );
51   },
52
53   // End to end test. Mounts a volume using fileSystemProvider.mount(), then
54   // checks if the mounted volume is added to VolumeManager, by querying
55   // fileBrowserPrivate.getVolumeMetadataList().
56   function successfulMount() {
57     var onTestSuccess = chrome.test.callbackPass();
58     var fileSystemId = 'caramel-candy';
59     chrome.fileSystemProvider.mount(
60         {fileSystemId: fileSystemId, displayName: 'caramel-candy.zip'},
61         function() {
62           chrome.fileBrowserPrivate.getVolumeMetadataList(function(volumeList) {
63             var volumeInfo;
64             volumeList.forEach(function(inVolumeInfo) {
65               if (inVolumeInfo.extensionId == chrome.runtime.id &&
66                   inVolumeInfo.fileSystemId == fileSystemId) {
67                 volumeInfo = inVolumeInfo;
68               }
69             });
70             chrome.test.assertTrue(!!volumeInfo);
71             chrome.test.assertTrue(volumeInfo.isReadOnly);
72             onTestSuccess();
73           });
74         },
75         function(error) {
76           chrome.test.fail();
77         });
78   },
79
80   // Checks whether mounting a file system in writable mode ends up on filling
81   // out the volume info properly.
82   function successfulWritableMount() {
83     var onTestSuccess = chrome.test.callbackPass();
84     var fileSystemId = 'caramel-fudges';
85     chrome.fileSystemProvider.mount(
86         {
87           fileSystemId: fileSystemId,
88           displayName: 'caramel-fudges.zip',
89           writable: true
90         },
91         function() {
92           chrome.fileBrowserPrivate.getVolumeMetadataList(function(volumeList) {
93             var volumeInfo;
94             volumeList.forEach(function(inVolumeInfo) {
95               if (inVolumeInfo.extensionId == chrome.runtime.id &&
96                   inVolumeInfo.fileSystemId == fileSystemId) {
97                 volumeInfo = inVolumeInfo;
98               }
99             });
100             chrome.test.assertTrue(!!volumeInfo);
101             chrome.test.assertFalse(volumeInfo.isReadOnly);
102             onTestSuccess();
103           });
104         },
105         function(error) {
106           chrome.test.fail();
107         });
108   },
109
110   // Checks is limit for mounted file systems per profile works correctly.
111   // Tries to create more than allowed number of file systems. All of the mount
112   // requests should succeed, except the last one which should fail with a
113   // security error.
114   function stressMountTest() {
115     var onTestSuccess = chrome.test.callbackPass();
116     var ALREADY_MOUNTED_FILE_SYSTEMS = 3;  // By previous tests.
117     var MAX_FILE_SYSTEMS = 16;
118     var index = 0;
119     var tryNextOne = function() {
120       index++;
121       if (index < MAX_FILE_SYSTEMS - ALREADY_MOUNTED_FILE_SYSTEMS + 1) {
122         var fileSystemId = index + '-stress-test';
123         chrome.fileSystemProvider.mount(
124             {fileSystemId: fileSystemId, displayName: index + 'th File System'},
125             function() {
126               tryNextOne();
127             },
128             function(error) {
129               chrome.test.fail(error.name);
130             });
131       } else {
132         chrome.fileSystemProvider.mount(
133             {
134               fileSystemId: 'over-the-limit-fs-id',
135               displayName: 'Over The Limit File System'
136             },
137             function() {
138               chrome.test.fail();
139             },
140             function(error) {
141               chrome.test.assertEq('SecurityError', error.name);
142               onTestSuccess();
143             });
144       }
145     };
146     tryNextOne();
147   }
148 ]);