| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 var expectedGalleryEntryLength; // Size of ../common/test.jpg. | 6 var expectedGalleryEntryLength; // Size of ../common/test.jpg. |
| 7 | 7 |
| 8 //Verifies a directory itself, then the contents. | 8 //Verifies a directory itself, then the contents. |
| 9 function getAndVerifyDirectoryEntry(parentEntry, directoryName, | 9 function getAndVerifyDirectoryEntry(parentEntry, directoryName, |
| 10 verifyFunction) { | 10 verifyFunction) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 if (remaining.length == 0) { | 23 if (remaining.length == 0) { |
| 24 doneCallback(); | 24 doneCallback(); |
| 25 return; | 25 return; |
| 26 } | 26 } |
| 27 verifyJPEG(parentDirectoryEntry, remaining.pop(), | 27 verifyJPEG(parentDirectoryEntry, remaining.pop(), |
| 28 expectedGalleryEntryLength, verifyNextJPEG); | 28 expectedGalleryEntryLength, verifyNextJPEG); |
| 29 } | 29 } |
| 30 verifyNextJPEG(); | 30 verifyNextJPEG(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 function GalleryPropertiesTest(picasaGallery) { | 33 function GalleryPropertiesTest(iphotoGallery) { |
| 34 var galleryProperties = | 34 var galleryProperties = |
| 35 mediaGalleries.getMediaFileSystemMetadata(picasaGallery); | 35 mediaGalleries.getMediaFileSystemMetadata(iphotoGallery); |
| 36 chrome.test.assertFalse(galleryProperties.isRemovable); | 36 chrome.test.assertFalse(galleryProperties.isRemovable); |
| 37 chrome.test.succeed(); | 37 chrome.test.succeed(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 function RootListingTest(picasaGallery) { | 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(); |
| 46 } |
| 47 |
| 48 verifyDirectoryEntry(iphotoGallery.root, verify); |
| 49 } |
| 50 |
| 51 function AlbumsListingTest(iphotoGallery) { |
| 41 function verify(directoryEntry, entries) { | 52 function verify(directoryEntry, entries) { |
| 42 chrome.test.assertEq(2, entries.length); | 53 chrome.test.assertEq(2, entries.length); |
| 43 chrome.test.assertTrue(entries[0].isDirectory); | 54 chrome.test.assertTrue(entries[0].isDirectory); |
| 44 chrome.test.assertTrue(entries[1].isDirectory); | 55 chrome.test.assertTrue(entries[1].isDirectory); |
| 45 chrome.test.assertEq("albums", entries[0].name); | 56 chrome.test.assertEq("Album1", entries[0].name); |
| 46 chrome.test.assertEq("folders", entries[1].name); | 57 chrome.test.assertEq("Album2", entries[1].name); |
| 47 chrome.test.succeed(); | 58 chrome.test.succeed(); |
| 48 } | 59 } |
| 49 | 60 |
| 50 verifyDirectoryEntry(picasaGallery.root, verify); | 61 getAndVerifyDirectoryEntry(iphotoGallery.root, "Albums", verify); |
| 51 } | 62 } |
| 52 | 63 |
| 53 function AlbumsListingTest(picasaGallery) { | 64 function Album1ListingTest(iphotoGallery) { |
| 54 function verify(directoryEntry, entries) { | |
| 55 chrome.test.assertEq(2, entries.length); | |
| 56 chrome.test.assertTrue(entries[0].isDirectory); | |
| 57 chrome.test.assertTrue(entries[1].isDirectory); | |
| 58 chrome.test.assertEq("Album 1 Name 1899-12-30", entries[0].name); | |
| 59 chrome.test.assertEq("Album 2 Name 1899-12-30", entries[1].name); | |
| 60 chrome.test.succeed(); | |
| 61 } | |
| 62 | |
| 63 getAndVerifyDirectoryEntry(picasaGallery.root, "albums", verify); | |
| 64 } | |
| 65 | |
| 66 function FoldersListingTest(picasaGallery) { | |
| 67 function verify(directoryEntry, entries) { | |
| 68 chrome.test.assertEq(2, entries.length); | |
| 69 chrome.test.assertTrue(entries[0].isDirectory); | |
| 70 chrome.test.assertTrue(entries[1].isDirectory); | |
| 71 chrome.test.assertEq("folder1 1899-12-30", entries[0].name); | |
| 72 chrome.test.assertEq("folder2 1899-12-30", entries[1].name); | |
| 73 chrome.test.succeed(); | |
| 74 } | |
| 75 | |
| 76 getAndVerifyDirectoryEntry(picasaGallery.root, "folders", verify); | |
| 77 } | |
| 78 | |
| 79 function Album1ListingTest(picasaGallery) { | |
| 80 function verify(directoryEntry, entries) { | 65 function verify(directoryEntry, entries) { |
| 81 chrome.test.assertEq(2, entries.length); | 66 chrome.test.assertEq(2, entries.length); |
| 82 chrome.test.assertTrue(entries[0].isFile); | 67 chrome.test.assertTrue(entries[0].isFile); |
| 83 chrome.test.assertTrue(entries[1].isFile); | 68 chrome.test.assertTrue(entries[1].isFile); |
| 84 chrome.test.assertEq("InBoth.jpg", entries[0].name); | 69 chrome.test.assertEq("InBoth.jpg", entries[0].name); |
| 85 chrome.test.assertEq("InFirstAlbumOnly.jpg", entries[1].name); | 70 chrome.test.assertEq("InFirstAlbumOnly.jpg", entries[1].name); |
| 86 | 71 |
| 87 verifyAllJPEGs(directoryEntry, ["InBoth.jpg", "InFirstAlbumOnly.jpg"], | 72 verifyAllJPEGs(directoryEntry, ["InBoth.jpg", "InFirstAlbumOnly.jpg"], |
| 88 chrome.test.succeed); | 73 chrome.test.succeed); |
| 89 } | 74 } |
| 90 | 75 |
| 91 getAndVerifyDirectoryEntry(picasaGallery.root, | 76 getAndVerifyDirectoryEntry(iphotoGallery.root, |
| 92 "albums/Album 1 Name 1899-12-30", verify); | 77 "Albums/Album1", verify); |
| 93 } | 78 } |
| 94 | 79 |
| 95 function Album2ListingTest(picasaGallery) { | 80 function Album2ListingTest(iphotoGallery) { |
| 96 function verify(directoryEntry, entries) { | 81 function verify(directoryEntry, entries) { |
| 97 chrome.test.assertEq(2, entries.length); | 82 chrome.test.assertEq(1, entries.length); |
| 98 chrome.test.assertTrue(entries[0].isFile); | 83 chrome.test.assertTrue(entries[0].isFile); |
| 99 chrome.test.assertTrue(entries[1].isFile); | |
| 100 chrome.test.assertEq("InBoth.jpg", entries[0].name); | 84 chrome.test.assertEq("InBoth.jpg", entries[0].name); |
| 101 chrome.test.assertEq("InSecondAlbumOnly.jpg", entries[1].name); | |
| 102 | 85 |
| 103 verifyAllJPEGs(directoryEntry, ["InBoth.jpg", "InSecondAlbumOnly.jpg"], | 86 verifyAllJPEGs(directoryEntry, ["InBoth.jpg"], |
| 104 chrome.test.succeed); | 87 chrome.test.succeed); |
| 105 } | 88 } |
| 106 | 89 |
| 107 getAndVerifyDirectoryEntry(picasaGallery.root, | 90 getAndVerifyDirectoryEntry(iphotoGallery.root, |
| 108 "albums/Album 2 Name 1899-12-30", verify); | 91 "Albums/Album2", verify); |
| 109 } | |
| 110 | |
| 111 function Folder1ListingTest(picasaGallery) { | |
| 112 function verify(directoryEntry, entries) { | |
| 113 chrome.test.assertEq(2, entries.length); | |
| 114 chrome.test.assertTrue(entries[0].isFile); | |
| 115 chrome.test.assertTrue(entries[1].isFile); | |
| 116 chrome.test.assertEq("InBoth.jpg", entries[0].name); | |
| 117 chrome.test.assertEq("InSecondAlbumOnly.jpg", entries[1].name); | |
| 118 | |
| 119 verifyAllJPEGs(directoryEntry, ["InBoth.jpg", "InSecondAlbumOnly.jpg"], | |
| 120 chrome.test.succeed); | |
| 121 } | |
| 122 | |
| 123 getAndVerifyDirectoryEntry(picasaGallery.root, | |
| 124 "folders/folder1 1899-12-30", verify); | |
| 125 } | |
| 126 | |
| 127 function Folder2ListingTest(picasaGallery) { | |
| 128 function verify(directoryEntry, entries) { | |
| 129 chrome.test.assertEq(1, entries.length); | |
| 130 chrome.test.assertTrue(entries[0].isFile); | |
| 131 chrome.test.assertEq("InFirstAlbumOnly.jpg", entries[0].name); | |
| 132 | |
| 133 verifyAllJPEGs(directoryEntry, ["InFirstAlbumOnly.jpg"], | |
| 134 chrome.test.succeed); | |
| 135 } | |
| 136 | |
| 137 getAndVerifyDirectoryEntry(picasaGallery.root, | |
| 138 "folders/folder2 1899-12-30", verify); | |
| 139 } | 92 } |
| 140 | 93 |
| 141 function getTest(testFunction) { | 94 function getTest(testFunction) { |
| 142 function getMediaFileSystemsList() { | 95 function getMediaFileSystemsList() { |
| 143 mediaGalleries.getMediaFileSystems(getMediaFileSystemsCallback); | 96 mediaGalleries.getMediaFileSystems(getMediaFileSystemsCallback); |
| 144 } | 97 } |
| 145 | 98 |
| 146 function getMediaFileSystemsCallback(results) { | 99 function getMediaFileSystemsCallback(results) { |
| 147 for (var i = 0; i < results.length; ++i) { | 100 for (var i = 0; i < results.length; ++i) { |
| 148 var properties = mediaGalleries.getMediaFileSystemMetadata(results[i]); | 101 var properties = mediaGalleries.getMediaFileSystemMetadata(results[i]); |
| 149 if (properties.name == "Picasa") { | 102 if (properties.name == "iPhoto") { |
| 150 testFunction(results[i]); | 103 testFunction(results[i]); |
| 151 return; | 104 return; |
| 152 } | 105 } |
| 153 } | 106 } |
| 154 chrome.test.fail("Picasa gallery not found"); | 107 chrome.test.fail("iPhoto gallery not found"); |
| 155 } | 108 } |
| 156 | 109 |
| 157 return function() { | 110 return function() { |
| 158 getMediaFileSystemsList(); | 111 getMediaFileSystemsList(); |
| 159 } | 112 } |
| 160 } | 113 } |
| 161 | 114 |
| 162 CreateDummyWindowToPreventSleep(); | 115 CreateDummyWindowToPreventSleep(); |
| 163 | 116 |
| 164 chrome.test.getConfig(function(config) { | 117 chrome.test.getConfig(function(config) { |
| 165 customArg = JSON.parse(config.customArg); | 118 customArg = JSON.parse(config.customArg); |
| 166 expectedGalleryEntryLength = customArg[0]; | 119 expectedGalleryEntryLength = customArg[0]; |
| 167 | 120 |
| 168 chrome.test.runTests([ | 121 chrome.test.runTests([ |
| 169 getTest(GalleryPropertiesTest), | 122 getTest(GalleryPropertiesTest), |
| 170 getTest(RootListingTest), | 123 getTest(RootListingTest), |
| 171 getTest(AlbumsListingTest), | 124 getTest(AlbumsListingTest), |
| 172 getTest(FoldersListingTest), | |
| 173 getTest(Album1ListingTest), | 125 getTest(Album1ListingTest), |
| 174 getTest(Album2ListingTest), | 126 getTest(Album2ListingTest), |
| 175 getTest(Folder1ListingTest), | |
| 176 getTest(Folder2ListingTest), | |
| 177 ]); | 127 ]); |
| 178 }); | 128 }); |
| OLD | NEW |