Index: chrome/test/data/extensions/api_test/file_system_provider/get_metadata/test.js |
diff --git a/chrome/test/data/extensions/api_test/file_system_provider/get_metadata/test.js b/chrome/test/data/extensions/api_test/file_system_provider/get_metadata/test.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9bca3f96105b928eff67261fe66ec4cb9ae59cef |
--- /dev/null |
+++ b/chrome/test/data/extensions/api_test/file_system_provider/get_metadata/test.js |
@@ -0,0 +1,136 @@ |
+// 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. |
+ |
hirono
2014/04/30 06:57:38
'use strict';
|
+var fileSystemId; |
+var fileSystem; |
+ |
+var TESTING_ROOT = { |
hirono
2014/04/30 06:57:38
nit: Object.freeze
mtomasz
2014/04/30 09:18:24
Done.
|
+ isDirectory: true, |
+ name: '', |
+ size: 0, |
+ modificationTime: new Date(2013, 3, 27, 9, 38, 14) |
+}; |
+ |
+var TESTING_FILE = { |
hirono
2014/04/30 06:57:38
ditto.
mtomasz
2014/04/30 09:18:24
Done.
|
+ isDirectory: false, |
+ name: 'tiramisu.txt', |
+ size: 4096, |
+ modificationTime: new Date(2014, 4, 28, 10, 39, 15) |
+}; |
+ |
+function onGetMetadataRequested( |
hirono
2014/04/30 06:57:38
nit: JSDoc
mtomasz
2014/04/30 09:18:24
Done.
|
+ inFileSystemId, entryPath, onSuccess, onError) { |
+ if (inFileSystemId != fileSystemId) { |
+ onError('SECURITY_ERROR'); // enum ProviderError. |
+ return; |
+ } |
+ |
+ if (entryPath == '/') { |
+ onSuccess(TESTING_ROOT); |
+ return; |
+ } |
+ |
+ if (entryPath == '/' + TESTING_FILE.name) { |
+ onSuccess(TESTING_FILE); |
+ return; |
+ } |
+ |
+ onError('NOT_FOUND'); // enum ProviderError. |
+} |
+ |
+function setUp(callback) { |
+ chrome.fileSystemProvider.mount('chocolate.zip', function(id) { |
+ fileSystemId = id; |
+ chrome.fileSystemProvider.onGetMetadataRequested.addListener( |
+ onGetMetadataRequested); |
hirono
2014/04/30 06:57:38
nit: 4 indent.
mtomasz
2014/04/30 09:18:24
Done.
|
+ var volumeId = |
+ 'provided:' + chrome.runtime.id + '-' + fileSystemId + '-user'; |
+ |
+ chrome.fileBrowserPrivate.requestFileSystem( |
+ volumeId, |
+ function(inFileSystem) { |
+ chrome.test.assertTrue(!!inFileSystem); |
+ |
+ fileSystem = inFileSystem; |
+ callback(); |
+ }); |
+ }, function() { |
+ chrome.test.fail(); |
+ }); |
+} |
+ |
+function runTests() { |
+ chrome.test.runTests([ |
+ // Read metadata of the root. |
+ function getFileMetadataSuccess() { |
+ var onSuccess = chrome.test.callbackPass(function() {}); |
+ fileSystem.root.getMetadata( |
+ function(metadata) { |
+ chrome.test.assertEq(TESTING_ROOT.size, metadata.size); |
+ chrome.test.assertEq( |
+ TESTING_ROOT.modificationTime.toString(), |
+ metadata.modificationTime.toString()); |
+ onSuccess(); |
+ }, function(error) { |
+ chrome.test.fail(error.name); |
+ }); |
+ }, |
+ // Read metadata of an existing testing file. |
+ function getFileMetadataSuccess() { |
+ var onSuccess = chrome.test.callbackPass(function() {}); |
+ fileSystem.root.getFile( |
+ TESTING_FILE.name, |
+ {create: false}, |
+ function(fileEntry) { |
+ chrome.test.assertEq(TESTING_FILE.name, fileEntry.name); |
+ chrome.test.assertEq( |
+ TESTING_FILE.isDirectory, fileEntry.isDirectory); |
+ fileEntry.getMetadata(function(metadata) { |
+ chrome.test.assertEq(TESTING_FILE.size, metadata.size); |
+ chrome.test.assertEq( |
+ TESTING_FILE.modificationTime.toString(), |
+ metadata.modificationTime.toString()); |
+ onSuccess(); |
+ }, function(error) { |
+ chrome.test.fail(error.name); |
+ }); |
+ }, |
+ function(error) { |
+ chrome.test.fail(error.name); |
+ }); |
+ }, |
+ // Read metadata of a directory which does not exist, what should return an |
+ // error. |
hirono
2014/04/30 06:57:38
Please add a comment that the getDirectory calls g
mtomasz
2014/04/30 09:18:24
Done.
|
+ function getFileMetadataNotFound() { |
+ var onSuccess = chrome.test.callbackPass(function() {}); |
+ fileSystem.root.getDirectory( |
+ 'cranberries', |
+ {create: false}, |
+ function(dirEntry) { |
+ chrome.test.fail(); |
+ }, |
+ function(error) { |
+ chrome.test.assertEq('NotFoundError', error.name); |
+ onSuccess(); |
+ }); |
+ }, |
+ // Read metadata of a file using getDirectory(). An error should be returned |
+ // because of type mismatching. |
hirono
2014/04/30 06:57:38
ditto.
mtomasz
2014/04/30 09:18:24
Done.
|
+ function getFileMetadataWrongType() { |
+ var onSuccess = chrome.test.callbackPass(function() {}); |
+ fileSystem.root.getDirectory( |
+ TESTING_FILE.name, |
+ {create: false}, |
+ function(fileEntry) { |
+ chrome.test.fail(); |
+ }, |
+ function(error) { |
+ chrome.test.assertEq('TypeMismatchError', error.name); |
+ onSuccess(); |
+ }); |
+ } |
+ ]); |
+} |
+ |
+setUp(runTests); |