| OLD | NEW |
| 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 /** | 7 /** |
| 8 * @type {string} | 8 * @type {string} |
| 9 * @const | 9 * @const |
| 10 */ | 10 */ |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 /** | 39 /** |
| 40 * 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, |
| 41 * the callback is not called. | 41 * the callback is not called. |
| 42 * | 42 * |
| 43 * @param {function()} callback Success callback. | 43 * @param {function()} callback Success callback. |
| 44 */ | 44 */ |
| 45 function setUp(callback) { | 45 function setUp(callback) { |
| 46 Promise.race([ | 46 Promise.race([ |
| 47 new Promise(function(fulfill, reject) { | 47 new Promise(function(fulfill, reject) { |
| 48 chrome.fileSystemProvider.mount( | 48 chrome.fileSystemProvider.mount( |
| 49 FIRST_FILE_SYSTEM_ID, | 49 {fileSystemId: FIRST_FILE_SYSTEM_ID, displayName: 'vanilla.zip'}, |
| 50 'vanilla.zip', | |
| 51 function() { fulfill(); }, | 50 function() { fulfill(); }, |
| 52 function(error) { reject(error); }); | 51 function(error) { reject(error); }); |
| 53 }), | 52 }), |
| 54 new Promise(function(fulfill, reject) { | 53 new Promise(function(fulfill, reject) { |
| 55 chrome.fileSystemProvider.mount( | 54 chrome.fileSystemProvider.mount( |
| 56 SECOND_FILE_SYSTEM_ID, | 55 {fileSystemId: SECOND_FILE_SYSTEM_ID, displayName: 'ice-cream.zip'}, |
| 57 'ice-cream.zip', | |
| 58 function() { fulfill(); }, | 56 function() { fulfill(); }, |
| 59 function(error) { reject(error); }); | 57 function(error) { reject(error); }); |
| 60 }) | 58 }) |
| 61 ]).then(callback).catch(function(error) { | 59 ]).then(callback).catch(function(error) { |
| 62 chrome.test.fail(error.name); | 60 chrome.test.fail(error.name); |
| 63 }); | 61 }); |
| 64 } | 62 } |
| 65 | 63 |
| 66 /** | 64 /** |
| 67 * Runs all of the test cases, one by one. | 65 * Runs all of the test cases, one by one. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 80 chrome.runtime.id, event.volumeMetadata.extensionId); | 78 chrome.runtime.id, event.volumeMetadata.extensionId); |
| 81 chrome.test.assertEq( | 79 chrome.test.assertEq( |
| 82 FIRST_FILE_SYSTEM_ID, event.volumeMetadata.fileSystemId); | 80 FIRST_FILE_SYSTEM_ID, event.volumeMetadata.fileSystemId); |
| 83 chrome.fileBrowserPrivate.onMountCompleted.removeListener( | 81 chrome.fileBrowserPrivate.onMountCompleted.removeListener( |
| 84 onMountCompleted); | 82 onMountCompleted); |
| 85 onTestSuccess(); | 83 onTestSuccess(); |
| 86 }; | 84 }; |
| 87 | 85 |
| 88 chrome.fileBrowserPrivate.onMountCompleted.addListener( | 86 chrome.fileBrowserPrivate.onMountCompleted.addListener( |
| 89 onMountCompleted); | 87 onMountCompleted); |
| 90 chrome.fileSystemProvider.unmount(FIRST_FILE_SYSTEM_ID, function() { | 88 chrome.fileSystemProvider.unmount( |
| 91 // Wait for the unmount event. | 89 {fileSystemId: FIRST_FILE_SYSTEM_ID}, |
| 92 }, function(error) { | 90 function() { |
| 93 chrome.test.fail(error.name); | 91 // Wait for the unmount event. |
| 94 }); | 92 }, |
| 93 function(error) { |
| 94 chrome.test.fail(error.name); |
| 95 }); |
| 95 }, | 96 }, |
| 96 | 97 |
| 97 // Tests the fileSystemProvider.unmount() with a wrong id. Verifies that | 98 // Tests the fileSystemProvider.unmount() with a wrong id. Verifies that |
| 98 // it fails with a correct error code. | 99 // it fails with a correct error code. |
| 99 function unmountWrongId() { | 100 function unmountWrongId() { |
| 100 var onTestSuccess = chrome.test.callbackPass(); | 101 var onTestSuccess = chrome.test.callbackPass(); |
| 101 chrome.fileSystemProvider.unmount('wrong-fs-id', function() { | 102 chrome.fileSystemProvider.unmount( |
| 102 chrome.test.fail(); | 103 {fileSystemId: 'wrong-fs-id'}, |
| 103 }, function(error) { | 104 function() { |
| 104 chrome.test.assertEq('SecurityError', error.name); | 105 chrome.test.fail(); |
| 105 onTestSuccess(); | 106 }, |
| 106 }); | 107 function(error) { |
| 108 chrome.test.assertEq('SecurityError', error.name); |
| 109 onTestSuccess(); |
| 110 }); |
| 107 }, | 111 }, |
| 108 | 112 |
| 109 // Tests if fileBrowserPrivate.removeMount() for provided file systems emits | 113 // Tests if fileBrowserPrivate.removeMount() for provided file systems emits |
| 110 // the onMountRequested() event with correct arguments. | 114 // the onMountRequested() event with correct arguments. |
| 111 function requestUnmountSuccess() { | 115 function requestUnmountSuccess() { |
| 112 var onTestSuccess = chrome.test.callbackPass(); | 116 var onTestSuccess = chrome.test.callbackPass(); |
| 113 | 117 |
| 114 var onUnmountRequested = function(fileSystemId, onSuccess, onError) { | 118 var onUnmountRequested = function(options, onSuccess, onError) { |
| 115 chrome.test.assertEq(SECOND_FILE_SYSTEM_ID, fileSystemId); | 119 chrome.test.assertEq(SECOND_FILE_SYSTEM_ID, options.fileSystemId); |
| 116 onSuccess(); | 120 onSuccess(); |
| 117 // Not calling fileSystemProvider.unmount(), so the onMountCompleted | 121 // Not calling fileSystemProvider.unmount(), so the onMountCompleted |
| 118 // event will not be raised. | 122 // event will not be raised. |
| 119 chrome.fileSystemProvider.onUnmountRequested.removeListener( | 123 chrome.fileSystemProvider.onUnmountRequested.removeListener( |
| 120 onUnmountRequested); | 124 onUnmountRequested); |
| 121 onTestSuccess(); | 125 onTestSuccess(); |
| 122 }; | 126 }; |
| 123 | 127 |
| 124 chrome.fileSystemProvider.onUnmountRequested.addListener( | 128 chrome.fileSystemProvider.onUnmountRequested.addListener( |
| 125 onUnmountRequested); | 129 onUnmountRequested); |
| 126 | 130 |
| 127 getVolumeInfo(SECOND_FILE_SYSTEM_ID, function(volumeInfo) { | 131 getVolumeInfo(SECOND_FILE_SYSTEM_ID, function(volumeInfo) { |
| 128 chrome.test.assertTrue(!!volumeInfo); | 132 chrome.test.assertTrue(!!volumeInfo); |
| 129 chrome.fileBrowserPrivate.removeMount(volumeInfo.volumeId); | 133 chrome.fileBrowserPrivate.removeMount(volumeInfo.volumeId); |
| 130 }); | 134 }); |
| 131 }, | 135 }, |
| 132 | 136 |
| 133 // End to end test with a failure. Invokes fileSystemProvider.removeMount() | 137 // End to end test with a failure. Invokes fileSystemProvider.removeMount() |
| 134 // on a provided file system, and verifies (1) if the onMountRequested() | 138 // on a provided file system, and verifies (1) if the onMountRequested() |
| 135 // event is called with correct aguments, and (2) if calling onError(), | 139 // event is called with correct aguments, and (2) if calling onError(), |
| 136 // results in an unmount event fired from the VolumeManager instance. | 140 // results in an unmount event fired from the VolumeManager instance. |
| 137 function requestUnmountError() { | 141 function requestUnmountError() { |
| 138 var onTestSuccess = chrome.test.callbackPass(); | 142 var onTestSuccess = chrome.test.callbackPass(); |
| 139 var unmountRequested = false; | 143 var unmountRequested = false; |
| 140 | 144 |
| 141 var onUnmountRequested = function(fileSystemId, onSuccess, onError) { | 145 var onUnmountRequested = function(options, onSuccess, onError) { |
| 142 chrome.test.assertEq(false, unmountRequested); | 146 chrome.test.assertEq(false, unmountRequested); |
| 143 chrome.test.assertEq(SECOND_FILE_SYSTEM_ID, fileSystemId); | 147 chrome.test.assertEq(SECOND_FILE_SYSTEM_ID, options.fileSystemId); |
| 144 onError('IN_USE'); // enum ProviderError. | 148 onError('IN_USE'); // enum ProviderError. |
| 145 unmountRequested = true; | 149 unmountRequested = true; |
| 146 chrome.fileSystemProvider.onUnmountRequested.removeListener( | 150 chrome.fileSystemProvider.onUnmountRequested.removeListener( |
| 147 onUnmountRequested); | 151 onUnmountRequested); |
| 148 }; | 152 }; |
| 149 | 153 |
| 150 var onMountCompleted = function(event) { | 154 var onMountCompleted = function(event) { |
| 151 chrome.test.assertEq('unmount', event.eventType); | 155 chrome.test.assertEq('unmount', event.eventType); |
| 152 chrome.test.assertEq('error_unknown', event.status); | 156 chrome.test.assertEq('error_unknown', event.status); |
| 153 chrome.test.assertEq( | 157 chrome.test.assertEq( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 170 getVolumeInfo(SECOND_FILE_SYSTEM_ID, function(volumeInfo) { | 174 getVolumeInfo(SECOND_FILE_SYSTEM_ID, function(volumeInfo) { |
| 171 chrome.test.assertTrue(!!volumeInfo); | 175 chrome.test.assertTrue(!!volumeInfo); |
| 172 chrome.fileBrowserPrivate.removeMount(volumeInfo.volumeId); | 176 chrome.fileBrowserPrivate.removeMount(volumeInfo.volumeId); |
| 173 }); | 177 }); |
| 174 } | 178 } |
| 175 ]); | 179 ]); |
| 176 } | 180 } |
| 177 | 181 |
| 178 // Setup and run all of the test cases. | 182 // Setup and run all of the test cases. |
| 179 setUp(runTests); | 183 setUp(runTests); |
| OLD | NEW |