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 function() { fulfill(); },
31 function(error) { reject(error); });
33 new Promise(function(fulfill, reject) {
34 chrome.fileSystemProvider.mount(
35 {fileSystemId: SECOND_FILE_SYSTEM_ID, displayName: 'ice-cream.zip'},
36 function() { fulfill(); },
37 function(error) { reject(error); });
39 ]).then(callback).catch(function(error) {
40 chrome.test.fail(error.name);
45 * Runs all of the test cases, one by one.
48 chrome.test.runTests([
49 // Tests the fileSystemProvider.unmount(). Verifies if the unmount event
50 // is emitted by VolumeManager.
52 var onTestSuccess = chrome.test.callbackPass();
54 var onMountCompleted = function(event) {
55 chrome.test.assertEq('unmount', event.eventType);
56 chrome.test.assertEq('success', event.status);
58 chrome.runtime.id, event.volumeMetadata.extensionId);
60 FIRST_FILE_SYSTEM_ID, event.volumeMetadata.fileSystemId);
61 chrome.fileManagerPrivate.onMountCompleted.removeListener(
66 chrome.fileManagerPrivate.onMountCompleted.addListener(
68 chrome.fileSystemProvider.unmount(
69 {fileSystemId: FIRST_FILE_SYSTEM_ID},
71 // Wait for the unmount event.
74 chrome.test.fail(error.name);
78 // Tests the fileSystemProvider.unmount() with a wrong id. Verifies that
79 // it fails with a correct error code.
80 function unmountWrongId() {
81 var onTestSuccess = chrome.test.callbackPass();
82 chrome.fileSystemProvider.unmount(
83 {fileSystemId: 'wrong-fs-id'},
88 chrome.test.assertEq('SecurityError', error.name);
93 // Tests if fileManagerPrivate.removeMount() for provided file systems emits
94 // the onMountRequested() event with correct arguments.
95 function requestUnmountSuccess() {
96 var onTestSuccess = chrome.test.callbackPass();
98 var onUnmountRequested = function(options, onSuccess, onError) {
99 chrome.test.assertEq(SECOND_FILE_SYSTEM_ID, options.fileSystemId);
101 // Not calling fileSystemProvider.unmount(), so the onMountCompleted
102 // event will not be raised.
103 chrome.fileSystemProvider.onUnmountRequested.removeListener(
108 chrome.fileSystemProvider.onUnmountRequested.addListener(
111 test_util.getVolumeInfo(SECOND_FILE_SYSTEM_ID, function(volumeInfo) {
112 chrome.test.assertTrue(!!volumeInfo);
113 chrome.fileManagerPrivate.removeMount(volumeInfo.volumeId);
117 // End to end test with a failure. Invokes fileSystemProvider.removeMount()
118 // on a provided file system, and verifies (1) if the onMountRequested()
119 // event is called with correct aguments, and (2) if calling onError(),
120 // results in an unmount event fired from the VolumeManager instance.
121 function requestUnmountError() {
122 var onTestSuccess = chrome.test.callbackPass();
123 var unmountRequested = false;
125 var onUnmountRequested = function(options, onSuccess, onError) {
126 chrome.test.assertEq(false, unmountRequested);
127 chrome.test.assertEq(SECOND_FILE_SYSTEM_ID, options.fileSystemId);
128 onError('IN_USE'); // enum ProviderError.
129 unmountRequested = true;
130 chrome.fileSystemProvider.onUnmountRequested.removeListener(
134 var onMountCompleted = function(event) {
135 chrome.test.assertEq('unmount', event.eventType);
136 chrome.test.assertEq('error_unknown', event.status);
137 chrome.test.assertEq(
138 chrome.runtime.id, event.volumeMetadata.extensionId);
139 chrome.test.assertEq(
140 SECOND_FILE_SYSTEM_ID, event.volumeMetadata.fileSystemId);
141 chrome.test.assertTrue(unmountRequested);
143 // Remove the handlers and mark the test as succeeded.
144 chrome.fileManagerPrivate.removeMount(SECOND_FILE_SYSTEM_ID);
145 chrome.fileManagerPrivate.onMountCompleted.removeListener(
150 chrome.fileSystemProvider.onUnmountRequested.addListener(
152 chrome.fileManagerPrivate.onMountCompleted.addListener(onMountCompleted);
154 test_util.getVolumeInfo(SECOND_FILE_SYSTEM_ID, function(volumeInfo) {
155 chrome.test.assertTrue(!!volumeInfo);
156 chrome.fileManagerPrivate.removeMount(volumeInfo.volumeId);
162 // Setup and run all of the test cases.