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

Unified Diff: chrome/test/data/extensions/api_test/file_browser/content_checksum_test/test.js

Issue 840843002: Expose computation of md5 content checksums for files via a file manager private API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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_browser/content_checksum_test/test.js
diff --git a/chrome/test/data/extensions/api_test/file_browser/content_checksum_test/test.js b/chrome/test/data/extensions/api_test/file_browser/content_checksum_test/test.js
new file mode 100644
index 0000000000000000000000000000000000000000..35e08f5221923aaea4a8c14da5c2a2a1e59a7dfc
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_browser/content_checksum_test/test.js
@@ -0,0 +1,75 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
mtomasz 2015/01/08 00:38:40 (c) 2013 -> 2014
Ben Kwa 2015/01/08 19:29:14 2015!
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * The test file system should be created and populated before running the test
+ * extension.
+ *
+ * The only file used right now is <root>/test_dir/test_file.txt.
+ */
+
+// This is a golden value computed using the md5sum command line tool.
+var kExpectedHash = 'a3dfffb5a580272fb8986611a9dbd166';
+
+function initTests(callback) {
mtomasz 2015/01/08 00:38:40 I think this can be greatly simplified. If we only
Ben Kwa 2015/01/08 19:29:14 Ah, ok. Thanks for clarifying - I wasn't sure wha
+ chrome.fileManagerPrivate.getVolumeMetadataList(function(volumeMetadataList) {
+ var possibleVolumeTypes = ['testing', 'drive'];
+
+ var sortedVolumeMetadataList = volumeMetadataList.filter(function(volume) {
+ return possibleVolumeTypes.indexOf(volume.volumeType) != -1;
+ }).sort(function(volumeA, volumeB) {
+ return possibleVolumeTypes.indexOf(volumeA.volumeType) >
+ possibleVolumeTypes.indexOf(volumeB.volumeType);
+ });
+
+ if (sortedVolumeMetadataList.length == 0) {
+ callback(null, 'No volumes available, which could be used for testing.');
+ return;
+ }
+
+ chrome.fileManagerPrivate.requestFileSystem(
+ sortedVolumeMetadataList[0].volumeId,
+ function(fileSystem) {
+ if (!fileSystem) {
+ callback(null, 'Failed to acquire the testing volume.');
+ return;
+ }
+
+ var testsToRun = collectTestsForVolumeId(
+ sortedVolumeMetadataList[0].volumeId, fileSystem);
+ callback(testsToRun, 'Success.');
+ });
+ });
+}
+
+function collectTestsForVolumeId(volumeId, fileSystem) {
+ console.log(volumeId);
+ var testsToRun = [];
+
+ testsToRun.push(function quickTest() {
+ fileSystem.root.getFile(
+ 'test_dir/test_file.txt',
+ {create: false},
+ function(entry) {
+ chrome.fileManagerPrivate.computeChecksum(
+ entry.toURL(),
+ chrome.test.callbackPass(function(result) {
+ chrome.test.assertEq(kExpectedHash, result);
+ }));
+ },
+ chrome.test.fail);
+ });
+
+ return testsToRun;
+}
+
+// Trigger the tests.
+initTests(function(testsToRun, errorMessage) {
+ if (!testsToRun) {
+ chrome.test.notifyFail('Failed to initialize tests: ' + errorMessage);
+ return;
+ }
+
+ chrome.test.runTests(testsToRun);
+});

Powered by Google App Engine
This is Rietveld 408576698