Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(766)

Side by Side Diff: chrome/test/data/extensions/api_test/file_system_provider/unmount/test.js

Issue 294073007: [fsp] Let extensions decide about the file system id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/data/extensions/api_test/file_system_provider/read_file/test.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 var firstFileSystemId; 7 /**
8 var secondFileSystemId; 8 * @type {string}
9 * @const
10 */
11 var FIRST_FILE_SYSTEM_ID = 'vanilla';
12
13 /**
14 * @type {string}
15 * @const
16 */
17 var SECOND_FILE_SYSTEM_ID = 'ice-cream';
18
19 /**
20 * Gets volume information for the provided file system.
21 *
22 * @param {string} fileSystemId Id of the provided file system.
23 * @param {function(Object)} callback Callback to be called on result, with the
24 * volume information object in case of success, or null if not found.
25 */
26 function getVolumeInfo(fileSystemId, callback) {
27 chrome.fileBrowserPrivate.getVolumeMetadataList(function(volumeList) {
28 for (var i = 0; i < volumeList.length; i++) {
29 if (volumeList[i].extensionId == chrome.runtime.id &&
30 volumeList[i].fileSystemId == fileSystemId) {
31 callback(volumeList[i]);
32 return;
33 }
34 }
35 callback(null);
36 });
37 }
9 38
10 /** 39 /**
11 * Sets up the tests. Called once per all test cases. In case of a failure, 40 * Sets up the tests. Called once per all test cases. In case of a failure,
12 * the callback is not called. 41 * the callback is not called.
13 * 42 *
14 * @param {function()} callback Success callback. 43 * @param {function()} callback Success callback.
15 */ 44 */
16 function setUp(callback) { 45 function setUp(callback) {
17 chrome.fileSystemProvider.mount('chocolate.zip', function(id) { 46 Promise.race([
18 firstFileSystemId = id; 47 new Promise(function(fulfill, reject) {
19 if (firstFileSystemId && secondFileSystemId) 48 chrome.fileSystemProvider.mount(
20 callback(); 49 FIRST_FILE_SYSTEM_ID,
21 }, function() { 50 'vanilla.zip',
22 chrome.test.fail(); 51 function() { fulfill(); },
23 }); 52 function(error) { reject(error); });
24 53 }),
25 chrome.fileSystemProvider.mount('banana.zip', function(id) { 54 new Promise(function(fulfill, reject) {
26 secondFileSystemId = id; 55 chrome.fileSystemProvider.mount(
27 if (firstFileSystemId && secondFileSystemId) 56 SECOND_FILE_SYSTEM_ID,
28 callback(); 57 'ice-cream.zip',
29 }, function() { 58 function() { fulfill(); },
30 chrome.test.fail(); 59 function(error) { reject(error); });
60 })
61 ]).then(callback).catch(function(error) {
62 chrome.test.fail(error.name);
31 }); 63 });
32 } 64 }
33 65
34 /** 66 /**
35 * Runs all of the test cases, one by one. 67 * Runs all of the test cases, one by one.
36 */ 68 */
37 function runTests() { 69 function runTests() {
38 chrome.test.runTests([ 70 chrome.test.runTests([
39 // Tests the fileSystemProvider.unmount(). Verifies if the unmount event 71 // Tests the fileSystemProvider.unmount(). Verifies if the unmount event
40 // is emitted by VolumeManager. 72 // is emitted by VolumeManager.
41 function unmount() { 73 function unmount() {
42 var onTestSuccess = chrome.test.callbackPass(function() {}); 74 var onTestSuccess = chrome.test.callbackPass();
43 var firstVolumeId =
44 'provided:' + chrome.runtime.id + '-' + firstFileSystemId + '-user';
45 75
46 var onMountCompleted = function(event) { 76 var onMountCompleted = function(event) {
47 chrome.test.assertEq('unmount', event.eventType); 77 chrome.test.assertEq('unmount', event.eventType);
48 chrome.test.assertEq('success', event.status); 78 chrome.test.assertEq('success', event.status);
49 chrome.test.assertEq(firstVolumeId, event.volumeMetadata.volumeId); 79 chrome.test.assertEq(
80 chrome.runtime.id, event.volumeMetadata.extensionId);
81 chrome.test.assertEq(
82 FIRST_FILE_SYSTEM_ID, event.volumeMetadata.fileSystemId);
50 chrome.fileBrowserPrivate.onMountCompleted.removeListener( 83 chrome.fileBrowserPrivate.onMountCompleted.removeListener(
51 onMountCompleted); 84 onMountCompleted);
52 onTestSuccess(); 85 onTestSuccess();
53 }; 86 };
54 87
55 chrome.fileBrowserPrivate.onMountCompleted.addListener( 88 chrome.fileBrowserPrivate.onMountCompleted.addListener(
56 onMountCompleted); 89 onMountCompleted);
57 chrome.fileSystemProvider.unmount(firstFileSystemId, function() { 90 chrome.fileSystemProvider.unmount(FIRST_FILE_SYSTEM_ID, function() {
58 // Wait for the unmount event. 91 // Wait for the unmount event.
59 }, function(error) { 92 }, function(error) {
60 chrome.test.fail(); 93 chrome.test.fail(error.name);
61 }); 94 });
62 }, 95 },
63 96
64 // Tests the fileSystemProvider.unmount() with a wrong id. Verifies that 97 // Tests the fileSystemProvider.unmount() with a wrong id. Verifies that
65 // it fails with a correct error code. 98 // it fails with a correct error code.
66 function unmountWrongId() { 99 function unmountWrongId() {
67 var onTestSuccess = chrome.test.callbackPass(function() {}); 100 var onTestSuccess = chrome.test.callbackPass();
68 chrome.fileSystemProvider.unmount(1337, function(fileSystemId) { 101 chrome.fileSystemProvider.unmount('wrong-fs-id', function() {
69 chrome.test.fail(); 102 chrome.test.fail();
70 }, function(error) { 103 }, function(error) {
71 chrome.test.assertEq('SecurityError', error.name); 104 chrome.test.assertEq('SecurityError', error.name);
72 onTestSuccess(); 105 onTestSuccess();
73 }); 106 });
74 }, 107 },
75 108
76 // Tests if fileBrowserPrivate.removeMount() for provided file systems emits 109 // Tests if fileBrowserPrivate.removeMount() for provided file systems emits
77 // the onMountRequested() event with correct arguments. 110 // the onMountRequested() event with correct arguments.
78 function requestUnmountSuccess() { 111 function requestUnmountSuccess() {
79 var onTestSuccess = chrome.test.callbackPass(function() {}); 112 var onTestSuccess = chrome.test.callbackPass();
80 var secondVolumeId =
81 'provided:' + chrome.runtime.id + '-' + secondFileSystemId + '-user';
82 113
83 var onUnmountRequested = function(fileSystemId, onSuccess, onError) { 114 var onUnmountRequested = function(fileSystemId, onSuccess, onError) {
84 chrome.test.assertEq(secondFileSystemId, fileSystemId); 115 chrome.test.assertEq(SECOND_FILE_SYSTEM_ID, fileSystemId);
85 onSuccess(); 116 onSuccess();
86 // Not calling fileSystemProvider.unmount(), so the onMountCompleted 117 // Not calling fileSystemProvider.unmount(), so the onMountCompleted
87 // event will not be raised. 118 // event will not be raised.
88 chrome.fileSystemProvider.onUnmountRequested.removeListener( 119 chrome.fileSystemProvider.onUnmountRequested.removeListener(
89 onUnmountRequested); 120 onUnmountRequested);
90 onTestSuccess(); 121 onTestSuccess();
91 }; 122 };
92 123
93 chrome.fileSystemProvider.onUnmountRequested.addListener( 124 chrome.fileSystemProvider.onUnmountRequested.addListener(
94 onUnmountRequested); 125 onUnmountRequested);
95 chrome.fileBrowserPrivate.removeMount(secondVolumeId); 126
127 getVolumeInfo(SECOND_FILE_SYSTEM_ID, function(volumeInfo) {
128 chrome.test.assertTrue(!!volumeInfo);
129 chrome.fileBrowserPrivate.removeMount(volumeInfo.volumeId);
130 });
96 }, 131 },
97 132
98 // End to end test with a failure. Invokes fileSystemProvider.removeMount() 133 // End to end test with a failure. Invokes fileSystemProvider.removeMount()
99 // on a provided file system, and verifies (1) if the onMountRequested() 134 // on a provided file system, and verifies (1) if the onMountRequested()
100 // event is called with correct aguments, and (2) if calling onError(), 135 // event is called with correct aguments, and (2) if calling onError(),
101 // results in an unmount event fired from the VolumeManager instance. 136 // results in an unmount event fired from the VolumeManager instance.
102 function requestUnmountError() { 137 function requestUnmountError() {
103 var onTestSuccess = chrome.test.callbackPass(function() {}); 138 var onTestSuccess = chrome.test.callbackPass();
104 var secondVolumeId =
105 'provided:' + chrome.runtime.id + '-' + secondFileSystemId + '-user';
106 var unmountRequested = false; 139 var unmountRequested = false;
107 140
108 var onUnmountRequested = function(fileSystemId, onSuccess, onError) { 141 var onUnmountRequested = function(fileSystemId, onSuccess, onError) {
109 chrome.test.assertEq(false, unmountRequested); 142 chrome.test.assertEq(false, unmountRequested);
110 chrome.test.assertEq(secondFileSystemId, fileSystemId); 143 chrome.test.assertEq(SECOND_FILE_SYSTEM_ID, fileSystemId);
111 onError('IN_USE'); // enum ProviderError. 144 onError('IN_USE'); // enum ProviderError.
112 unmountRequested = true; 145 unmountRequested = true;
113 chrome.fileSystemProvider.onUnmountRequested.removeListener( 146 chrome.fileSystemProvider.onUnmountRequested.removeListener(
114 onUnmountRequested); 147 onUnmountRequested);
115 }; 148 };
116 149
117 var onMountCompleted = function(event) { 150 var onMountCompleted = function(event) {
118 chrome.test.assertEq('unmount', event.eventType); 151 chrome.test.assertEq('unmount', event.eventType);
119 chrome.test.assertEq('error_unknown', event.status); 152 chrome.test.assertEq('error_unknown', event.status);
120 chrome.test.assertEq(secondVolumeId, event.volumeMetadata.volumeId); 153 chrome.test.assertEq(
154 chrome.runtime.id, event.volumeMetadata.extensionId);
155 chrome.test.assertEq(
156 SECOND_FILE_SYSTEM_ID, event.volumeMetadata.fileSystemId);
121 chrome.test.assertTrue(unmountRequested); 157 chrome.test.assertTrue(unmountRequested);
122 158
123 // Remove the handlers and mark the test as succeeded. 159 // Remove the handlers and mark the test as succeeded.
124 chrome.fileBrowserPrivate.removeMount(secondVolumeId); 160 chrome.fileBrowserPrivate.removeMount(SECOND_FILE_SYSTEM_ID);
125 chrome.fileBrowserPrivate.onMountCompleted.removeListener( 161 chrome.fileBrowserPrivate.onMountCompleted.removeListener(
126 onMountCompleted); 162 onMountCompleted);
127 onTestSuccess(); 163 onTestSuccess();
128 }; 164 };
129 165
130 chrome.fileSystemProvider.onUnmountRequested.addListener( 166 chrome.fileSystemProvider.onUnmountRequested.addListener(
131 onUnmountRequested); 167 onUnmountRequested);
132 chrome.fileBrowserPrivate.onMountCompleted.addListener(onMountCompleted); 168 chrome.fileBrowserPrivate.onMountCompleted.addListener(onMountCompleted);
133 chrome.fileBrowserPrivate.removeMount(secondVolumeId); 169
170 getVolumeInfo(SECOND_FILE_SYSTEM_ID, function(volumeInfo) {
171 chrome.test.assertTrue(!!volumeInfo);
172 chrome.fileBrowserPrivate.removeMount(volumeInfo.volumeId);
173 });
134 } 174 }
135 ]); 175 ]);
136 } 176 }
137 177
138 // Setup and run all of the test cases. 178 // Setup and run all of the test cases.
139 setUp(runTests); 179 setUp(runTests);
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/file_system_provider/read_file/test.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698