Move action_runner.py out of actions folder prior to moving actions to internal.
[chromium-blink-merge.git] / ui / file_manager / gallery / js / entry_list_watcher_unittest.js
blob601a2612b0b24d8bfffb694eb7ffa5bd51ebfcbf
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 chrome;
6 var mockFileSystem;
8 function setUp() {
9   chrome = {
10     fileManagerPrivate: {
11       onDirectoryChanged: new MockAPIEvent(),
12       addFileWatch: function(url) {
13         this.watchedURLs[url] = true;
14       },
15       removeFileWatch: function(url) {
16         delete this.watchedURLs[url];
17       },
18       watchedURLs: {}
19     }
20   };
22   mockFileSystem = new MockFileSystem('volumeId', 'filesystem://rootURL');
23   mockFileSystem.entries['/'] = new MockDirectoryEntry(mockFileSystem, '/');
24   mockFileSystem.entries['/A.txt'] =
25       new MockFileEntry(mockFileSystem, '/A.txt', {});
26   mockFileSystem.entries['/B.txt'] =
27       new MockFileEntry(mockFileSystem, '/B.txt', {});
28   mockFileSystem.entries['/C/'] = new MockDirectoryEntry(mockFileSystem, '/C/');
29   mockFileSystem.entries['/C/D.txt'] =
30       new MockFileEntry(mockFileSystem, '/C/D.txt', {});
33 function testAddWatcher() {
34   var list = new cr.ui.ArrayDataModel([
35     mockFileSystem.entries['/A.txt']
36   ]);
37   var watcher = new EntryListWatcher(list);
38   assertArrayEquals(
39       ['filesystem://rootURL/'],
40       Object.keys(chrome.fileManagerPrivate.watchedURLs));
41   list.push(mockFileSystem.entries['/C/D.txt']);
42   assertArrayEquals(
43       ['filesystem://rootURL/', 'filesystem://rootURL/C/'],
44       Object.keys(chrome.fileManagerPrivate.watchedURLs).sort());
47 function testRemoveWatcher() {
48   var list = new cr.ui.ArrayDataModel([
49     mockFileSystem.entries['/A.txt'],
50     mockFileSystem.entries['/C/D.txt']
51   ]);
52   var watcher = new EntryListWatcher(list);
53   assertArrayEquals(
54       ['filesystem://rootURL/', 'filesystem://rootURL/C/'],
55       Object.keys(chrome.fileManagerPrivate.watchedURLs).sort());
56   list.splice(1, 1);
57   assertArrayEquals(
58       ['filesystem://rootURL/'],
59       Object.keys(chrome.fileManagerPrivate.watchedURLs));
63 function testEntryRemoved(callback) {
64   var list = new cr.ui.ArrayDataModel([
65     mockFileSystem.entries['/A.txt'],
66     mockFileSystem.entries['/B.txt']
67   ]);
69   var watcher = new EntryListWatcher(list);
70   var splicedPromise = new Promise(function(fulfill) {
71     list.addEventListener('splice', fulfill);
72   });
74   var deletedB = mockFileSystem.entries['/B.txt'];
75   delete mockFileSystem.entries['/B.txt'];
76   assertArrayEquals(
77       ['filesystem://rootURL/'],
78       Object.keys(chrome.fileManagerPrivate.watchedURLs));
79   chrome.fileManagerPrivate.onDirectoryChanged.dispatch(
80       {entry: mockFileSystem.entries['/']});
82   reportPromise(splicedPromise.then(function(event) {
83     assertEquals(1, event.removed.length);
84     assertEquals(deletedB, event.removed[0]);
85   }), callback);