Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / file_system_provider / mount / test.js
blob0a968c6b2228192f48377c1adbf39e4e89568180
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.
5 'use strict';
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 chrome.fileSystemProvider.mount(
14 {fileSystemId: 'file-system-id', displayName: 'file-system-name'},
15 chrome.test.callbackPass());
18 // Verifies that mounting fails, when an empty string is provided as a name.
19 function emptyDisplayName() {
20 chrome.fileSystemProvider.mount(
21 {fileSystemId: 'file-system-id-2', displayName: ''},
22 chrome.test.callbackFail('INVALID_OPERATION'));
25 // Verifies that mounting fails, when an empty string is provided as an Id
26 function emptyFileSystemId() {
27 chrome.fileSystemProvider.mount(
28 {fileSystemId: '', displayName: 'File System Name'},
29 chrome.test.callbackFail('INVALID_OPERATION'));
32 // Verifies that mounting succeeds, when a positive limit for opened files is
33 // provided.
34 function goodOpenedFilesLimit() {
35 chrome.fileSystemProvider.mount({
36 fileSystemId: 'file-system-id-3',
37 displayName: 'File System Name',
38 openedFilesLimit: 10
39 }, chrome.test.callbackPass());
42 // Verifies that mounting succeeds, when limit for number of opened files is
43 // set to 0. It means no limit.
44 function goodOpenedFilesLimit() {
45 chrome.fileSystemProvider.mount({
46 fileSystemId: 'file-system-id-4',
47 displayName: 'File System Name',
48 openedFilesLimit: 0
49 }, chrome.test.callbackPass());
52 // Verifies that mounting fails, when a negative limit for opened files is
53 // provided.
54 function illegalOpenedFilesLimit() {
55 chrome.fileSystemProvider.mount({
56 fileSystemId: 'file-system-id-5',
57 displayName: 'File System Name',
58 openedFilesLimit: -1
59 }, chrome.test.callbackFail('INVALID_OPERATION'));
62 // End to end test. Mounts a volume using fileSystemProvider.mount(), then
63 // checks if the mounted volume is added to VolumeManager, by querying
64 // fileManagerPrivate.getVolumeMetadataList().
65 function successfulMount() {
66 var fileSystemId = 'caramel-candy';
67 chrome.fileSystemProvider.mount(
69 fileSystemId: fileSystemId,
70 displayName: 'caramel-candy.zip',
72 chrome.test.callbackPass(function() {
73 chrome.fileManagerPrivate.getVolumeMetadataList(function(volumeList) {
74 var volumeInfo;
75 volumeList.forEach(function(inVolumeInfo) {
76 if (inVolumeInfo.extensionId === chrome.runtime.id &&
77 inVolumeInfo.fileSystemId === fileSystemId) {
78 volumeInfo = inVolumeInfo;
80 });
81 chrome.test.assertTrue(!!volumeInfo);
82 chrome.test.assertTrue(volumeInfo.isReadOnly);
83 });
84 }));
87 // Checks whether mounting a file system in writable mode ends up on filling
88 // out the volume info properly.
89 function successfulWritableMount() {
90 var fileSystemId = 'caramel-fudges';
91 chrome.fileSystemProvider.mount(
93 fileSystemId: fileSystemId,
94 displayName: 'caramel-fudges.zip',
95 writable: true
97 chrome.test.callbackPass(function() {
98 chrome.fileManagerPrivate.getVolumeMetadataList(function(volumeList) {
99 var volumeInfo;
100 volumeList.forEach(function(inVolumeInfo) {
101 if (inVolumeInfo.extensionId === chrome.runtime.id &&
102 inVolumeInfo.fileSystemId === fileSystemId) {
103 volumeInfo = inVolumeInfo;
106 chrome.test.assertTrue(!!volumeInfo);
107 chrome.test.assertFalse(volumeInfo.isReadOnly);
109 }));
112 // Checks is limit for mounted file systems per profile works correctly.
113 // Tries to create more than allowed number of file systems. All of the mount
114 // requests should succeed, except the last one which should fail with a
115 // security error.
116 function stressMountTest() {
117 var ALREADY_MOUNTED_FILE_SYSTEMS = 5; // By previous tests.
118 var MAX_FILE_SYSTEMS = 16;
119 var index = 0;
120 var tryNextOne = function() {
121 index++;
122 if (index < MAX_FILE_SYSTEMS - ALREADY_MOUNTED_FILE_SYSTEMS + 1) {
123 var fileSystemId = index + '-stress-test';
124 chrome.fileSystemProvider.mount(
125 {fileSystemId: fileSystemId, displayName: index + 'th File System'},
126 chrome.test.callbackPass(tryNextOne));
127 } else {
128 chrome.fileSystemProvider.mount(
130 fileSystemId: 'over-the-limit-fs-id',
131 displayName: 'Over The Limit File System'
133 chrome.test.callbackFail('TOO_MANY_OPENED'));
136 tryNextOne();
139 // Tests if fileManagerPrivate.addProvidedFileSystem() emits the
140 // onMountRequested() event.
141 function requestMountSuccess() {
142 var onMountRequested = chrome.test.callbackPass(
143 function(onSuccess, onError) {
144 chrome.fileSystemProvider.onMountRequested.removeListener(
145 onMountRequested);
148 chrome.fileSystemProvider.onMountRequested.addListener(
149 onMountRequested);
150 chrome.fileManagerPrivate.getProvidingExtensions(
151 chrome.test.callbackPass(function(extensions) {
152 chrome.test.assertEq(extensions.length, 1);
153 chrome.test.assertEq(chrome.runtime.id, extensions[0].extensionId);
154 chrome.test.assertEq(
155 chrome.runtime.getManifest().name, extensions[0].name);
156 chrome.test.assertFalse(extensions[0].configurable);
157 chrome.test.assertFalse(extensions[0].watchable);
158 chrome.test.assertFalse(extensions[0].multipleMounts);
159 chrome.test.assertEq('network', extensions[0].source);
160 }));
162 chrome.fileManagerPrivate.addProvidedFileSystem(
163 chrome.runtime.id,
164 chrome.test.callbackPass(function() {}));