Elim cr-checkbox
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / media_galleries / delete_access / test.js
blob8fd4f5dcd365614d8da035867fc6573362620acc
1 // Copyright 2013 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;
7 var galleries;
8 var testResults = [];
9 var foundGalleryWithEntry = false;
10 var expectedFileSystems;
12 function checkFinished() {
13 if (testResults.length != galleries.length)
14 return;
15 var success = true;
16 for (var i = 0; i < testResults.length; i++) {
17 if (testResults[i]) {
18 success = false;
21 if (!foundGalleryWithEntry) {
22 testResults.push("Did not find gallery with 1 FileEntry");
23 success = false;
25 if (success) {
26 chrome.test.succeed();
27 return;
29 chrome.test.fail(testResults);
32 var deleteFileCallback = function(file) {
33 testResults.push("");
34 checkFinished();
37 var deleteFileFailedCallback = function(err) {
38 testResults.push("Couldn't delete file: " + err.name);
39 checkFinished();
42 var mediaFileSystemsDirectoryEntryCallback = function(entries) {
43 if (entries.length == 0) {
44 testResults.push("");
45 } else if (entries.length == 1) {
46 if (foundGalleryWithEntry) {
47 testResults.push("Found multiple galleries with 1 FileEntry");
48 } else {
49 foundGalleryWithEntry = true;
50 entries[0].remove(deleteFileCallback, deleteFileFailedCallback);
52 } else {
53 testResults.push("Found a gallery with more than 1 FileEntry");
55 checkFinished();
58 var mediaFileSystemsDirectoryErrorCallback = function(err) {
59 testResults.push("Couldn't read from directory: " + err.name);
60 checkFinished();
63 var mediaFileSystemsListCallback = function(results) {
64 galleries = results;
67 chrome.test.getConfig(function(config) {
68 customArg = JSON.parse(config.customArg);
69 expectedFileSystems = customArg[0];
71 chrome.test.runTests([
72 function getMediaFileSystems() {
73 mediaGalleries.getMediaFileSystems(
74 chrome.test.callbackPass(mediaFileSystemsListCallback));
76 function readFileSystemsAndDeleteFile() {
77 chrome.test.assertEq(expectedFileSystems, galleries.length);
78 if (expectedFileSystems == 0) {
79 chrome.test.succeed();
80 return;
83 for (var i = 0; i < galleries.length; i++) {
84 var dirReader = galleries[i].root.createReader();
85 dirReader.readEntries(mediaFileSystemsDirectoryEntryCallback,
86 mediaFileSystemsDirectoryErrorCallback);
89 ]);