OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 var firstFileSystemId; |
| 6 var secondFileSystemId; |
| 7 |
| 8 function setUp(callback) { |
| 9 chrome.fileSystemProvider.mount('chocolate.zip', function(id) { |
| 10 firstFileSystemId = id; |
| 11 if (firstFileSystemId && secondFileSystemId) |
| 12 callback(); |
| 13 }, function() { |
| 14 chrome.test.fail(); |
| 15 }); |
| 16 |
| 17 chrome.fileSystemProvider.mount('banana.zip', function(id) { |
| 18 secondFileSystemId = id; |
| 19 if (firstFileSystemId && secondFileSystemId) |
| 20 callback(); |
| 21 }, function() { |
| 22 chrome.test.fail(); |
| 23 }); |
| 24 } |
| 25 |
| 26 function runTests() { |
| 27 chrome.test.runTests([ |
| 28 // Tests the fileSystemProvider.unmount(). Verifies if the unmount event |
| 29 // is emitted by VolumeManager. |
| 30 function unmount() { |
| 31 var firstVolumeId = |
| 32 'provided:' + chrome.runtime.id + '-' + firstFileSystemId + '-user'; |
| 33 |
| 34 var onMountCompleted = function(event) { |
| 35 chrome.test.assertEq('unmount', event.eventType); |
| 36 chrome.test.assertEq('success', event.status); |
| 37 chrome.test.assertEq(firstVolumeId, event.volumeMetadata.volumeId); |
| 38 chrome.fileBrowserPrivate.onMountCompleted.removeListener( |
| 39 onMountCompleted); |
| 40 chrome.test.succeed(); |
| 41 }; |
| 42 |
| 43 chrome.fileBrowserPrivate.onMountCompleted.addListener( |
| 44 onMountCompleted); |
| 45 chrome.fileSystemProvider.unmount(firstFileSystemId, function() { |
| 46 // Wait for the unmount event. |
| 47 }, function(error) { |
| 48 chrome.test.fail(); |
| 49 }); |
| 50 }, |
| 51 |
| 52 // Tests the fileSystemProvider.unmount() with a wrong id. Verifies that |
| 53 // it fails with a correct error code. |
| 54 function unmountWrongId() { |
| 55 chrome.fileSystemProvider.unmount(1337, function() { |
| 56 chrome.test.fail(); |
| 57 }, function(error) { |
| 58 chrome.test.assertEq('SecurityError', error.name); |
| 59 chrome.test.succeed(); |
| 60 }); |
| 61 }, |
| 62 |
| 63 // Tests if fileBrowserPrivate.removeMount() for provided file systems emits |
| 64 // the onMountRequested() event with correct arguments. |
| 65 function requestUnmountSuccess() { |
| 66 var secondVolumeId = |
| 67 'provided:' + chrome.runtime.id + '-' + secondFileSystemId + '-user'; |
| 68 |
| 69 var onUnmountRequested = function(fileSystemId, onSuccess, onError) { |
| 70 chrome.test.assertEq(secondFileSystemId, fileSystemId); |
| 71 onSuccess(); |
| 72 // Not calling fileSystemProvider.unmount(), so the onMountCompleted |
| 73 // event will not be raised. |
| 74 chrome.fileSystemProvider.onUnmountRequested.removeListener( |
| 75 onUnmountRequested); |
| 76 chrome.test.succeed(); |
| 77 }; |
| 78 |
| 79 chrome.fileSystemProvider.onUnmountRequested.addListener( |
| 80 onUnmountRequested); |
| 81 chrome.fileBrowserPrivate.removeMount(secondVolumeId); |
| 82 }, |
| 83 |
| 84 // End to end test with a failure. Invokes fileSystemProvider.removeMount() |
| 85 // on a provided file system, and verifies (1) if the onMountRequested() |
| 86 // event is called with correct aguments, and (2) if calling onError(), |
| 87 // results in an unmount event fired from the VolumeManager instance. |
| 88 function requestUnmountError() { |
| 89 var secondVolumeId = |
| 90 'provided:' + chrome.runtime.id + '-' + secondFileSystemId + '-user'; |
| 91 var unmountRequested = false; |
| 92 |
| 93 var onUnmountRequested = function(fileSystemId, onSuccess, onError) { |
| 94 chrome.test.assertEq(false, unmountRequested); |
| 95 chrome.test.assertEq(secondFileSystemId, fileSystemId); |
| 96 onError('IN_USE'); // enum ProviderError. |
| 97 unmountRequested = true; |
| 98 chrome.fileSystemProvider.onUnmountRequested.removeListener( |
| 99 onUnmountRequested); |
| 100 }; |
| 101 |
| 102 var onMountCompleted = function(event) { |
| 103 chrome.test.assertEq('unmount', event.eventType); |
| 104 chrome.test.assertEq('error_unknown', event.status); |
| 105 chrome.test.assertEq(secondVolumeId, event.volumeMetadata.volumeId); |
| 106 chrome.test.assertTrue(unmountRequested); |
| 107 |
| 108 // Remove the handlers and mark the test as succeeded. |
| 109 chrome.fileBrowserPrivate.removeMount(secondVolumeId); |
| 110 chrome.fileBrowserPrivate.onMountCompleted.removeListener( |
| 111 onMountCompleted); |
| 112 chrome.test.succeed(); |
| 113 }; |
| 114 |
| 115 chrome.fileSystemProvider.onUnmountRequested.addListener( |
| 116 onUnmountRequested); |
| 117 chrome.fileBrowserPrivate.onMountCompleted.addListener(onMountCompleted); |
| 118 chrome.fileBrowserPrivate.removeMount(secondVolumeId); |
| 119 } |
| 120 ]); |
| 121 }; |
| 122 |
| 123 setUp(runTests); |
OLD | NEW |