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 function unmount() { | |
satorux1
2014/03/26 08:15:03
This is testing the most common case, right? Could
mtomasz
2014/03/26 10:27:42
I added comments for each test case. Done.
| |
29 var firstVolumeId = | |
30 'provided:' + chrome.runtime.id + '-' + firstFileSystemId + '-user'; | |
31 | |
32 var onMountCompleted = function(event) { | |
33 chrome.test.assertEq('unmount', event.eventType); | |
34 chrome.test.assertEq('success', event.status); | |
35 chrome.test.assertEq(firstVolumeId, event.volumeMetadata.volumeId); | |
36 chrome.fileBrowserPrivate.onMountCompleted.removeListener( | |
37 onMountCompleted); | |
38 chrome.test.succeed(); | |
39 }; | |
40 | |
41 chrome.fileBrowserPrivate.onMountCompleted.addListener( | |
42 onMountCompleted); | |
43 chrome.fileSystemProvider.unmount(firstFileSystemId, function() { | |
44 // Wait for the unmount event. | |
45 }, function(error) { | |
46 chrome.test.fail(); | |
47 }); | |
48 }, | |
49 | |
50 function unmountWrongId() { | |
51 chrome.fileSystemProvider.unmount(1337, function() { | |
52 chrome.test.fail(); | |
53 }, function(error) { | |
54 chrome.test.assertEq('SecurityError', error.name); | |
55 chrome.test.succeed(); | |
56 }); | |
57 }, | |
58 | |
59 function requestUnmountSuccess() { | |
60 var secondVolumeId = | |
61 'provided:' + chrome.runtime.id + '-' + secondFileSystemId + '-user'; | |
62 | |
63 var onUnmountRequested = function(fileSystemId, onSuccess, onError) { | |
64 chrome.test.assertEq(secondFileSystemId, fileSystemId); | |
65 onSuccess(); | |
66 // Not calling fileSystemProvider.unmount(), so the onMountCompleted | |
67 // event will not be raised. | |
68 chrome.fileSystemProvider.onUnmountRequested.removeListener( | |
69 onUnmountRequested); | |
70 chrome.test.succeed(); | |
71 }; | |
72 | |
73 chrome.fileSystemProvider.onUnmountRequested.addListener( | |
74 onUnmountRequested); | |
75 chrome.fileBrowserPrivate.removeMount(secondVolumeId); | |
satorux1
2014/03/26 08:15:03
In this test, unmounting is initiated by fileBrows
mtomasz
2014/03/26 10:27:42
Exactly. The previous one tests fileSystemProvider
| |
76 }, | |
77 | |
78 function requestUnmountError() { | |
79 var secondVolumeId = | |
80 'provided:' + chrome.runtime.id + '-' + secondFileSystemId + '-user'; | |
81 var unmountRequested = false; | |
82 | |
83 var onUnmountRequested = function(fileSystemId, onSuccess, onError) { | |
84 chrome.test.assertEq(false, unmountRequested); | |
85 chrome.test.assertEq(secondFileSystemId, fileSystemId); | |
86 onError('IN_USE'); // enum ProviderError. | |
87 unmountRequested = true; | |
88 chrome.fileSystemProvider.onUnmountRequested.removeListener( | |
89 onUnmountRequested); | |
90 }; | |
91 | |
92 var onMountCompleted = function(event) { | |
93 chrome.test.assertEq('unmount', event.eventType); | |
94 chrome.test.assertEq('error_unknown', event.status); | |
95 chrome.test.assertEq(secondVolumeId, event.volumeMetadata.volumeId); | |
96 chrome.test.assertTrue(unmountRequested); | |
97 | |
98 // Remove the handlers and mark the test as succeeded. | |
99 chrome.fileBrowserPrivate.removeMount(secondVolumeId); | |
100 chrome.fileBrowserPrivate.onMountCompleted.removeListener( | |
101 onMountCompleted); | |
102 chrome.test.succeed(); | |
103 }; | |
104 | |
105 chrome.fileSystemProvider.onUnmountRequested.addListener( | |
106 onUnmountRequested); | |
107 chrome.fileBrowserPrivate.onMountCompleted.addListener(onMountCompleted); | |
108 chrome.fileBrowserPrivate.removeMount(secondVolumeId); | |
109 } | |
110 ]); | |
111 }; | |
112 | |
113 setUp(runTests); | |
OLD | NEW |