Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: chrome/test/data/extensions/api_test/file_system_provider/notify/test.js

Issue 985533004: Implement chrome.fileSystem.requestFileSystem(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed kiosk mode. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * @type {Object} 8 * @type {Object}
9 * @const 9 * @const
10 */ 10 */
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 function runTests() { 77 function runTests() {
78 chrome.test.runTests([ 78 chrome.test.runTests([
79 79
80 // Add a watcher, and then notifies that the entry has changed. 80 // Add a watcher, and then notifies that the entry has changed.
81 function notifyChanged() { 81 function notifyChanged() {
82 test_util.fileSystem.root.getDirectory( 82 test_util.fileSystem.root.getDirectory(
83 TESTING_DIRECTORY.name, 83 TESTING_DIRECTORY.name,
84 {create: false}, 84 {create: false},
85 chrome.test.callbackPass(function(fileEntry) { 85 chrome.test.callbackPass(function(fileEntry) {
86 chrome.test.assertEq(TESTING_DIRECTORY.name, fileEntry.name); 86 chrome.test.assertEq(TESTING_DIRECTORY.name, fileEntry.name);
87 chrome.fileManagerPrivate.addFileWatch( 87 test_util.toExternalEntry(fileEntry).then(
88 fileEntry.toURL(), 88 chrome.test.callbackPass(function(externalEntry) {
89 chrome.test.callbackPass(function(result) { 89 chrome.test.assertTrue(!!externalEntry);
90 chrome.test.assertTrue(result); 90 chrome.fileManagerPrivate.addFileWatch(
91 // Verify closure called when an even arrives. 91 externalEntry.toURL(),
92 directoryChangedCallback = chrome.test.callbackPass( 92 chrome.test.callbackPass(function(result) {
93 function() { 93 chrome.test.assertTrue(result);
94 chrome.test.assertEq(1, directoryChangedEvents.length); 94 // Verify closure called when an even arrives.
95 chrome.test.assertEq( 95 directoryChangedCallback = chrome.test.callbackPass(
96 'changed', directoryChangedEvents[0].eventType); 96 function() {
97 chrome.test.assertEq(
98 fileEntry.toURL(),
99 directoryChangedEvents[0].entry.toURL());
100 // Confirm that the tag is updated.
101 chrome.fileSystemProvider.getAll(
102 chrome.test.callbackPass(function(fileSystems) {
103 chrome.test.assertEq(1, fileSystems.length);
104 chrome.test.assertEq( 97 chrome.test.assertEq(
105 1, fileSystems[0].watchers.length); 98 1, directoryChangedEvents.length);
106 var watcher = fileSystems[0].watchers[0];
107 chrome.test.assertEq( 99 chrome.test.assertEq(
108 TESTING_TAG, watcher.lastTag); 100 'changed',
109 })); 101 directoryChangedEvents[0].eventType);
110 }); 102 chrome.test.assertEq(
111 // TODO(mtomasz): Add more advanced tests, eg. for the details 103 externalEntry.toURL(),
112 // of changes. 104 directoryChangedEvents[0].entry.toURL());
113 chrome.fileSystemProvider.notify({ 105 // Confirm that the tag is updated.
114 fileSystemId: test_util.FILE_SYSTEM_ID, 106 chrome.fileSystemProvider.getAll(
115 observedPath: fileEntry.fullPath, 107 chrome.test.callbackPass(function(items) {
116 recursive: false, 108 chrome.test.assertEq(1, items.length);
117 changeType: 'CHANGED', 109 chrome.test.assertEq(
118 tag: TESTING_TAG 110 1, items[0].watchers.length);
119 }, chrome.test.callbackPass()); 111 var watcher = items[0].watchers[0];
120 })); 112 chrome.test.assertEq(
113 TESTING_TAG, watcher.lastTag);
114 }));
115 });
116 // TODO(mtomasz): Add more advanced tests, eg. for the
117 // details of changes.
118 chrome.fileSystemProvider.notify({
119 fileSystemId: test_util.FILE_SYSTEM_ID,
120 observedPath: fileEntry.fullPath,
121 recursive: false,
122 changeType: 'CHANGED',
123 tag: TESTING_TAG
124 }, chrome.test.callbackPass());
125 }));
126 })).catch(chrome.test.fail);
121 }), function(error) { 127 }), function(error) {
122 chrome.test.fail(error.name); 128 chrome.test.fail(error.name);
123 }); 129 });
124 }, 130 },
125 131
126 // Passing an empty tag (or no tag) is invalid when the file system supports 132 // Passing an empty tag (or no tag) is invalid when the file system supports
127 // the tag. 133 // the tag.
128 function notifyEmptyTag() { 134 function notifyEmptyTag() {
129 test_util.fileSystem.root.getDirectory( 135 test_util.fileSystem.root.getDirectory(
130 TESTING_DIRECTORY.name, 136 TESTING_DIRECTORY.name,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 177
172 // Notify about the watched entry being removed. That should result in the 178 // Notify about the watched entry being removed. That should result in the
173 // watcher being removed. 179 // watcher being removed.
174 function notifyDeleted() { 180 function notifyDeleted() {
175 test_util.fileSystem.root.getDirectory( 181 test_util.fileSystem.root.getDirectory(
176 TESTING_DIRECTORY.name, 182 TESTING_DIRECTORY.name,
177 {create: false}, 183 {create: false},
178 chrome.test.callbackPass(function(fileEntry) { 184 chrome.test.callbackPass(function(fileEntry) {
179 chrome.test.assertEq(TESTING_DIRECTORY.name, fileEntry.name); 185 chrome.test.assertEq(TESTING_DIRECTORY.name, fileEntry.name);
180 // Verify closure called when an even arrives. 186 // Verify closure called when an even arrives.
181 directoryChangedCallback = chrome.test.callbackPass( 187 test_util.toExternalEntry(fileEntry).then(
182 function() { 188 chrome.test.callbackPass(function(externalEntry) {
183 chrome.test.assertEq(2, directoryChangedEvents.length); 189 chrome.test.assertTrue(!!externalEntry);
184 chrome.test.assertEq( 190 directoryChangedCallback = chrome.test.callbackPass(
185 'changed', directoryChangedEvents[1].eventType); 191 function() {
186 chrome.test.assertEq(fileEntry.toURL(), 192 chrome.test.assertEq(2, directoryChangedEvents.length);
187 directoryChangedEvents[1].entry.toURL());
188 // Confirm that the watcher is removed.
189 chrome.fileSystemProvider.getAll(
190 chrome.test.callbackPass(function(fileSystems) {
191 chrome.test.assertEq(1, fileSystems.length);
192 chrome.test.assertEq( 193 chrome.test.assertEq(
193 0, fileSystems[0].watchers.length); 194 'changed', directoryChangedEvents[1].eventType);
194 })); 195 chrome.test.assertEq(
195 }); 196 externalEntry.toURL(),
196 // TODO(mtomasz): Add more advanced tests, eg. for the details 197 directoryChangedEvents[1].entry.toURL());
197 // of changes. 198 // Confirm that the watcher is removed.
198 chrome.fileSystemProvider.notify({ 199 chrome.fileSystemProvider.getAll(
199 fileSystemId: test_util.FILE_SYSTEM_ID, 200 chrome.test.callbackPass(function(fileSystems) {
200 observedPath: fileEntry.fullPath, 201 chrome.test.assertEq(1, fileSystems.length);
201 recursive: false, 202 chrome.test.assertEq(
202 changeType: 'DELETED', 203 0, fileSystems[0].watchers.length);
203 tag: TESTING_ANOTHER_TAG 204 }));
204 }, chrome.test.callbackPass()); 205 });
206 // TODO(mtomasz): Add more advanced tests, eg. for the details
207 // of changes.
208 chrome.fileSystemProvider.notify({
209 fileSystemId: test_util.FILE_SYSTEM_ID,
210 observedPath: fileEntry.fullPath,
211 recursive: false,
212 changeType: 'DELETED',
213 tag: TESTING_ANOTHER_TAG
214 }, chrome.test.callbackPass());
215 })).catch(chrome.test.fail);
205 })); 216 }));
206 }, 217 },
207 218
208 // Notify about an entry which is not watched. That should result in an 219 // Notify about an entry which is not watched. That should result in an
209 // error. 220 // error.
210 function notifyNotWatched() { 221 function notifyNotWatched() {
211 test_util.fileSystem.root.getDirectory( 222 test_util.fileSystem.root.getDirectory(
212 TESTING_DIRECTORY.name, 223 TESTING_DIRECTORY.name,
213 {create: false}, 224 {create: false},
214 chrome.test.callbackPass(function(fileEntry) { 225 chrome.test.callbackPass(function(fileEntry) {
215 chrome.test.assertEq(TESTING_DIRECTORY.name, fileEntry.name); 226 chrome.test.assertEq(TESTING_DIRECTORY.name, fileEntry.name);
216 directoryChangedCallback = function() { 227 test_util.toExternalEntry(fileEntry).then(
217 chrome.test.fail(); 228 chrome.test.callbackPass(function(externalEntry) {
218 }; 229 chrome.test.assertTrue(!!externalEntry);
219 // TODO(mtomasz): NOT_FOUND error should be returned instead. 230 directoryChangedCallback = function() {
220 chrome.fileSystemProvider.notify({ 231 chrome.test.fail();
221 fileSystemId: test_util.FILE_SYSTEM_ID, 232 };
222 observedPath: fileEntry.fullPath, 233 // TODO(mtomasz): NOT_FOUND error should be returned instead.
223 recursive: false, 234 chrome.fileSystemProvider.notify({
224 changeType: 'CHANGED', 235 fileSystemId: test_util.FILE_SYSTEM_ID,
225 tag: TESTING_ANOTHER_TAG 236 observedPath: fileEntry.fullPath,
226 }, chrome.test.callbackFail('NOT_FOUND')); 237 recursive: false,
227 })); 238 changeType: 'CHANGED',
239 tag: TESTING_ANOTHER_TAG
240 }, chrome.test.callbackFail('NOT_FOUND'));
241 })).catch(chrome.test.fail);
242 }));
228 } 243 }
229 ]); 244 ]);
230 } 245 }
231 246
232 // Setup and run all of the test cases. 247 // Setup and run all of the test cases.
233 setUp(runTests); 248 setUp(runTests);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698