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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/provided_file_system_unittest.cc

Issue 674413002: [fsp] Rename ObserveEntry with AddWatcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 6 years, 1 month 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 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" 5 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/files/file.h" 10 #include "base/files/file.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" 17 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h"
18 #include "chrome/browser/chromeos/file_system_provider/notification_manager.h" 18 #include "chrome/browser/chromeos/file_system_provider/notification_manager.h"
19 #include "chrome/browser/chromeos/file_system_provider/observed_entry.h"
20 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h" 19 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h"
21 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h" 20 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h"
22 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_obse rver.h" 21 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_obse rver.h"
23 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" 22 #include "chrome/browser/chromeos/file_system_provider/request_manager.h"
23 #include "chrome/browser/chromeos/file_system_provider/watcher.h"
24 #include "chrome/common/extensions/api/file_system_provider.h" 24 #include "chrome/common/extensions/api/file_system_provider.h"
25 #include "chrome/common/extensions/api/file_system_provider_internal.h" 25 #include "chrome/common/extensions/api/file_system_provider_internal.h"
26 #include "chrome/test/base/testing_profile.h" 26 #include "chrome/test/base/testing_profile.h"
27 #include "content/public/test/test_browser_thread_bundle.h" 27 #include "content/public/test/test_browser_thread_bundle.h"
28 #include "extensions/browser/event_router.h" 28 #include "extensions/browser/event_router.h"
29 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
30 30
31 namespace chromeos { 31 namespace chromeos {
32 namespace file_system_provider { 32 namespace file_system_provider {
33 namespace { 33 namespace {
(...skipping 24 matching lines...) Expand all
58 const std::string& extension_id, 58 const std::string& extension_id,
59 scoped_ptr<extensions::Event> event) override { 59 scoped_ptr<extensions::Event> event) override {
60 ASSERT_TRUE(file_system_); 60 ASSERT_TRUE(file_system_);
61 std::string file_system_id; 61 std::string file_system_id;
62 const base::DictionaryValue* dictionary_value = NULL; 62 const base::DictionaryValue* dictionary_value = NULL;
63 ASSERT_TRUE(event->event_args->GetDictionary(0, &dictionary_value)); 63 ASSERT_TRUE(event->event_args->GetDictionary(0, &dictionary_value));
64 EXPECT_TRUE(dictionary_value->GetString("fileSystemId", &file_system_id)); 64 EXPECT_TRUE(dictionary_value->GetString("fileSystemId", &file_system_id));
65 EXPECT_EQ(kFileSystemId, file_system_id); 65 EXPECT_EQ(kFileSystemId, file_system_id);
66 int request_id = -1; 66 int request_id = -1;
67 EXPECT_TRUE(dictionary_value->GetInteger("requestId", &request_id)); 67 EXPECT_TRUE(dictionary_value->GetInteger("requestId", &request_id));
68 EXPECT_TRUE(event->event_name == 68 EXPECT_TRUE(event->event_name == extensions::api::file_system_provider::
69 extensions::api::file_system_provider:: 69 OnAddWatcherRequested::kEventName ||
70 OnObserveDirectoryRequested::kEventName ||
71 event->event_name == extensions::api::file_system_provider:: 70 event->event_name == extensions::api::file_system_provider::
72 OnUnobserveEntryRequested::kEventName); 71 OnRemoveWatcherRequested::kEventName);
73 72
74 if (reply_result_ == base::File::FILE_OK) { 73 if (reply_result_ == base::File::FILE_OK) {
75 base::ListValue value_as_list; 74 base::ListValue value_as_list;
76 value_as_list.Set(0, new base::StringValue(kFileSystemId)); 75 value_as_list.Set(0, new base::StringValue(kFileSystemId));
77 value_as_list.Set(1, new base::FundamentalValue(request_id)); 76 value_as_list.Set(1, new base::FundamentalValue(request_id));
78 value_as_list.Set(2, new base::FundamentalValue(0) /* execution_time */); 77 value_as_list.Set(2, new base::FundamentalValue(0) /* execution_time */);
79 78
80 using extensions::api::file_system_provider_internal:: 79 using extensions::api::file_system_provider_internal::
81 OperationRequestedSuccess::Params; 80 OperationRequestedSuccess::Params;
82 scoped_ptr<Params> params(Params::Create(value_as_list)); 81 scoped_ptr<Params> params(Params::Create(value_as_list));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 private: 118 private:
120 const ProvidedFileSystemObserver::ChangeType change_type_; 119 const ProvidedFileSystemObserver::ChangeType change_type_;
121 const ProvidedFileSystemObserver::Changes changes_; 120 const ProvidedFileSystemObserver::Changes changes_;
122 121
123 DISALLOW_COPY_AND_ASSIGN(ChangeEvent); 122 DISALLOW_COPY_AND_ASSIGN(ChangeEvent);
124 }; 123 };
125 124
126 Observer() : list_changed_counter_(0), tag_updated_counter_(0) {} 125 Observer() : list_changed_counter_(0), tag_updated_counter_(0) {}
127 126
128 // ProvidedFileSystemInterfaceObserver overrides. 127 // ProvidedFileSystemInterfaceObserver overrides.
129 virtual void OnObservedEntryChanged( 128 virtual void OnWatcherChanged(
130 const ProvidedFileSystemInfo& file_system_info, 129 const ProvidedFileSystemInfo& file_system_info,
131 const ObservedEntry& observed_entry, 130 const Watcher& watcher,
132 ProvidedFileSystemObserver::ChangeType change_type, 131 ProvidedFileSystemObserver::ChangeType change_type,
133 const ProvidedFileSystemObserver::Changes& changes, 132 const ProvidedFileSystemObserver::Changes& changes,
134 const base::Closure& callback) override { 133 const base::Closure& callback) override {
135 EXPECT_EQ(kFileSystemId, file_system_info.file_system_id()); 134 EXPECT_EQ(kFileSystemId, file_system_info.file_system_id());
136 change_events_.push_back(new ChangeEvent(change_type, changes)); 135 change_events_.push_back(new ChangeEvent(change_type, changes));
137 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); 136 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
138 } 137 }
139 138
140 virtual void OnObservedEntryTagUpdated( 139 virtual void OnWatcherTagUpdated(
141 const ProvidedFileSystemInfo& file_system_info, 140 const ProvidedFileSystemInfo& file_system_info,
142 const ObservedEntry& observed_entry) override { 141 const Watcher& watcher) override {
143 EXPECT_EQ(kFileSystemId, file_system_info.file_system_id()); 142 EXPECT_EQ(kFileSystemId, file_system_info.file_system_id());
144 ++tag_updated_counter_; 143 ++tag_updated_counter_;
145 } 144 }
146 145
147 virtual void OnObservedEntryListChanged( 146 virtual void OnWatcherListChanged(
148 const ProvidedFileSystemInfo& file_system_info, 147 const ProvidedFileSystemInfo& file_system_info,
149 const ObservedEntries& observed_entries) override { 148 const Watchers& watchers) override {
150 EXPECT_EQ(kFileSystemId, file_system_info.file_system_id()); 149 EXPECT_EQ(kFileSystemId, file_system_info.file_system_id());
151 ++list_changed_counter_; 150 ++list_changed_counter_;
152 } 151 }
153 152
154 int list_changed_counter() const { return list_changed_counter_; } 153 int list_changed_counter() const { return list_changed_counter_; }
155 const ScopedVector<ChangeEvent>& change_events() const { 154 const ScopedVector<ChangeEvent>& change_events() const {
156 return change_events_; 155 return change_events_;
157 } 156 }
158 int tag_updated_counter() const { return tag_updated_counter_; } 157 int tag_updated_counter() const { return tag_updated_counter_; }
159 158
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 mount_options.file_system_id = kFileSystemId; 202 mount_options.file_system_id = kFileSystemId;
204 mount_options.display_name = kDisplayName; 203 mount_options.display_name = kDisplayName;
205 mount_options.supports_notify_tag = true; 204 mount_options.supports_notify_tag = true;
206 file_system_info_.reset( 205 file_system_info_.reset(
207 new ProvidedFileSystemInfo(kExtensionId, mount_options, mount_path)); 206 new ProvidedFileSystemInfo(kExtensionId, mount_options, mount_path));
208 provided_file_system_.reset( 207 provided_file_system_.reset(
209 new ProvidedFileSystem(profile_.get(), *file_system_info_.get())); 208 new ProvidedFileSystem(profile_.get(), *file_system_info_.get()));
210 event_router_.reset( 209 event_router_.reset(
211 new FakeEventRouter(profile_.get(), provided_file_system_.get())); 210 new FakeEventRouter(profile_.get(), provided_file_system_.get()));
212 event_router_->AddEventListener(extensions::api::file_system_provider:: 211 event_router_->AddEventListener(extensions::api::file_system_provider::
213 OnObserveDirectoryRequested::kEventName, 212 OnAddWatcherRequested::kEventName,
214 NULL, 213 NULL,
215 kExtensionId); 214 kExtensionId);
216 event_router_->AddEventListener(extensions::api::file_system_provider:: 215 event_router_->AddEventListener(extensions::api::file_system_provider::
217 OnUnobserveEntryRequested::kEventName, 216 OnRemoveWatcherRequested::kEventName,
218 NULL, 217 NULL,
219 kExtensionId); 218 kExtensionId);
220 provided_file_system_->SetEventRouterForTesting(event_router_.get()); 219 provided_file_system_->SetEventRouterForTesting(event_router_.get());
221 provided_file_system_->SetNotificationManagerForTesting( 220 provided_file_system_->SetNotificationManagerForTesting(
222 make_scoped_ptr(new StubNotificationManager)); 221 make_scoped_ptr(new StubNotificationManager));
223 } 222 }
224 223
225 content::TestBrowserThreadBundle thread_bundle_; 224 content::TestBrowserThreadBundle thread_bundle_;
226 scoped_ptr<TestingProfile> profile_; 225 scoped_ptr<TestingProfile> profile_;
227 scoped_ptr<FakeEventRouter> event_router_; 226 scoped_ptr<FakeEventRouter> event_router_;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 base::Bind(&LogStatus, base::Unretained(&log), base::File::FILE_OK))); 271 base::Bind(&LogStatus, base::Unretained(&log), base::File::FILE_OK)));
273 base::Closure callback = auto_updater->CreateCallback(); 272 base::Closure callback = auto_updater->CreateCallback();
274 // The callback gets out of scope, so the ref counted auto updater instance 273 // The callback gets out of scope, so the ref counted auto updater instance
275 // gets deleted. Still, updating shouldn't be invoked, since the callback 274 // gets deleted. Still, updating shouldn't be invoked, since the callback
276 // wasn't executed. 275 // wasn't executed.
277 } 276 }
278 base::RunLoop().RunUntilIdle(); 277 base::RunLoop().RunUntilIdle();
279 EXPECT_EQ(0u, log.size()); 278 EXPECT_EQ(0u, log.size());
280 } 279 }
281 280
282 TEST_F(FileSystemProviderProvidedFileSystemTest, ObserveDirectory_NotFound) { 281 TEST_F(FileSystemProviderProvidedFileSystemTest, AddWatcher_NotFound) {
283 Log log; 282 Log log;
284 Observer observer; 283 Observer observer;
285 284
286 provided_file_system_->AddObserver(&observer); 285 provided_file_system_->AddObserver(&observer);
287 286
288 // First, set the extension response to an error. 287 // First, set the extension response to an error.
289 event_router_->set_reply_result(base::File::FILE_ERROR_NOT_FOUND); 288 event_router_->set_reply_result(base::File::FILE_ERROR_NOT_FOUND);
290 289
291 provided_file_system_->ObserveDirectory( 290 provided_file_system_->AddWatcher(
292 GURL(kOrigin), 291 GURL(kOrigin),
293 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 292 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
294 false /* recursive */, 293 false /* recursive */,
295 false /* persistent */, 294 false /* persistent */,
296 base::Bind(&LogStatus, base::Unretained(&log))); 295 base::Bind(&LogStatus, base::Unretained(&log)));
297 base::RunLoop().RunUntilIdle(); 296 base::RunLoop().RunUntilIdle();
298 297
299 // The directory should not become observed because of an error. 298 // The directory should not become watched because of an error.
300 ASSERT_EQ(1u, log.size()); 299 ASSERT_EQ(1u, log.size());
301 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, log[0]); 300 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, log[0]);
302 301
303 ObservedEntries* const observed_entries = 302 Watchers* const watchers = provided_file_system_->GetWatchers();
304 provided_file_system_->GetObservedEntries(); 303 EXPECT_EQ(0u, watchers->size());
305 EXPECT_EQ(0u, observed_entries->size());
306 304
307 // The observer should not be called. 305 // The observer should not be called.
308 EXPECT_EQ(0, observer.list_changed_counter()); 306 EXPECT_EQ(0, observer.list_changed_counter());
309 EXPECT_EQ(0, observer.tag_updated_counter()); 307 EXPECT_EQ(0, observer.tag_updated_counter());
310 308
311 provided_file_system_->RemoveObserver(&observer); 309 provided_file_system_->RemoveObserver(&observer);
312 } 310 }
313 311
314 TEST_F(FileSystemProviderProvidedFileSystemTest, ObserveDirectory) { 312 TEST_F(FileSystemProviderProvidedFileSystemTest, AddWatcher) {
315 Log log; 313 Log log;
316 Observer observer; 314 Observer observer;
317 315
318 provided_file_system_->AddObserver(&observer); 316 provided_file_system_->AddObserver(&observer);
319 317
320 provided_file_system_->ObserveDirectory( 318 provided_file_system_->AddWatcher(
321 GURL(kOrigin), 319 GURL(kOrigin),
322 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 320 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
323 false /* recursive */, 321 false /* recursive */,
324 true /* persistent */, 322 true /* persistent */,
325 base::Bind(&LogStatus, base::Unretained(&log))); 323 base::Bind(&LogStatus, base::Unretained(&log)));
326 base::RunLoop().RunUntilIdle(); 324 base::RunLoop().RunUntilIdle();
327 325
328 ASSERT_EQ(1u, log.size()); 326 ASSERT_EQ(1u, log.size());
329 EXPECT_EQ(base::File::FILE_OK, log[0]); 327 EXPECT_EQ(base::File::FILE_OK, log[0]);
330 EXPECT_EQ(1, observer.list_changed_counter()); 328 EXPECT_EQ(1, observer.list_changed_counter());
331 EXPECT_EQ(0, observer.tag_updated_counter()); 329 EXPECT_EQ(0, observer.tag_updated_counter());
332 330
333 ObservedEntries* const observed_entries = 331 Watchers* const watchers = provided_file_system_->GetWatchers();
334 provided_file_system_->GetObservedEntries(); 332 ASSERT_EQ(1u, watchers->size());
335 ASSERT_EQ(1u, observed_entries->size()); 333 const Watcher& watcher = watchers->begin()->second;
336 const ObservedEntry& observed_entry = observed_entries->begin()->second; 334 EXPECT_EQ(FILE_PATH_LITERAL(kDirectoryPath), watcher.entry_path.value());
337 EXPECT_EQ(FILE_PATH_LITERAL(kDirectoryPath), 335 EXPECT_FALSE(watcher.recursive);
338 observed_entry.entry_path.value()); 336 EXPECT_EQ("", watcher.last_tag);
339 EXPECT_FALSE(observed_entry.recursive);
340 EXPECT_EQ("", observed_entry.last_tag);
341 337
342 provided_file_system_->RemoveObserver(&observer); 338 provided_file_system_->RemoveObserver(&observer);
343 } 339 }
344 340
345 TEST_F(FileSystemProviderProvidedFileSystemTest, 341 TEST_F(FileSystemProviderProvidedFileSystemTest, AddWatcher_PersistentIllegal) {
346 ObserveDirectory_PersistentIllegal) {
347 Log log; 342 Log log;
348 Observer observer; 343 Observer observer;
349 344
350 // Create a provided file system interface, which does not support a notify 345 // Create a provided file system interface, which does not support a notify
351 // tag, though. 346 // tag, though.
352 const base::FilePath mount_path = 347 const base::FilePath mount_path =
353 util::GetMountPath(profile_.get(), kExtensionId, kFileSystemId); 348 util::GetMountPath(profile_.get(), kExtensionId, kFileSystemId);
354 MountOptions mount_options; 349 MountOptions mount_options;
355 mount_options.file_system_id = kFileSystemId; 350 mount_options.file_system_id = kFileSystemId;
356 mount_options.display_name = kDisplayName; 351 mount_options.display_name = kDisplayName;
357 mount_options.supports_notify_tag = false; 352 mount_options.supports_notify_tag = false;
358 ProvidedFileSystemInfo file_system_info( 353 ProvidedFileSystemInfo file_system_info(
359 kExtensionId, mount_options, mount_path); 354 kExtensionId, mount_options, mount_path);
360 ProvidedFileSystem simple_provided_file_system(profile_.get(), 355 ProvidedFileSystem simple_provided_file_system(profile_.get(),
361 file_system_info); 356 file_system_info);
362 simple_provided_file_system.SetEventRouterForTesting(event_router_.get()); 357 simple_provided_file_system.SetEventRouterForTesting(event_router_.get());
363 simple_provided_file_system.SetNotificationManagerForTesting( 358 simple_provided_file_system.SetNotificationManagerForTesting(
364 make_scoped_ptr(new StubNotificationManager)); 359 make_scoped_ptr(new StubNotificationManager));
365 360
366 simple_provided_file_system.AddObserver(&observer); 361 simple_provided_file_system.AddObserver(&observer);
367 362
368 simple_provided_file_system.ObserveDirectory( 363 simple_provided_file_system.AddWatcher(
369 GURL(kOrigin), 364 GURL(kOrigin),
370 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 365 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
371 false /* recursive */, 366 false /* recursive */,
372 true /* persistent */, 367 true /* persistent */,
373 base::Bind(&LogStatus, base::Unretained(&log))); 368 base::Bind(&LogStatus, base::Unretained(&log)));
374 base::RunLoop().RunUntilIdle(); 369 base::RunLoop().RunUntilIdle();
375 370
376 ASSERT_EQ(1u, log.size()); 371 ASSERT_EQ(1u, log.size());
377 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, log[0]); 372 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, log[0]);
378 EXPECT_EQ(0, observer.list_changed_counter()); 373 EXPECT_EQ(0, observer.list_changed_counter());
379 EXPECT_EQ(0, observer.tag_updated_counter()); 374 EXPECT_EQ(0, observer.tag_updated_counter());
380 375
381 simple_provided_file_system.RemoveObserver(&observer); 376 simple_provided_file_system.RemoveObserver(&observer);
382 } 377 }
383 378
384 TEST_F(FileSystemProviderProvidedFileSystemTest, ObserveDirectory_Exists) { 379 TEST_F(FileSystemProviderProvidedFileSystemTest, AddWatcher_Exists) {
385 Observer observer; 380 Observer observer;
386 provided_file_system_->AddObserver(&observer); 381 provided_file_system_->AddObserver(&observer);
387 382
388 { 383 {
389 // First observe a directory not recursively. 384 // First watch a directory not recursively.
390 Log log; 385 Log log;
391 provided_file_system_->ObserveDirectory( 386 provided_file_system_->AddWatcher(
392 GURL(kOrigin), 387 GURL(kOrigin),
393 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 388 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
394 false /* recursive */, 389 false /* recursive */,
395 true /* persistent */, 390 true /* persistent */,
396 base::Bind(&LogStatus, base::Unretained(&log))); 391 base::Bind(&LogStatus, base::Unretained(&log)));
397 base::RunLoop().RunUntilIdle(); 392 base::RunLoop().RunUntilIdle();
398 393
399 ASSERT_EQ(1u, log.size()); 394 ASSERT_EQ(1u, log.size());
400 EXPECT_EQ(base::File::FILE_OK, log[0]); 395 EXPECT_EQ(base::File::FILE_OK, log[0]);
401 EXPECT_EQ(1, observer.list_changed_counter()); 396 EXPECT_EQ(1, observer.list_changed_counter());
402 EXPECT_EQ(0, observer.tag_updated_counter()); 397 EXPECT_EQ(0, observer.tag_updated_counter());
403 398
404 ObservedEntries* const observed_entries = 399 Watchers* const watchers = provided_file_system_->GetWatchers();
405 provided_file_system_->GetObservedEntries(); 400 ASSERT_TRUE(watchers);
406 ASSERT_TRUE(observed_entries); 401 ASSERT_EQ(1u, watchers->size());
407 ASSERT_EQ(1u, observed_entries->size()); 402 const auto& watcher_it = watchers->find(
408 const auto& observed_entry_it = observed_entries->find( 403 WatcherKey(base::FilePath(FILE_PATH_LITERAL(kDirectoryPath)),
409 ObservedEntryKey(base::FilePath(FILE_PATH_LITERAL(kDirectoryPath)), 404 false /* recursive */));
410 false /* recursive */)); 405 ASSERT_NE(watchers->end(), watcher_it);
411 ASSERT_NE(observed_entries->end(), observed_entry_it);
412 406
413 EXPECT_EQ(1u, observed_entry_it->second.subscribers.size()); 407 EXPECT_EQ(1u, watcher_it->second.subscribers.size());
414 const auto& subscriber_it = 408 const auto& subscriber_it =
415 observed_entry_it->second.subscribers.find(GURL(kOrigin)); 409 watcher_it->second.subscribers.find(GURL(kOrigin));
416 ASSERT_NE(observed_entry_it->second.subscribers.end(), subscriber_it); 410 ASSERT_NE(watcher_it->second.subscribers.end(), subscriber_it);
417 EXPECT_EQ(kOrigin, subscriber_it->second.origin.spec()); 411 EXPECT_EQ(kOrigin, subscriber_it->second.origin.spec());
418 EXPECT_TRUE(subscriber_it->second.persistent); 412 EXPECT_TRUE(subscriber_it->second.persistent);
419 } 413 }
420 414
421 { 415 {
422 // Create another non-recursive observer. That should fail. 416 // Create another non-recursive observer. That should fail.
423 Log log; 417 Log log;
424 provided_file_system_->ObserveDirectory( 418 provided_file_system_->AddWatcher(
425 GURL(kOrigin), 419 GURL(kOrigin),
426 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 420 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
427 false /* recursive */, 421 false /* recursive */,
428 true /* persistent */, 422 true /* persistent */,
429 base::Bind(&LogStatus, base::Unretained(&log))); 423 base::Bind(&LogStatus, base::Unretained(&log)));
430 base::RunLoop().RunUntilIdle(); 424 base::RunLoop().RunUntilIdle();
431 425
432 ASSERT_EQ(1u, log.size()); 426 ASSERT_EQ(1u, log.size());
433 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, log[0]); 427 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, log[0]);
434 EXPECT_EQ(1, observer.list_changed_counter()); // No changes on the list. 428 EXPECT_EQ(1, observer.list_changed_counter()); // No changes on the list.
435 EXPECT_EQ(0, observer.tag_updated_counter()); 429 EXPECT_EQ(0, observer.tag_updated_counter());
436 } 430 }
437 431
438 { 432 {
439 // Lastly, create another recursive observer. That should succeed. 433 // Lastly, create another recursive observer. That should succeed.
440 Log log; 434 Log log;
441 provided_file_system_->ObserveDirectory( 435 provided_file_system_->AddWatcher(
442 GURL(kOrigin), 436 GURL(kOrigin),
443 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 437 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
444 true /* recursive */, 438 true /* recursive */,
445 true /* persistent */, 439 true /* persistent */,
446 base::Bind(&LogStatus, base::Unretained(&log))); 440 base::Bind(&LogStatus, base::Unretained(&log)));
447 base::RunLoop().RunUntilIdle(); 441 base::RunLoop().RunUntilIdle();
448 442
449 ASSERT_EQ(1u, log.size()); 443 ASSERT_EQ(1u, log.size());
450 EXPECT_EQ(base::File::FILE_OK, log[0]); 444 EXPECT_EQ(base::File::FILE_OK, log[0]);
451 EXPECT_EQ(2, observer.list_changed_counter()); 445 EXPECT_EQ(2, observer.list_changed_counter());
452 EXPECT_EQ(0, observer.tag_updated_counter()); 446 EXPECT_EQ(0, observer.tag_updated_counter());
453 } 447 }
454 448
455 provided_file_system_->RemoveObserver(&observer); 449 provided_file_system_->RemoveObserver(&observer);
456 } 450 }
457 451
458 TEST_F(FileSystemProviderProvidedFileSystemTest, 452 TEST_F(FileSystemProviderProvidedFileSystemTest, AddWatcher_MultipleOrigins) {
459 ObserveDirectory_MultipleOrigins) {
460 Observer observer; 453 Observer observer;
461 provided_file_system_->AddObserver(&observer); 454 provided_file_system_->AddObserver(&observer);
462 455
463 { 456 {
464 // First observe a directory not recursively. 457 // First watch a directory not recursively.
465 Log log; 458 Log log;
466 provided_file_system_->ObserveDirectory( 459 provided_file_system_->AddWatcher(
467 GURL(kOrigin), 460 GURL(kOrigin),
468 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 461 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
469 false /* recursive */, 462 false /* recursive */,
470 false /* persistent */, 463 false /* persistent */,
471 base::Bind(&LogStatus, base::Unretained(&log))); 464 base::Bind(&LogStatus, base::Unretained(&log)));
472 base::RunLoop().RunUntilIdle(); 465 base::RunLoop().RunUntilIdle();
473 466
474 ASSERT_EQ(1u, log.size()); 467 ASSERT_EQ(1u, log.size());
475 EXPECT_EQ(base::File::FILE_OK, log[0]); 468 EXPECT_EQ(base::File::FILE_OK, log[0]);
476 EXPECT_EQ(1, observer.list_changed_counter()); 469 EXPECT_EQ(1, observer.list_changed_counter());
477 EXPECT_EQ(0, observer.tag_updated_counter()); 470 EXPECT_EQ(0, observer.tag_updated_counter());
478 471
479 ObservedEntries* const observed_entries = 472 Watchers* const watchers = provided_file_system_->GetWatchers();
480 provided_file_system_->GetObservedEntries(); 473 ASSERT_TRUE(watchers);
481 ASSERT_TRUE(observed_entries); 474 ASSERT_EQ(1u, watchers->size());
482 ASSERT_EQ(1u, observed_entries->size()); 475 const auto& watcher_it = watchers->find(
483 const auto& observed_entry_it = observed_entries->find( 476 WatcherKey(base::FilePath(FILE_PATH_LITERAL(kDirectoryPath)),
484 ObservedEntryKey(base::FilePath(FILE_PATH_LITERAL(kDirectoryPath)), 477 false /* recursive */));
485 false /* recursive */)); 478 ASSERT_NE(watchers->end(), watcher_it);
486 ASSERT_NE(observed_entries->end(), observed_entry_it);
487 479
488 EXPECT_EQ(1u, observed_entry_it->second.subscribers.size()); 480 EXPECT_EQ(1u, watcher_it->second.subscribers.size());
489 const auto& subscriber_it = 481 const auto& subscriber_it =
490 observed_entry_it->second.subscribers.find(GURL(kOrigin)); 482 watcher_it->second.subscribers.find(GURL(kOrigin));
491 ASSERT_NE(observed_entry_it->second.subscribers.end(), subscriber_it); 483 ASSERT_NE(watcher_it->second.subscribers.end(), subscriber_it);
492 EXPECT_EQ(kOrigin, subscriber_it->first.spec()); 484 EXPECT_EQ(kOrigin, subscriber_it->first.spec());
493 EXPECT_EQ(kOrigin, subscriber_it->second.origin.spec()); 485 EXPECT_EQ(kOrigin, subscriber_it->second.origin.spec());
494 EXPECT_FALSE(subscriber_it->second.persistent); 486 EXPECT_FALSE(subscriber_it->second.persistent);
495 } 487 }
496 488
497 { 489 {
498 // Create another observer, but recursive and with a different origin. 490 // Create another watcher, but recursive and with a different origin.
499 Log log; 491 Log log;
500 provided_file_system_->ObserveDirectory( 492 provided_file_system_->AddWatcher(
501 GURL(kAnotherOrigin), 493 GURL(kAnotherOrigin),
502 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 494 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
503 true /* recursive */, 495 true /* recursive */,
504 true /* persistent */, 496 true /* persistent */,
505 base::Bind(&LogStatus, base::Unretained(&log))); 497 base::Bind(&LogStatus, base::Unretained(&log)));
506 base::RunLoop().RunUntilIdle(); 498 base::RunLoop().RunUntilIdle();
507 499
508 ASSERT_EQ(1u, log.size()); 500 ASSERT_EQ(1u, log.size());
509 EXPECT_EQ(base::File::FILE_OK, log[0]); 501 EXPECT_EQ(base::File::FILE_OK, log[0]);
510 EXPECT_EQ(2, observer.list_changed_counter()); 502 EXPECT_EQ(2, observer.list_changed_counter());
511 EXPECT_EQ(0, observer.tag_updated_counter()); 503 EXPECT_EQ(0, observer.tag_updated_counter());
512 504
513 ObservedEntries* const observed_entries = 505 Watchers* const watchers = provided_file_system_->GetWatchers();
514 provided_file_system_->GetObservedEntries(); 506 ASSERT_TRUE(watchers);
515 ASSERT_TRUE(observed_entries); 507 ASSERT_EQ(2u, watchers->size());
516 ASSERT_EQ(2u, observed_entries->size()); 508 const auto& watcher_it = watchers->find(
517 const auto& observed_entry_it = observed_entries->find( 509 WatcherKey(base::FilePath(FILE_PATH_LITERAL(kDirectoryPath)),
518 ObservedEntryKey(base::FilePath(FILE_PATH_LITERAL(kDirectoryPath)), 510 false /* recursive */));
519 false /* recursive */)); 511 ASSERT_NE(watchers->end(), watcher_it);
520 ASSERT_NE(observed_entries->end(), observed_entry_it);
521 512
522 EXPECT_EQ(1u, observed_entry_it->second.subscribers.size()); 513 EXPECT_EQ(1u, watcher_it->second.subscribers.size());
523 const auto& subscriber_it = 514 const auto& subscriber_it =
524 observed_entry_it->second.subscribers.find(GURL(kOrigin)); 515 watcher_it->second.subscribers.find(GURL(kOrigin));
525 ASSERT_NE(observed_entry_it->second.subscribers.end(), subscriber_it); 516 ASSERT_NE(watcher_it->second.subscribers.end(), subscriber_it);
526 EXPECT_EQ(kOrigin, subscriber_it->first.spec()); 517 EXPECT_EQ(kOrigin, subscriber_it->first.spec());
527 EXPECT_EQ(kOrigin, subscriber_it->second.origin.spec()); 518 EXPECT_EQ(kOrigin, subscriber_it->second.origin.spec());
528 EXPECT_FALSE(subscriber_it->second.persistent); 519 EXPECT_FALSE(subscriber_it->second.persistent);
529 } 520 }
530 521
531 { 522 {
532 // Unobserve the second one gracefully. 523 // Remove the second watcher gracefully.
533 Log log; 524 Log log;
534 provided_file_system_->UnobserveEntry( 525 provided_file_system_->RemoveWatcher(
535 GURL(kAnotherOrigin), 526 GURL(kAnotherOrigin),
536 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 527 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
537 true /* recursive */, 528 true /* recursive */,
538 base::Bind(&LogStatus, base::Unretained(&log))); 529 base::Bind(&LogStatus, base::Unretained(&log)));
539 base::RunLoop().RunUntilIdle(); 530 base::RunLoop().RunUntilIdle();
540 531
541 ASSERT_EQ(1u, log.size()); 532 ASSERT_EQ(1u, log.size());
542 EXPECT_EQ(base::File::FILE_OK, log[0]); 533 EXPECT_EQ(base::File::FILE_OK, log[0]);
543 EXPECT_EQ(3, observer.list_changed_counter()); 534 EXPECT_EQ(3, observer.list_changed_counter());
544 EXPECT_EQ(0, observer.tag_updated_counter()); 535 EXPECT_EQ(0, observer.tag_updated_counter());
545 536
546 ObservedEntries* const observed_entries = 537 Watchers* const watchers = provided_file_system_->GetWatchers();
547 provided_file_system_->GetObservedEntries(); 538 ASSERT_TRUE(watchers);
548 ASSERT_TRUE(observed_entries); 539 EXPECT_EQ(1u, watchers->size());
549 EXPECT_EQ(1u, observed_entries->size()); 540 const auto& watcher_it = watchers->find(
550 const auto& observed_entry_it = observed_entries->find( 541 WatcherKey(base::FilePath(FILE_PATH_LITERAL(kDirectoryPath)),
551 ObservedEntryKey(base::FilePath(FILE_PATH_LITERAL(kDirectoryPath)), 542 false /* recursive */));
552 false /* recursive */)); 543 ASSERT_NE(watchers->end(), watcher_it);
553 ASSERT_NE(observed_entries->end(), observed_entry_it);
554 544
555 EXPECT_EQ(1u, observed_entry_it->second.subscribers.size()); 545 EXPECT_EQ(1u, watcher_it->second.subscribers.size());
556 const auto& subscriber_it = 546 const auto& subscriber_it =
557 observed_entry_it->second.subscribers.find(GURL(kOrigin)); 547 watcher_it->second.subscribers.find(GURL(kOrigin));
558 ASSERT_NE(observed_entry_it->second.subscribers.end(), subscriber_it); 548 ASSERT_NE(watcher_it->second.subscribers.end(), subscriber_it);
559 EXPECT_EQ(kOrigin, subscriber_it->first.spec()); 549 EXPECT_EQ(kOrigin, subscriber_it->first.spec());
560 EXPECT_EQ(kOrigin, subscriber_it->second.origin.spec()); 550 EXPECT_EQ(kOrigin, subscriber_it->second.origin.spec());
561 EXPECT_FALSE(subscriber_it->second.persistent); 551 EXPECT_FALSE(subscriber_it->second.persistent);
562 } 552 }
563 553
564 provided_file_system_->RemoveObserver(&observer); 554 provided_file_system_->RemoveObserver(&observer);
565 } 555 }
566 556
567 TEST_F(FileSystemProviderProvidedFileSystemTest, UnobserveEntry) { 557 TEST_F(FileSystemProviderProvidedFileSystemTest, RemoveWatcher) {
568 Observer observer; 558 Observer observer;
569 provided_file_system_->AddObserver(&observer); 559 provided_file_system_->AddObserver(&observer);
570 560
571 { 561 {
572 // First, confirm that unobserving an entry which is not observed, results 562 // First, confirm that removing a watcher which does not exist results in an
573 // in an error. 563 // error.
574 Log log; 564 Log log;
575 provided_file_system_->UnobserveEntry( 565 provided_file_system_->RemoveWatcher(
576 GURL(kOrigin), 566 GURL(kOrigin),
577 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 567 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
578 false /* recursive */, 568 false /* recursive */,
579 base::Bind(&LogStatus, base::Unretained(&log))); 569 base::Bind(&LogStatus, base::Unretained(&log)));
580 base::RunLoop().RunUntilIdle(); 570 base::RunLoop().RunUntilIdle();
581 571
582 ASSERT_EQ(1u, log.size()); 572 ASSERT_EQ(1u, log.size());
583 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, log[0]); 573 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, log[0]);
584 EXPECT_EQ(0, observer.list_changed_counter()); 574 EXPECT_EQ(0, observer.list_changed_counter());
585 EXPECT_EQ(0, observer.tag_updated_counter()); 575 EXPECT_EQ(0, observer.tag_updated_counter());
586 } 576 }
587 577
588 { 578 {
589 // Observe a directory not recursively. 579 // Watch a directory not recursively.
590 Log log; 580 Log log;
591 provided_file_system_->ObserveDirectory( 581 provided_file_system_->AddWatcher(
592 GURL(kOrigin), 582 GURL(kOrigin),
593 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 583 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
594 false /* recursive */, 584 false /* recursive */,
595 true /* persistent */, 585 true /* persistent */,
596 base::Bind(&LogStatus, base::Unretained(&log))); 586 base::Bind(&LogStatus, base::Unretained(&log)));
597 base::RunLoop().RunUntilIdle(); 587 base::RunLoop().RunUntilIdle();
598 588
599 ASSERT_EQ(1u, log.size()); 589 ASSERT_EQ(1u, log.size());
600 EXPECT_EQ(base::File::FILE_OK, log[0]); 590 EXPECT_EQ(base::File::FILE_OK, log[0]);
601 EXPECT_EQ(1, observer.list_changed_counter()); 591 EXPECT_EQ(1, observer.list_changed_counter());
602 EXPECT_EQ(0, observer.tag_updated_counter()); 592 EXPECT_EQ(0, observer.tag_updated_counter());
603 593
604 ObservedEntries* const observed_entries = 594 Watchers* const watchers = provided_file_system_->GetWatchers();
605 provided_file_system_->GetObservedEntries(); 595 EXPECT_EQ(1u, watchers->size());
606 EXPECT_EQ(1u, observed_entries->size());
607 } 596 }
608 597
609 { 598 {
610 // Unobserve it gracefully. 599 // Remove a watcher gracefully.
611 Log log; 600 Log log;
612 provided_file_system_->UnobserveEntry( 601 provided_file_system_->RemoveWatcher(
613 GURL(kOrigin), 602 GURL(kOrigin),
614 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 603 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
615 false /* recursive */, 604 false /* recursive */,
616 base::Bind(&LogStatus, base::Unretained(&log))); 605 base::Bind(&LogStatus, base::Unretained(&log)));
617 base::RunLoop().RunUntilIdle(); 606 base::RunLoop().RunUntilIdle();
618 607
619 ASSERT_EQ(1u, log.size()); 608 ASSERT_EQ(1u, log.size());
620 EXPECT_EQ(base::File::FILE_OK, log[0]); 609 EXPECT_EQ(base::File::FILE_OK, log[0]);
621 EXPECT_EQ(2, observer.list_changed_counter()); 610 EXPECT_EQ(2, observer.list_changed_counter());
622 EXPECT_EQ(0, observer.tag_updated_counter()); 611 EXPECT_EQ(0, observer.tag_updated_counter());
623 612
624 ObservedEntries* const observed_entries = 613 Watchers* const watchers = provided_file_system_->GetWatchers();
625 provided_file_system_->GetObservedEntries(); 614 EXPECT_EQ(0u, watchers->size());
626 EXPECT_EQ(0u, observed_entries->size());
627 } 615 }
628 616
629 { 617 {
630 // Confirm that it's possible to observe it again. 618 // Confirm that it's possible to watch it again.
631 Log log; 619 Log log;
632 provided_file_system_->ObserveDirectory( 620 provided_file_system_->AddWatcher(
633 GURL(kOrigin), 621 GURL(kOrigin),
634 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 622 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
635 false /* recursive */, 623 false /* recursive */,
636 true /* persistent */, 624 true /* persistent */,
637 base::Bind(&LogStatus, base::Unretained(&log))); 625 base::Bind(&LogStatus, base::Unretained(&log)));
638 base::RunLoop().RunUntilIdle(); 626 base::RunLoop().RunUntilIdle();
639 627
640 ASSERT_EQ(1u, log.size()); 628 ASSERT_EQ(1u, log.size());
641 EXPECT_EQ(base::File::FILE_OK, log[0]); 629 EXPECT_EQ(base::File::FILE_OK, log[0]);
642 EXPECT_EQ(3, observer.list_changed_counter()); 630 EXPECT_EQ(3, observer.list_changed_counter());
643 EXPECT_EQ(0, observer.tag_updated_counter()); 631 EXPECT_EQ(0, observer.tag_updated_counter());
644 632
645 ObservedEntries* const observed_entries = 633 Watchers* const watchers = provided_file_system_->GetWatchers();
646 provided_file_system_->GetObservedEntries(); 634 EXPECT_EQ(1u, watchers->size());
647 EXPECT_EQ(1u, observed_entries->size());
648 } 635 }
649 636
650 { 637 {
651 // Finally, unobserve it, but with an error from extension. That should 638 // Finally, remove it, but with an error from extension. That should result
652 // result in a removed observer, anyway. The error code should not be 639 // in a removed watcher, anyway. The error code should not be passed.
653 // passed.
654 event_router_->set_reply_result(base::File::FILE_ERROR_FAILED); 640 event_router_->set_reply_result(base::File::FILE_ERROR_FAILED);
655 641
656 Log log; 642 Log log;
657 provided_file_system_->UnobserveEntry( 643 provided_file_system_->RemoveWatcher(
658 GURL(kOrigin), 644 GURL(kOrigin),
659 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 645 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
660 false /* recursive */, 646 false /* recursive */,
661 base::Bind(&LogStatus, base::Unretained(&log))); 647 base::Bind(&LogStatus, base::Unretained(&log)));
662 base::RunLoop().RunUntilIdle(); 648 base::RunLoop().RunUntilIdle();
663 649
664 ASSERT_EQ(1u, log.size()); 650 ASSERT_EQ(1u, log.size());
665 EXPECT_EQ(base::File::FILE_OK, log[0]); 651 EXPECT_EQ(base::File::FILE_OK, log[0]);
666 EXPECT_EQ(4, observer.list_changed_counter()); 652 EXPECT_EQ(4, observer.list_changed_counter());
667 EXPECT_EQ(0, observer.tag_updated_counter()); 653 EXPECT_EQ(0, observer.tag_updated_counter());
668 654
669 ObservedEntries* const observed_entries = 655 Watchers* const watchers = provided_file_system_->GetWatchers();
670 provided_file_system_->GetObservedEntries(); 656 EXPECT_EQ(0u, watchers->size());
671 EXPECT_EQ(0u, observed_entries->size());
672 } 657 }
673 658
674 provided_file_system_->RemoveObserver(&observer); 659 provided_file_system_->RemoveObserver(&observer);
675 } 660 }
676 661
677 TEST_F(FileSystemProviderProvidedFileSystemTest, Notify) { 662 TEST_F(FileSystemProviderProvidedFileSystemTest, Notify) {
678 Observer observer; 663 Observer observer;
679 provided_file_system_->AddObserver(&observer); 664 provided_file_system_->AddObserver(&observer);
680 665
681 { 666 {
682 // Observe a directory. 667 // Watch a directory.
683 Log log; 668 Log log;
684 provided_file_system_->ObserveDirectory( 669 provided_file_system_->AddWatcher(
685 GURL(kOrigin), 670 GURL(kOrigin),
686 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 671 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
687 false /* recursive */, 672 false /* recursive */,
688 true /* persistent */, 673 true /* persistent */,
689 base::Bind(&LogStatus, base::Unretained(&log))); 674 base::Bind(&LogStatus, base::Unretained(&log)));
690 base::RunLoop().RunUntilIdle(); 675 base::RunLoop().RunUntilIdle();
691 676
692 ASSERT_EQ(1u, log.size()); 677 ASSERT_EQ(1u, log.size());
693 EXPECT_EQ(base::File::FILE_OK, log[0]); 678 EXPECT_EQ(base::File::FILE_OK, log[0]);
694 EXPECT_EQ(1, observer.list_changed_counter()); 679 EXPECT_EQ(1, observer.list_changed_counter());
695 EXPECT_EQ(0, observer.tag_updated_counter()); 680 EXPECT_EQ(0, observer.tag_updated_counter());
696 681
697 ObservedEntries* const observed_entries = 682 Watchers* const watchers = provided_file_system_->GetWatchers();
698 provided_file_system_->GetObservedEntries(); 683 EXPECT_EQ(1u, watchers->size());
699 EXPECT_EQ(1u, observed_entries->size()); 684 provided_file_system_->GetWatchers();
700 provided_file_system_->GetObservedEntries(); 685 EXPECT_EQ("", watchers->begin()->second.last_tag);
701 EXPECT_EQ("", observed_entries->begin()->second.last_tag);
702 } 686 }
703 687
704 { 688 {
705 // Notify about a change. 689 // Notify about a change.
706 const ProvidedFileSystemObserver::ChangeType change_type = 690 const ProvidedFileSystemObserver::ChangeType change_type =
707 ProvidedFileSystemObserver::CHANGED; 691 ProvidedFileSystemObserver::CHANGED;
708 const std::string tag = "hello-world"; 692 const std::string tag = "hello-world";
709 EXPECT_TRUE(provided_file_system_->Notify( 693 EXPECT_TRUE(provided_file_system_->Notify(
710 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 694 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
711 false /* recursive */, 695 false /* recursive */,
712 change_type, 696 change_type,
713 make_scoped_ptr(new ProvidedFileSystemObserver::Changes), 697 make_scoped_ptr(new ProvidedFileSystemObserver::Changes),
714 tag)); 698 tag));
715 699
716 // Verify the observer event. 700 // Verify the observer event.
717 ASSERT_EQ(1u, observer.change_events().size()); 701 ASSERT_EQ(1u, observer.change_events().size());
718 const Observer::ChangeEvent* const change_event = 702 const Observer::ChangeEvent* const change_event =
719 observer.change_events()[0]; 703 observer.change_events()[0];
720 EXPECT_EQ(change_type, change_event->change_type()); 704 EXPECT_EQ(change_type, change_event->change_type());
721 EXPECT_EQ(0u, change_event->changes().size()); 705 EXPECT_EQ(0u, change_event->changes().size());
722 706
723 // The tag should not be updated in advance, before all observers handle 707 // The tag should not be updated in advance, before all observers handle
724 // the notification. 708 // the notification.
725 ObservedEntries* const observed_entries = 709 Watchers* const watchers = provided_file_system_->GetWatchers();
726 provided_file_system_->GetObservedEntries(); 710 EXPECT_EQ(1u, watchers->size());
727 EXPECT_EQ(1u, observed_entries->size()); 711 provided_file_system_->GetWatchers();
728 provided_file_system_->GetObservedEntries(); 712 EXPECT_EQ("", watchers->begin()->second.last_tag);
729 EXPECT_EQ("", observed_entries->begin()->second.last_tag);
730 713
731 // Wait until all observers finish handling the notification. 714 // Wait until all observers finish handling the notification.
732 base::RunLoop().RunUntilIdle(); 715 base::RunLoop().RunUntilIdle();
733 716
734 // Confirm, that the entry is still being observed, and that the tag is 717 // Confirm, that the watcher still exists, and that the tag is updated.
735 // updated. 718 ASSERT_EQ(1u, watchers->size());
736 ASSERT_EQ(1u, observed_entries->size()); 719 EXPECT_EQ(tag, watchers->begin()->second.last_tag);
737 EXPECT_EQ(tag, observed_entries->begin()->second.last_tag);
738 EXPECT_EQ(1, observer.list_changed_counter()); 720 EXPECT_EQ(1, observer.list_changed_counter());
739 EXPECT_EQ(1, observer.tag_updated_counter()); 721 EXPECT_EQ(1, observer.tag_updated_counter());
740 } 722 }
741 723
742 { 724 {
743 // Notify about deleting of the observed entry. 725 // Notify about deleting of the watched entry.
744 const ProvidedFileSystemObserver::ChangeType change_type = 726 const ProvidedFileSystemObserver::ChangeType change_type =
745 ProvidedFileSystemObserver::DELETED; 727 ProvidedFileSystemObserver::DELETED;
746 const ProvidedFileSystemObserver::Changes changes; 728 const ProvidedFileSystemObserver::Changes changes;
747 const std::string tag = "chocolate-disco"; 729 const std::string tag = "chocolate-disco";
748 EXPECT_TRUE(provided_file_system_->Notify( 730 EXPECT_TRUE(provided_file_system_->Notify(
749 base::FilePath::FromUTF8Unsafe(kDirectoryPath), 731 base::FilePath::FromUTF8Unsafe(kDirectoryPath),
750 false /* recursive */, 732 false /* recursive */,
751 change_type, 733 change_type,
752 make_scoped_ptr(new ProvidedFileSystemObserver::Changes), 734 make_scoped_ptr(new ProvidedFileSystemObserver::Changes),
753 tag)); 735 tag));
754 base::RunLoop().RunUntilIdle(); 736 base::RunLoop().RunUntilIdle();
755 737
756 // Verify the observer event. 738 // Verify the observer event.
757 ASSERT_EQ(2u, observer.change_events().size()); 739 ASSERT_EQ(2u, observer.change_events().size());
758 const Observer::ChangeEvent* const change_event = 740 const Observer::ChangeEvent* const change_event =
759 observer.change_events()[1]; 741 observer.change_events()[1];
760 EXPECT_EQ(change_type, change_event->change_type()); 742 EXPECT_EQ(change_type, change_event->change_type());
761 EXPECT_EQ(0u, change_event->changes().size()); 743 EXPECT_EQ(0u, change_event->changes().size());
762 } 744 }
763 745
764 // Confirm, that the entry is not observed anymore. 746 // Confirm, that the watcher is removed.
765 { 747 {
766 ObservedEntries* const observed_entries = 748 Watchers* const watchers = provided_file_system_->GetWatchers();
767 provided_file_system_->GetObservedEntries(); 749 EXPECT_EQ(0u, watchers->size());
768 EXPECT_EQ(0u, observed_entries->size());
769 EXPECT_EQ(2, observer.list_changed_counter()); 750 EXPECT_EQ(2, observer.list_changed_counter());
770 EXPECT_EQ(2, observer.tag_updated_counter()); 751 EXPECT_EQ(2, observer.tag_updated_counter());
771 } 752 }
772 753
773 provided_file_system_->RemoveObserver(&observer); 754 provided_file_system_->RemoveObserver(&observer);
774 } 755 }
775 756
776 } // namespace file_system_provider 757 } // namespace file_system_provider
777 } // namespace chromeos 758 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698