1 // Copyright (c) 2012 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.
5 var mediaGalleries = chrome.mediaGalleries;
6 var expectedGalleryEntryLength;
8 function TestFirstFilesystem(verifyFilesystem) {
9 function getMediaFileSystemsList() {
10 mediaGalleries.getMediaFileSystems(getMediaFileSystemsCallback);
13 function getMediaFileSystemsCallback(results) {
14 chrome.test.assertEq(1, results.length);
15 verifyFilesystem(results[0]);
18 getMediaFileSystemsList();
21 function ReadDirectoryTest() {
22 function verifyFilesystem(filesystem) {
23 verifyDirectoryEntry(filesystem.root, verify);
26 function verify(directoryEntry, entries) {
27 chrome.test.assertEq(1, entries.length);
28 chrome.test.assertFalse(entries[0].isDirectory);
29 chrome.test.assertEq("test.jpg", entries[0].name);
30 chrome.test.succeed();
33 TestFirstFilesystem(verifyFilesystem);
36 function ReadFileToBytesTest() {
37 function verifyFilesystem(filesystem) {
38 verifyJPEG(filesystem.root, "test.jpg", expectedGalleryEntryLength,
42 TestFirstFilesystem(verifyFilesystem);
45 function GetMetadataTest() {
46 function verifyFilesystem(filesystem) {
47 filesystem.root.getFile("test.jpg", {create: false}, verifyFileEntry,
51 function verifyFileEntry(fileEntry) {
52 fileEntry.file(verifyFile, chrome.test.fail)
55 function verifyFile(file) {
56 mediaGalleries.getMetadata(file, {}, verifyMetadata);
59 function verifyMetadata(metadata) {
60 chrome.test.assertEq("image/jpeg", metadata.mimeType);
61 chrome.test.succeed();
64 TestFirstFilesystem(verifyFilesystem);
67 function GetMediaFileSystemMetadataTest() {
68 function verifyFilesystem(filesystem) {
69 var metadata = mediaGalleries.getMediaFileSystemMetadata(filesystem);
70 checkMetadata(metadata);
71 chrome.test.succeed();
74 TestFirstFilesystem(verifyFilesystem);
77 function GetAllMediaFileSystemMetadataTest() {
78 function verifyMetadataList(metadataList) {
79 chrome.test.assertEq(1, metadataList.length)
80 checkMetadata(metadataList[0]);
81 chrome.test.succeed();
84 mediaGalleries.getAllMediaFileSystemMetadata(verifyMetadataList);
87 function DropPermissionForMediaFileSystemTest() {
88 var droppedFilesystem;
91 function callDropPermission(filesystem) {
92 var metadata = mediaGalleries.getMediaFileSystemMetadata(filesystem);
93 droppedFilesystem = filesystem;
94 droppedGalleryId = metadata.galleryId;
95 mediaGalleries.dropPermissionForMediaFileSystem(
97 chrome.test.callbackPass(onDropPermissionSucceeded));
100 function onDropPermissionSucceeded() {
101 var metadata = mediaGalleries.getMediaFileSystemMetadata(droppedFilesystem);
102 var notFoundMetadata = {
105 "isRemovable": false,
106 "isMediaDevice": false,
107 "isAvailable": false,
109 chrome.test.assertEq(notFoundMetadata, metadata);
110 mediaGalleries.getMediaFileSystems(verifyNoFileSystemAccess);
113 function verifyNoFileSystemAccess(results) {
114 chrome.test.assertEq(0, results.length);
115 mediaGalleries.dropPermissionForMediaFileSystem(
117 chrome.test.callbackFail("Failed to set gallery permission.",
118 onDropPermissionFailed));
121 function onDropPermissionFailed() {
122 mediaGalleries.dropPermissionForMediaFileSystem(
124 chrome.test.callbackFail("Invalid gallery id.",
125 onDropPermissionFailedForInvalidGallery));
128 function onDropPermissionFailedForInvalidGallery() {
129 mediaGalleries.dropPermissionForMediaFileSystem(
131 chrome.test.callbackFail("Non-existent gallery id.",
132 chrome.test.succeed));
135 TestFirstFilesystem(callDropPermission);
138 CreateDummyWindowToPreventSleep();
140 chrome.test.getConfig(function(config) {
141 customArg = JSON.parse(config.customArg);
142 expectedGalleryEntryLength = customArg[0];
144 chrome.test.runTests([
148 GetMediaFileSystemMetadataTest,
149 GetAllMediaFileSystemMetadataTest,
150 DropPermissionForMediaFileSystemTest,