1 // Copyright 2014 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.
11 var FIRST_FILE_SYSTEM_ID
= 'vanilla';
17 var SECOND_FILE_SYSTEM_ID
= 'ice-cream';
20 * Sets up the tests. Called once per all test cases. In case of a failure,
21 * the callback is not called.
23 * @param {function()} callback Success callback.
25 function setUp(callback
) {
27 new Promise(function(fulfill
, reject
) {
28 chrome
.fileSystemProvider
.mount(
29 {fileSystemId
: FIRST_FILE_SYSTEM_ID
, displayName
: 'vanilla.zip'},
30 chrome
.test
.callbackPass(fulfill
));
32 new Promise(function(fulfill
, reject
) {
33 chrome
.fileSystemProvider
.mount(
34 {fileSystemId
: SECOND_FILE_SYSTEM_ID
, displayName
: 'ice-cream.zip'},
35 chrome
.test
.callbackPass(fulfill
));
37 ]).then(callback
).catch(function(error
) {
38 chrome
.test
.fail(error
.stack
|| error
);
43 * Runs all of the test cases, one by one.
46 chrome
.test
.runTests([
47 // Tests the fileSystemProvider.unmount(). Verifies if the unmount event
48 // is emitted by VolumeManager.
50 var onMountCompleted = function(event
) {
51 chrome
.test
.assertEq('unmount', event
.eventType
);
52 chrome
.test
.assertEq('success', event
.status
);
54 chrome
.runtime
.id
, event
.volumeMetadata
.extensionId
);
56 FIRST_FILE_SYSTEM_ID
, event
.volumeMetadata
.fileSystemId
);
57 chrome
.fileManagerPrivate
.onMountCompleted
.removeListener(
61 chrome
.fileManagerPrivate
.onMountCompleted
.addListener(
63 chrome
.fileSystemProvider
.unmount(
64 {fileSystemId
: FIRST_FILE_SYSTEM_ID
},
65 chrome
.test
.callbackPass());
68 // Tests the fileSystemProvider.unmount() with a wrong id. Verifies that
69 // it fails with a correct error code.
70 function unmountWrongId() {
71 chrome
.fileSystemProvider
.unmount(
72 {fileSystemId
: 'wrong-fs-id'},
73 chrome
.test
.callbackFail('NOT_FOUND'));
76 // Tests if fileManagerPrivate.removeMount() for provided file systems emits
77 // the onMountRequested() event with correct arguments.
78 function requestUnmountSuccess() {
79 var onUnmountRequested
= chrome
.test
.callbackPass(
80 function(options
, onSuccess
, onError
) {
81 chrome
.test
.assertEq(SECOND_FILE_SYSTEM_ID
, options
.fileSystemId
);
82 // Not calling fileSystemProvider.unmount(), so the onMountCompleted
83 // event will not be raised.
84 chrome
.fileSystemProvider
.onUnmountRequested
.removeListener(
89 chrome
.fileSystemProvider
.onUnmountRequested
.addListener(
92 test_util
.getVolumeInfo(SECOND_FILE_SYSTEM_ID
, function(volumeInfo
) {
93 chrome
.test
.assertTrue(!!volumeInfo
);
94 chrome
.fileManagerPrivate
.removeMount(volumeInfo
.volumeId
);
98 // End to end test with a failure. Invokes fileSystemProvider.removeMount()
99 // on a provided file system, and verifies (1) if the onMountRequested()
100 // event is called with correct aguments, and (2) if calling onError(),
101 // results in an unmount event fired from the VolumeManager instance.
102 function requestUnmountError() {
103 var unmountRequested
= false;
105 var onUnmountRequested = function(options
, onSuccess
, onError
) {
106 chrome
.test
.assertEq(false, unmountRequested
);
107 chrome
.test
.assertEq(SECOND_FILE_SYSTEM_ID
, options
.fileSystemId
);
108 onError('IN_USE'); // enum ProviderError.
109 unmountRequested
= true;
110 chrome
.fileSystemProvider
.onUnmountRequested
.removeListener(
114 var onMountCompleted
= chrome
.test
.callbackPass(function(event
) {
115 chrome
.test
.assertEq('unmount', event
.eventType
);
116 chrome
.test
.assertEq('error_unknown', event
.status
);
117 chrome
.test
.assertEq(
118 chrome
.runtime
.id
, event
.volumeMetadata
.extensionId
);
119 chrome
.test
.assertEq(
120 SECOND_FILE_SYSTEM_ID
, event
.volumeMetadata
.fileSystemId
);
121 chrome
.test
.assertTrue(unmountRequested
);
123 // Remove the handlers and mark the test as succeeded.
124 chrome
.fileManagerPrivate
.removeMount(SECOND_FILE_SYSTEM_ID
);
125 chrome
.fileManagerPrivate
.onMountCompleted
.removeListener(
129 chrome
.fileSystemProvider
.onUnmountRequested
.addListener(
131 chrome
.fileManagerPrivate
.onMountCompleted
.addListener(onMountCompleted
);
133 test_util
.getVolumeInfo(SECOND_FILE_SYSTEM_ID
, function(volumeInfo
) {
134 chrome
.test
.assertTrue(!!volumeInfo
);
135 chrome
.fileManagerPrivate
.removeMount(volumeInfo
.volumeId
);
141 // Setup and run all of the test cases.