1 // Copyright 2014 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
; // Size of ../common/test.jpg.
8 //Verifies a directory itself, then the contents.
9 function getAndVerifyDirectoryEntry(parentEntry
, directoryName
,
11 function getDirectoryCallback(entry
) {
12 chrome
.test
.assertTrue(entry
.isDirectory
);
13 verifyDirectoryEntry(entry
, verifyFunction
);
16 parentEntry
.getDirectory(directoryName
, {create
: false},
17 getDirectoryCallback
, chrome
.test
.fail
);
20 function verifyAllJPEGs(parentDirectoryEntry
, filenames
, doneCallback
) {
21 var remaining
= filenames
;
22 function verifyNextJPEG() {
23 if (remaining
.length
== 0) {
27 verifyJPEG(parentDirectoryEntry
, remaining
.pop(),
28 expectedGalleryEntryLength
, verifyNextJPEG
);
33 function GalleryPropertiesTest(iphotoGallery
) {
34 var galleryProperties
=
35 mediaGalleries
.getMediaFileSystemMetadata(iphotoGallery
);
36 chrome
.test
.assertFalse(galleryProperties
.isRemovable
);
37 chrome
.test
.succeed();
40 function RootListingTest(iphotoGallery
) {
41 function verify(directoryEntry
, entries
) {
42 chrome
.test
.assertEq(1, entries
.length
);
43 chrome
.test
.assertTrue(entries
[0].isDirectory
);
44 chrome
.test
.assertEq("Albums", entries
[0].name
);
45 chrome
.test
.succeed();
48 verifyDirectoryEntry(iphotoGallery
.root
, verify
);
51 function AlbumsListingTest(iphotoGallery
) {
52 function verify(directoryEntry
, entries
) {
53 chrome
.test
.assertEq(2, entries
.length
);
54 chrome
.test
.assertTrue(entries
[0].isDirectory
);
55 chrome
.test
.assertTrue(entries
[1].isDirectory
);
56 chrome
.test
.assertEq("Album1", entries
[0].name
);
57 chrome
.test
.assertEq("Album2", entries
[1].name
);
58 chrome
.test
.succeed();
61 getAndVerifyDirectoryEntry(iphotoGallery
.root
, "Albums", verify
);
64 function Album1ListingTest(iphotoGallery
) {
65 function verify(directoryEntry
, entries
) {
66 chrome
.test
.assertEq(2, entries
.length
);
67 chrome
.test
.assertTrue(entries
[0].isFile
);
68 chrome
.test
.assertTrue(entries
[1].isFile
);
69 chrome
.test
.assertEq("InBoth.jpg", entries
[0].name
);
70 chrome
.test
.assertEq("InFirstAlbumOnly.jpg", entries
[1].name
);
72 verifyAllJPEGs(directoryEntry
, ["InBoth.jpg", "InFirstAlbumOnly.jpg"],
76 getAndVerifyDirectoryEntry(iphotoGallery
.root
,
77 "Albums/Album1", verify
);
80 function Album2ListingTest(iphotoGallery
) {
81 function verify(directoryEntry
, entries
) {
82 chrome
.test
.assertEq(1, entries
.length
);
83 chrome
.test
.assertTrue(entries
[0].isFile
);
84 chrome
.test
.assertEq("InBoth.jpg", entries
[0].name
);
86 verifyAllJPEGs(directoryEntry
, ["InBoth.jpg"],
90 getAndVerifyDirectoryEntry(iphotoGallery
.root
,
91 "Albums/Album2", verify
);
94 function getTest(testFunction
) {
95 function getMediaFileSystemsList() {
96 mediaGalleries
.getMediaFileSystems(getMediaFileSystemsCallback
);
99 function getMediaFileSystemsCallback(results
) {
100 for (var i
= 0; i
< results
.length
; ++i
) {
101 var properties
= mediaGalleries
.getMediaFileSystemMetadata(results
[i
]);
102 if (properties
.name
== "iPhoto") {
103 testFunction(results
[i
]);
107 chrome
.test
.fail("iPhoto gallery not found");
111 getMediaFileSystemsList();
115 CreateDummyWindowToPreventSleep();
117 chrome
.test
.getConfig(function(config
) {
118 customArg
= JSON
.parse(config
.customArg
);
119 expectedGalleryEntryLength
= customArg
[0];
121 chrome
.test
.runTests([
122 getTest(GalleryPropertiesTest
),
123 getTest(RootListingTest
),
124 getTest(AlbumsListingTest
),
125 getTest(Album1ListingTest
),
126 getTest(Album2ListingTest
),