Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / file_manager / gallery / js / gallery_util_unittest.js
blob429ce6b4de2962e8a1266f3cd88a6c90c37fed41
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 fileSystem;
7 function setUp() {
8   fileSystem = new MockFileSystem('fake-media-volume');
9   var filenames = [
10     '/DCIM/photos0/IMG00001.jpg',
11     '/DCIM/photos0/IMG00002.jpg',
12     '/DCIM/photos0/IMG00003.jpg',
13     '/DCIM/photos0/MyNote.txt',
14     '/DCIM/photos0/.HiddenFile.jpg',
15     '/DCIM/photos1/IMG00001.jpg',
16     '/DCIM/photos1/IMG00002.jpg',
17     '/DCIM/photos1/IMG00003.jpg'
18   ];
19   fileSystem.populate(filenames);
22 function testcreateEntrySet(callback) {
23   var emptySelectionPromise = GalleryUtil.createEntrySet([
24   ]).then(function(results) {
25     assertEquals(0, results.length);
26   });
28   var singleSelectionPromise = GalleryUtil.createEntrySet([
29     fileSystem.entries['/DCIM/photos0/IMG00002.jpg']
30   ]).then(function(results) {
31     assertEquals(3, results.length);
32     assertEquals('/DCIM/photos0/IMG00001.jpg', results[0].fullPath);
33     assertEquals('/DCIM/photos0/IMG00002.jpg', results[1].fullPath);
34     assertEquals('/DCIM/photos0/IMG00003.jpg', results[2].fullPath);
35   });
37   // If a hidden file is selected directly by users, includes it.
38   var singleHiddenSelectionPromise = GalleryUtil.createEntrySet([
39     fileSystem.entries['/DCIM/photos0/.HiddenFile.jpg']
40   ]).then(function(results) {
41     assertEquals(4, results.length);
42     assertEquals('/DCIM/photos0/.HiddenFile.jpg', results[0].fullPath);
43     assertEquals('/DCIM/photos0/IMG00001.jpg', results[1].fullPath);
44     assertEquals('/DCIM/photos0/IMG00002.jpg', results[2].fullPath);
45     assertEquals('/DCIM/photos0/IMG00003.jpg', results[3].fullPath);
46   });
48   var multipleSelectionPromise = GalleryUtil.createEntrySet([
49     fileSystem.entries['/DCIM/photos0/IMG00001.jpg'],
50     fileSystem.entries['/DCIM/photos0/IMG00002.jpg'],
51   ]).then(function(results) {
52     assertEquals(2, results.length);
53     assertEquals('/DCIM/photos0/IMG00001.jpg', results[0].fullPath);
54     assertEquals('/DCIM/photos0/IMG00002.jpg', results[1].fullPath);
55   });
57   var multipleSelectionReverseOrderPromise = GalleryUtil.createEntrySet([
58     fileSystem.entries['/DCIM/photos0/IMG00002.jpg'],
59     fileSystem.entries['/DCIM/photos0/IMG00001.jpg'],
60   ]).then(function(results) {
61     assertEquals(2, results.length);
62     assertEquals('/DCIM/photos0/IMG00001.jpg', results[0].fullPath);
63     assertEquals('/DCIM/photos0/IMG00002.jpg', results[1].fullPath);
64   });
66   var multipleHiddenSelectionPromise = GalleryUtil.createEntrySet([
67     fileSystem.entries['/DCIM/photos0/IMG00001.jpg'],
68     fileSystem.entries['/DCIM/photos0/.HiddenFile.jpg']
69   ]).then(function(results) {
70     assertEquals(2, results.length);
71     assertEquals('/DCIM/photos0/.HiddenFile.jpg', results[0].fullPath);
72     assertEquals('/DCIM/photos0/IMG00001.jpg', results[1].fullPath);
73   });
75   reportPromise(Promise.all([
76     emptySelectionPromise,
77     singleSelectionPromise,
78     singleHiddenSelectionPromise,
79     multipleSelectionPromise,
80     multipleSelectionReverseOrderPromise,
81     multipleHiddenSelectionPromise
82   ]), callback);