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.
11 onDirectoryChanged: new MockAPIEvent(),
12 addFileWatch: function(url) {
13 this.watchedURLs[url] = true;
15 removeFileWatch: function(url) {
16 delete this.watchedURLs[url];
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']
37 var watcher = new EntryListWatcher(list);
39 ['filesystem://rootURL/'],
40 Object.keys(chrome.fileManagerPrivate.watchedURLs));
41 list.push(mockFileSystem.entries['/C/D.txt']);
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']
52 var watcher = new EntryListWatcher(list);
54 ['filesystem://rootURL/', 'filesystem://rootURL/C/'],
55 Object.keys(chrome.fileManagerPrivate.watchedURLs).sort());
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']
69 var watcher = new EntryListWatcher(list);
70 var splicedPromise = new Promise(function(fulfill) {
71 list.addEventListener('splice', fulfill);
74 var deletedB = mockFileSystem.entries['/B.txt'];
75 delete mockFileSystem.entries['/B.txt'];
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]);