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

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

Issue 194693002: [fsp] Add requestUnmount() method together with the request manager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed some too strict thread checks. Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
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..d09dcdb23a6ac8231f9d7aa98f094819a085650f
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system_provider/unmount/test.js
@@ -0,0 +1,123 @@
+// 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([
+ // Tests the fileSystemProvider.unmount(). Verifies if the unmount event
+ // is emitted by VolumeManager.
+ function unmount() {
+ 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();
+ });
+ },
+
+ // Tests the fileSystemProvider.unmount() with a wrong id. Verifies that
+ // it fails with a correct error code.
+ function unmountWrongId() {
+ chrome.fileSystemProvider.unmount(1337, function() {
+ chrome.test.fail();
+ }, function(error) {
+ chrome.test.assertEq('SecurityError', error.name);
+ chrome.test.succeed();
+ });
+ },
+
+ // Tests if fileBrowserPrivate.removeMount() for provided file systems emits
+ // the onMountRequested() event with correct arguments.
+ 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);
+ },
+
+ // End to end test with a failure. Invokes fileSystemProvider.removeMount()
+ // on a provided file system, and verifies (1) if the onMountRequested()
+ // event is called with correct aguments, and (2) if calling onError(),
+ // results in an unmount event fired from the VolumeManager instance.
+ 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);

Powered by Google App Engine
This is Rietveld 408576698