OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var mediaGalleries = chrome.mediaGalleries; | 5 var mediaGalleries = chrome.mediaGalleries; |
6 | 6 |
7 var galleries; | 7 var galleries; |
8 var testResults = []; | 8 var testResults = []; |
| 9 var expectedFileSystems; |
9 | 10 |
10 function checkFinished() { | 11 function checkFinished() { |
11 if (testResults.length != galleries.length) | 12 if (testResults.length != galleries.length) |
12 return; | 13 return; |
13 var success = true; | 14 var success = true; |
14 for (var i = 0; i < testResults.length; i++) { | 15 for (var i = 0; i < testResults.length; i++) { |
15 if (testResults[i]) { | 16 if (testResults[i]) { |
16 success = false; | 17 success = false; |
17 } | 18 } |
18 } | 19 } |
19 if (success) { | 20 if (success) { |
20 chrome.test.succeed(); | 21 chrome.test.succeed(); |
21 return; | 22 return; |
22 } | 23 } |
23 chrome.test.fail(testResults); | 24 chrome.test.fail(testResults); |
24 } | 25 } |
25 | 26 |
26 var mediaFileSystemsDirectoryEntryCallback = function(entries) { | 27 var mediaFileSystemsDirectoryEntryCallback = function(entries) { |
27 testResults.push("Shouldn't have been able to get a directory listing."); | 28 testResults.push("Shouldn't have been able to get a directory listing."); |
28 checkFinished(); | 29 checkFinished(); |
29 } | 30 } |
30 | 31 |
31 var mediaFileSystemsDirectoryErrorCallback = function(err) { | 32 var mediaFileSystemsDirectoryErrorCallback = function(err) { |
32 testResults.push(""); | 33 testResults.push(""); |
33 checkFinished(); | 34 checkFinished(); |
34 }; | 35 }; |
35 | 36 |
36 function testGalleries(expectedFileSystems) { | |
37 chrome.test.assertEq(expectedFileSystems, galleries.length); | |
38 if (expectedFileSystems == 0) { | |
39 chrome.test.succeed(); | |
40 return; | |
41 } | |
42 | |
43 for (var i = 0; i < galleries.length; i++) { | |
44 var dirReader = galleries[i].root.createReader(); | |
45 dirReader.readEntries(mediaFileSystemsDirectoryEntryCallback, | |
46 mediaFileSystemsDirectoryErrorCallback); | |
47 } | |
48 } | |
49 | |
50 var mediaFileSystemsListCallback = function(results) { | 37 var mediaFileSystemsListCallback = function(results) { |
51 galleries = results; | 38 galleries = results; |
52 }; | 39 }; |
53 | 40 |
54 chrome.test.runTests([ | 41 chrome.test.getConfig(function(config) { |
55 function mediaGalleriesNoAccess() { | 42 customArg = JSON.parse(config.customArg); |
56 mediaGalleries.getMediaFileSystems( | 43 expectedFileSystems = customArg[0]; |
57 chrome.test.callbackPass(mediaFileSystemsListCallback)); | 44 |
58 }, | 45 chrome.test.runTests([ |
59 ]); | 46 function getMediaFileSystems() { |
| 47 mediaGalleries.getMediaFileSystems( |
| 48 chrome.test.callbackPass(mediaFileSystemsListCallback)); |
| 49 }, |
| 50 function testGalleries() { |
| 51 chrome.test.assertEq(expectedFileSystems, galleries.length); |
| 52 if (expectedFileSystems == 0) { |
| 53 chrome.test.succeed(); |
| 54 return; |
| 55 } |
| 56 |
| 57 for (var i = 0; i < galleries.length; i++) { |
| 58 var dirReader = galleries[i].root.createReader(); |
| 59 dirReader.readEntries(mediaFileSystemsDirectoryEntryCallback, |
| 60 mediaFileSystemsDirectoryErrorCallback); |
| 61 } |
| 62 }, |
| 63 |
| 64 ]); |
| 65 }) |
OLD | NEW |