Chromium Code Reviews| Index: chrome/test/data/extensions/api_test/file_system_provider/unmount/test.js |
| diff --git a/chrome/test/data/extensions/api_test/file_system_provider/unmount/test.js b/chrome/test/data/extensions/api_test/file_system_provider/unmount/test.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bb808b0ae0b9f32956a9fc2bcffd1cbc1f08c2cf |
| --- /dev/null |
| +++ b/chrome/test/data/extensions/api_test/file_system_provider/unmount/test.js |
| @@ -0,0 +1,113 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +var firstFileSystemId; |
| +var secondFileSystemId; |
| + |
| +function setUp(callback) { |
| + chrome.fileSystemProvider.mount('chocolate.zip', function(id) { |
| + firstFileSystemId = id; |
| + if (firstFileSystemId && secondFileSystemId) |
| + callback(); |
| + }, function() { |
| + chrome.test.fail(); |
| + }); |
| + |
| + chrome.fileSystemProvider.mount('banana.zip', function(id) { |
| + secondFileSystemId = id; |
| + if (firstFileSystemId && secondFileSystemId) |
| + callback(); |
| + }, function() { |
| + chrome.test.fail(); |
| + }); |
| +} |
| + |
| +function runTests() { |
| + chrome.test.runTests([ |
| + 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.
|
| + var firstVolumeId = |
| + 'provided:' + chrome.runtime.id + '-' + firstFileSystemId + '-user'; |
| + |
| + var onMountCompleted = function(event) { |
| + chrome.test.assertEq('unmount', event.eventType); |
| + chrome.test.assertEq('success', event.status); |
| + chrome.test.assertEq(firstVolumeId, event.volumeMetadata.volumeId); |
| + chrome.fileBrowserPrivate.onMountCompleted.removeListener( |
| + onMountCompleted); |
| + chrome.test.succeed(); |
| + }; |
| + |
| + chrome.fileBrowserPrivate.onMountCompleted.addListener( |
| + onMountCompleted); |
| + chrome.fileSystemProvider.unmount(firstFileSystemId, function() { |
| + // Wait for the unmount event. |
| + }, function(error) { |
| + chrome.test.fail(); |
| + }); |
| + }, |
| + |
| + function unmountWrongId() { |
| + chrome.fileSystemProvider.unmount(1337, function() { |
| + chrome.test.fail(); |
| + }, function(error) { |
| + chrome.test.assertEq('SecurityError', error.name); |
| + chrome.test.succeed(); |
| + }); |
| + }, |
| + |
| + function requestUnmountSuccess() { |
| + var secondVolumeId = |
| + 'provided:' + chrome.runtime.id + '-' + secondFileSystemId + '-user'; |
| + |
| + var onUnmountRequested = function(fileSystemId, onSuccess, onError) { |
| + chrome.test.assertEq(secondFileSystemId, fileSystemId); |
| + onSuccess(); |
| + // Not calling fileSystemProvider.unmount(), so the onMountCompleted |
| + // event will not be raised. |
| + chrome.fileSystemProvider.onUnmountRequested.removeListener( |
| + onUnmountRequested); |
| + chrome.test.succeed(); |
| + }; |
| + |
| + chrome.fileSystemProvider.onUnmountRequested.addListener( |
| + onUnmountRequested); |
| + 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
|
| + }, |
| + |
| + function requestUnmountError() { |
| + var secondVolumeId = |
| + 'provided:' + chrome.runtime.id + '-' + secondFileSystemId + '-user'; |
| + var unmountRequested = false; |
| + |
| + var onUnmountRequested = function(fileSystemId, onSuccess, onError) { |
| + chrome.test.assertEq(false, unmountRequested); |
| + chrome.test.assertEq(secondFileSystemId, fileSystemId); |
| + onError('IN_USE'); // enum ProviderError. |
| + unmountRequested = true; |
| + chrome.fileSystemProvider.onUnmountRequested.removeListener( |
| + onUnmountRequested); |
| + }; |
| + |
| + var onMountCompleted = function(event) { |
| + chrome.test.assertEq('unmount', event.eventType); |
| + chrome.test.assertEq('error_unknown', event.status); |
| + chrome.test.assertEq(secondVolumeId, event.volumeMetadata.volumeId); |
| + chrome.test.assertTrue(unmountRequested); |
| + |
| + // Remove the handlers and mark the test as succeeded. |
| + chrome.fileBrowserPrivate.removeMount(secondVolumeId); |
| + chrome.fileBrowserPrivate.onMountCompleted.removeListener( |
| + onMountCompleted); |
| + chrome.test.succeed(); |
| + }; |
| + |
| + chrome.fileSystemProvider.onUnmountRequested.addListener( |
| + onUnmountRequested); |
| + chrome.fileBrowserPrivate.onMountCompleted.addListener(onMountCompleted); |
| + chrome.fileBrowserPrivate.removeMount(secondVolumeId); |
| + } |
| + ]); |
| +}; |
| + |
| +setUp(runTests); |