Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/provided_file_system_info .h" | 19 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h" |
| 20 #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" |
| 21 #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" |
| 22 #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" | 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 "storage/browser/fileapi/watcher_manager.h" | |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 31 |
| 31 namespace chromeos { | 32 namespace chromeos { |
| 32 namespace file_system_provider { | 33 namespace file_system_provider { |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 const char kOrigin[] = | 36 const char kOrigin[] = |
| 36 "chrome-extension://abcabcabcabcabcabcabcabcabcabcabcabca/"; | 37 "chrome-extension://abcabcabcabcabcabcabcabcabcabcabcabca/"; |
| 37 const char kAnotherOrigin[] = | 38 const char kAnotherOrigin[] = |
| 38 "chrome-extension://efgefgefgefgefgefgefgefgefgefgefgefge/"; | 39 "chrome-extension://efgefgefgefgefgefgefgefgefgefgefgefge/"; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 ProvidedFileSystemInterface* const file_system_; // Not owned. | 97 ProvidedFileSystemInterface* const file_system_; // Not owned. |
| 97 base::File::Error reply_result_; | 98 base::File::Error reply_result_; |
| 98 DISALLOW_COPY_AND_ASSIGN(FakeEventRouter); | 99 DISALLOW_COPY_AND_ASSIGN(FakeEventRouter); |
| 99 }; | 100 }; |
| 100 | 101 |
| 101 // Observes the tested file system. | 102 // Observes the tested file system. |
| 102 class Observer : public ProvidedFileSystemObserver { | 103 class Observer : public ProvidedFileSystemObserver { |
| 103 public: | 104 public: |
| 104 class ChangeEvent { | 105 class ChangeEvent { |
| 105 public: | 106 public: |
| 106 ChangeEvent(ProvidedFileSystemObserver::ChangeType change_type, | 107 ChangeEvent(storage::WatcherManager::ChangeType change_type, |
| 107 const ProvidedFileSystemObserver::Changes& changes) | 108 const ProvidedFileSystemObserver::Changes& changes) |
| 108 : change_type_(change_type), changes_(changes) {} | 109 : change_type_(change_type), changes_(changes) {} |
| 109 virtual ~ChangeEvent() {} | 110 virtual ~ChangeEvent() {} |
| 110 | 111 |
| 111 ProvidedFileSystemObserver::ChangeType change_type() const { | 112 storage::WatcherManager::ChangeType change_type() const { |
| 112 return change_type_; | 113 return change_type_; |
| 113 } | 114 } |
| 114 const ProvidedFileSystemObserver::Changes& changes() const { | 115 const ProvidedFileSystemObserver::Changes& changes() const { |
| 115 return changes_; | 116 return changes_; |
| 116 } | 117 } |
| 117 | 118 |
| 118 private: | 119 private: |
| 119 const ProvidedFileSystemObserver::ChangeType change_type_; | 120 const storage::WatcherManager::ChangeType change_type_; |
| 120 const ProvidedFileSystemObserver::Changes changes_; | 121 const ProvidedFileSystemObserver::Changes changes_; |
| 121 | 122 |
| 122 DISALLOW_COPY_AND_ASSIGN(ChangeEvent); | 123 DISALLOW_COPY_AND_ASSIGN(ChangeEvent); |
| 123 }; | 124 }; |
| 124 | 125 |
| 125 Observer() : list_changed_counter_(0), tag_updated_counter_(0) {} | 126 Observer() : list_changed_counter_(0), tag_updated_counter_(0) {} |
| 126 | 127 |
| 127 // ProvidedFileSystemInterfaceObserver overrides. | 128 // ProvidedFileSystemInterfaceObserver overrides. |
| 128 virtual void OnWatcherChanged( | 129 virtual void OnWatcherChanged( |
| 129 const ProvidedFileSystemInfo& file_system_info, | 130 const ProvidedFileSystemInfo& file_system_info, |
| 130 const Watcher& watcher, | 131 const Watcher& watcher, |
| 131 ProvidedFileSystemObserver::ChangeType change_type, | 132 storage::WatcherManager::ChangeType change_type, |
| 132 const ProvidedFileSystemObserver::Changes& changes, | 133 const ProvidedFileSystemObserver::Changes& changes, |
| 133 const base::Closure& callback) override { | 134 const base::Closure& callback) override { |
| 134 EXPECT_EQ(kFileSystemId, file_system_info.file_system_id()); | 135 EXPECT_EQ(kFileSystemId, file_system_info.file_system_id()); |
| 135 change_events_.push_back(new ChangeEvent(change_type, changes)); | 136 change_events_.push_back(new ChangeEvent(change_type, changes)); |
| 136 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); | 137 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
| 137 } | 138 } |
| 138 | 139 |
| 139 virtual void OnWatcherTagUpdated( | 140 virtual void OnWatcherTagUpdated( |
| 140 const ProvidedFileSystemInfo& file_system_info, | 141 const ProvidedFileSystemInfo& file_system_info, |
| 141 const Watcher& watcher) override { | 142 const Watcher& watcher) override { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 virtual void ShowUnresponsiveNotification( | 175 virtual void ShowUnresponsiveNotification( |
| 175 int id, | 176 int id, |
| 176 const NotificationCallback& callback) override {} | 177 const NotificationCallback& callback) override {} |
| 177 virtual void HideUnresponsiveNotification(int id) override {} | 178 virtual void HideUnresponsiveNotification(int id) override {} |
| 178 | 179 |
| 179 private: | 180 private: |
| 180 DISALLOW_COPY_AND_ASSIGN(StubNotificationManager); | 181 DISALLOW_COPY_AND_ASSIGN(StubNotificationManager); |
| 181 }; | 182 }; |
| 182 | 183 |
| 183 typedef std::vector<base::File::Error> Log; | 184 typedef std::vector<base::File::Error> Log; |
| 185 typedef std::vector<storage::WatcherManager::ChangeType> NotificationLog; | |
| 184 | 186 |
| 185 // Writes a |result| to the |log| vector. | 187 // Writes a |result| to the |log| vector. |
| 186 void LogStatus(Log* log, base::File::Error result) { | 188 void LogStatus(Log* log, base::File::Error result) { |
| 187 log->push_back(result); | 189 log->push_back(result); |
| 188 } | 190 } |
| 189 | 191 |
| 192 // Writes an |change_type| to the |notification_log| vector. | |
| 193 void LogNotification(NotificationLog* notification_log, | |
| 194 storage::WatcherManager::ChangeType change_type) { | |
| 195 notification_log->push_back(change_type); | |
| 196 } | |
| 197 | |
| 190 } // namespace | 198 } // namespace |
| 191 | 199 |
| 192 class FileSystemProviderProvidedFileSystemTest : public testing::Test { | 200 class FileSystemProviderProvidedFileSystemTest : public testing::Test { |
| 193 protected: | 201 protected: |
| 194 FileSystemProviderProvidedFileSystemTest() {} | 202 FileSystemProviderProvidedFileSystemTest() {} |
| 195 virtual ~FileSystemProviderProvidedFileSystemTest() {} | 203 virtual ~FileSystemProviderProvidedFileSystemTest() {} |
| 196 | 204 |
| 197 virtual void SetUp() override { | 205 virtual void SetUp() override { |
| 198 profile_.reset(new TestingProfile); | 206 profile_.reset(new TestingProfile); |
| 199 const base::FilePath mount_path = | 207 const base::FilePath mount_path = |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 // The callback gets out of scope, so the ref counted auto updater instance | 281 // The callback gets out of scope, so the ref counted auto updater instance |
| 274 // gets deleted. Still, updating shouldn't be invoked, since the callback | 282 // gets deleted. Still, updating shouldn't be invoked, since the callback |
| 275 // wasn't executed. | 283 // wasn't executed. |
| 276 } | 284 } |
| 277 base::RunLoop().RunUntilIdle(); | 285 base::RunLoop().RunUntilIdle(); |
| 278 EXPECT_EQ(0u, log.size()); | 286 EXPECT_EQ(0u, log.size()); |
| 279 } | 287 } |
| 280 | 288 |
| 281 TEST_F(FileSystemProviderProvidedFileSystemTest, AddWatcher_NotFound) { | 289 TEST_F(FileSystemProviderProvidedFileSystemTest, AddWatcher_NotFound) { |
| 282 Log log; | 290 Log log; |
| 291 NotificationLog notification_log; | |
| 283 Observer observer; | 292 Observer observer; |
| 284 | 293 |
| 285 provided_file_system_->AddObserver(&observer); | 294 provided_file_system_->AddObserver(&observer); |
| 286 | 295 |
| 287 // First, set the extension response to an error. | 296 // First, set the extension response to an error. |
| 288 event_router_->set_reply_result(base::File::FILE_ERROR_NOT_FOUND); | 297 event_router_->set_reply_result(base::File::FILE_ERROR_NOT_FOUND); |
| 289 | 298 |
| 290 provided_file_system_->AddWatcher( | 299 provided_file_system_->AddWatcher( |
| 291 GURL(kOrigin), | 300 GURL(kOrigin), |
| 292 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 301 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
| 293 false /* recursive */, | 302 false /* recursive */, |
| 294 false /* persistent */, | 303 false /* persistent */, |
| 295 base::Bind(&LogStatus, base::Unretained(&log))); | 304 base::Bind(&LogStatus, base::Unretained(&log)), |
| 305 base::Bind(&LogNotification, base::Unretained(¬ification_log))); | |
| 296 base::RunLoop().RunUntilIdle(); | 306 base::RunLoop().RunUntilIdle(); |
| 297 | 307 |
| 298 // The directory should not become watched because of an error. | 308 // The directory should not become watched because of an error. |
| 299 ASSERT_EQ(1u, log.size()); | 309 ASSERT_EQ(1u, log.size()); |
| 300 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, log[0]); | 310 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, log[0]); |
| 311 EXPECT_EQ(0u, notification_log.size()); | |
| 301 | 312 |
| 302 Watchers* const watchers = provided_file_system_->GetWatchers(); | 313 Watchers* const watchers = provided_file_system_->GetWatchers(); |
| 303 EXPECT_EQ(0u, watchers->size()); | 314 EXPECT_EQ(0u, watchers->size()); |
| 304 | 315 |
| 305 // The observer should not be called. | 316 // The observer should not be called. |
| 306 EXPECT_EQ(0, observer.list_changed_counter()); | 317 EXPECT_EQ(0, observer.list_changed_counter()); |
| 307 EXPECT_EQ(0, observer.tag_updated_counter()); | 318 EXPECT_EQ(0, observer.tag_updated_counter()); |
| 308 | 319 |
| 309 provided_file_system_->RemoveObserver(&observer); | 320 provided_file_system_->RemoveObserver(&observer); |
| 310 } | 321 } |
| 311 | 322 |
| 312 TEST_F(FileSystemProviderProvidedFileSystemTest, AddWatcher) { | 323 TEST_F(FileSystemProviderProvidedFileSystemTest, AddWatcher) { |
| 313 Log log; | 324 Log log; |
| 314 Observer observer; | 325 Observer observer; |
| 315 | 326 |
| 316 provided_file_system_->AddObserver(&observer); | 327 provided_file_system_->AddObserver(&observer); |
| 317 | 328 |
| 318 provided_file_system_->AddWatcher( | 329 provided_file_system_->AddWatcher( |
| 319 GURL(kOrigin), | 330 GURL(kOrigin), |
| 320 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 331 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
| 321 false /* recursive */, | 332 false /* recursive */, |
| 322 true /* persistent */, | 333 true /* persistent */, |
| 323 base::Bind(&LogStatus, base::Unretained(&log))); | 334 base::Bind(&LogStatus, base::Unretained(&log)), |
| 335 storage::WatcherManager::NotificationCallback()); | |
| 324 base::RunLoop().RunUntilIdle(); | 336 base::RunLoop().RunUntilIdle(); |
| 325 | 337 |
| 326 ASSERT_EQ(1u, log.size()); | 338 ASSERT_EQ(1u, log.size()); |
| 327 EXPECT_EQ(base::File::FILE_OK, log[0]); | 339 EXPECT_EQ(base::File::FILE_OK, log[0]); |
| 328 EXPECT_EQ(1, observer.list_changed_counter()); | 340 EXPECT_EQ(1, observer.list_changed_counter()); |
| 329 EXPECT_EQ(0, observer.tag_updated_counter()); | 341 EXPECT_EQ(0, observer.tag_updated_counter()); |
| 330 | 342 |
| 331 Watchers* const watchers = provided_file_system_->GetWatchers(); | 343 Watchers* const watchers = provided_file_system_->GetWatchers(); |
| 332 ASSERT_EQ(1u, watchers->size()); | 344 ASSERT_EQ(1u, watchers->size()); |
| 333 const Watcher& watcher = watchers->begin()->second; | 345 const Watcher& watcher = watchers->begin()->second; |
| 334 EXPECT_EQ(FILE_PATH_LITERAL(kDirectoryPath), watcher.entry_path.value()); | 346 EXPECT_EQ(FILE_PATH_LITERAL(kDirectoryPath), watcher.entry_path.value()); |
| 335 EXPECT_FALSE(watcher.recursive); | 347 EXPECT_FALSE(watcher.recursive); |
| 336 EXPECT_EQ("", watcher.last_tag); | 348 EXPECT_EQ("", watcher.last_tag); |
| 337 | 349 |
| 338 provided_file_system_->RemoveObserver(&observer); | 350 provided_file_system_->RemoveObserver(&observer); |
| 339 } | 351 } |
| 340 | 352 |
| 341 TEST_F(FileSystemProviderProvidedFileSystemTest, AddWatcher_PersistentIllegal) { | 353 TEST_F(FileSystemProviderProvidedFileSystemTest, AddWatcher_PersistentIllegal) { |
| 354 { | |
| 355 // Adding a persistent watcher with a notification callback is not allowed, | |
| 356 // as it's basically impossible to restore the callback after a shutdown. | |
| 342 Log log; | 357 Log log; |
|
fukino
2014/10/30 03:42:32
Incorrect indent in this block.
mtomasz
2014/10/30 09:50:32
Done.
| |
| 358 NotificationLog notification_log; | |
| 359 | |
| 343 Observer observer; | 360 Observer observer; |
| 361 provided_file_system_->AddObserver(&observer); | |
| 344 | 362 |
| 345 // Create a provided file system interface, which does not support a notify | 363 provided_file_system_->AddWatcher( |
| 346 // tag, though. | |
| 347 const base::FilePath mount_path = | |
| 348 util::GetMountPath(profile_.get(), kExtensionId, kFileSystemId); | |
| 349 MountOptions mount_options; | |
| 350 mount_options.file_system_id = kFileSystemId; | |
| 351 mount_options.display_name = kDisplayName; | |
| 352 mount_options.supports_notify_tag = false; | |
| 353 ProvidedFileSystemInfo file_system_info( | |
| 354 kExtensionId, mount_options, mount_path); | |
| 355 ProvidedFileSystem simple_provided_file_system(profile_.get(), | |
| 356 file_system_info); | |
| 357 simple_provided_file_system.SetEventRouterForTesting(event_router_.get()); | |
| 358 simple_provided_file_system.SetNotificationManagerForTesting( | |
| 359 make_scoped_ptr(new StubNotificationManager)); | |
| 360 | |
| 361 simple_provided_file_system.AddObserver(&observer); | |
| 362 | |
| 363 simple_provided_file_system.AddWatcher( | |
| 364 GURL(kOrigin), | 364 GURL(kOrigin), |
| 365 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 365 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
| 366 false /* recursive */, | 366 false /* recursive */, |
| 367 true /* persistent */, | 367 true /* persistent */, |
| 368 base::Bind(&LogStatus, base::Unretained(&log))); | 368 base::Bind(&LogStatus, base::Unretained(&log)), |
| 369 base::Bind(&LogNotification, base::Unretained(¬ification_log))); | |
| 369 base::RunLoop().RunUntilIdle(); | 370 base::RunLoop().RunUntilIdle(); |
| 370 | 371 |
| 371 ASSERT_EQ(1u, log.size()); | 372 ASSERT_EQ(1u, log.size()); |
| 372 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, log[0]); | 373 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, log[0]); |
| 373 EXPECT_EQ(0, observer.list_changed_counter()); | 374 EXPECT_EQ(0, observer.list_changed_counter()); |
| 374 EXPECT_EQ(0, observer.tag_updated_counter()); | 375 EXPECT_EQ(0, observer.tag_updated_counter()); |
| 375 | 376 |
| 376 simple_provided_file_system.RemoveObserver(&observer); | 377 provided_file_system_->RemoveObserver(&observer); |
| 378 } | |
| 379 | |
| 380 { | |
| 381 // Adding a persistent watcher is not allowed if the file system doesn't | |
| 382 // support the notify tag. It's because the notify tag is essential to be | |
| 383 // able to recreate notification during shutdown. | |
| 384 Log log; | |
| 385 Observer observer; | |
| 386 | |
| 387 // Create a provided file system interface, which does not support a notify | |
| 388 // tag, though. | |
| 389 const base::FilePath mount_path = | |
| 390 util::GetMountPath(profile_.get(), kExtensionId, kFileSystemId); | |
| 391 MountOptions mount_options; | |
| 392 mount_options.file_system_id = kFileSystemId; | |
| 393 mount_options.display_name = kDisplayName; | |
| 394 mount_options.supports_notify_tag = false; | |
| 395 ProvidedFileSystemInfo file_system_info( | |
| 396 kExtensionId, mount_options, mount_path); | |
| 397 ProvidedFileSystem simple_provided_file_system(profile_.get(), | |
| 398 file_system_info); | |
| 399 simple_provided_file_system.SetEventRouterForTesting(event_router_.get()); | |
| 400 simple_provided_file_system.SetNotificationManagerForTesting( | |
| 401 make_scoped_ptr(new StubNotificationManager)); | |
| 402 | |
| 403 simple_provided_file_system.AddObserver(&observer); | |
| 404 | |
| 405 simple_provided_file_system.AddWatcher( | |
| 406 GURL(kOrigin), | |
| 407 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | |
| 408 false /* recursive */, | |
| 409 true /* persistent */, | |
| 410 base::Bind(&LogStatus, base::Unretained(&log)), | |
| 411 storage::WatcherManager::NotificationCallback()); | |
| 412 base::RunLoop().RunUntilIdle(); | |
| 413 | |
| 414 ASSERT_EQ(1u, log.size()); | |
| 415 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, log[0]); | |
| 416 EXPECT_EQ(0, observer.list_changed_counter()); | |
| 417 EXPECT_EQ(0, observer.tag_updated_counter()); | |
| 418 | |
| 419 simple_provided_file_system.RemoveObserver(&observer); | |
| 420 } | |
| 377 } | 421 } |
| 378 | 422 |
| 379 TEST_F(FileSystemProviderProvidedFileSystemTest, AddWatcher_Exists) { | 423 TEST_F(FileSystemProviderProvidedFileSystemTest, AddWatcher_Exists) { |
| 380 Observer observer; | 424 Observer observer; |
| 381 provided_file_system_->AddObserver(&observer); | 425 provided_file_system_->AddObserver(&observer); |
| 382 | 426 |
| 383 { | 427 { |
| 384 // First watch a directory not recursively. | 428 // First watch a directory not recursively. |
| 385 Log log; | 429 Log log; |
| 386 provided_file_system_->AddWatcher( | 430 provided_file_system_->AddWatcher( |
| 387 GURL(kOrigin), | 431 GURL(kOrigin), |
| 388 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 432 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
| 389 false /* recursive */, | 433 false /* recursive */, |
| 390 true /* persistent */, | 434 true /* persistent */, |
| 391 base::Bind(&LogStatus, base::Unretained(&log))); | 435 base::Bind(&LogStatus, base::Unretained(&log)), |
| 436 storage::WatcherManager::NotificationCallback()); | |
| 392 base::RunLoop().RunUntilIdle(); | 437 base::RunLoop().RunUntilIdle(); |
| 393 | 438 |
| 394 ASSERT_EQ(1u, log.size()); | 439 ASSERT_EQ(1u, log.size()); |
| 395 EXPECT_EQ(base::File::FILE_OK, log[0]); | 440 EXPECT_EQ(base::File::FILE_OK, log[0]); |
| 396 EXPECT_EQ(1, observer.list_changed_counter()); | 441 EXPECT_EQ(1, observer.list_changed_counter()); |
| 397 EXPECT_EQ(0, observer.tag_updated_counter()); | 442 EXPECT_EQ(0, observer.tag_updated_counter()); |
| 398 | 443 |
| 399 Watchers* const watchers = provided_file_system_->GetWatchers(); | 444 Watchers* const watchers = provided_file_system_->GetWatchers(); |
| 400 ASSERT_TRUE(watchers); | 445 ASSERT_TRUE(watchers); |
| 401 ASSERT_EQ(1u, watchers->size()); | 446 ASSERT_EQ(1u, watchers->size()); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 413 } | 458 } |
| 414 | 459 |
| 415 { | 460 { |
| 416 // Create another non-recursive observer. That should fail. | 461 // Create another non-recursive observer. That should fail. |
| 417 Log log; | 462 Log log; |
| 418 provided_file_system_->AddWatcher( | 463 provided_file_system_->AddWatcher( |
| 419 GURL(kOrigin), | 464 GURL(kOrigin), |
| 420 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 465 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
| 421 false /* recursive */, | 466 false /* recursive */, |
| 422 true /* persistent */, | 467 true /* persistent */, |
| 423 base::Bind(&LogStatus, base::Unretained(&log))); | 468 base::Bind(&LogStatus, base::Unretained(&log)), |
| 469 storage::WatcherManager::NotificationCallback()); | |
| 424 base::RunLoop().RunUntilIdle(); | 470 base::RunLoop().RunUntilIdle(); |
| 425 | 471 |
| 426 ASSERT_EQ(1u, log.size()); | 472 ASSERT_EQ(1u, log.size()); |
| 427 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, log[0]); | 473 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, log[0]); |
| 428 EXPECT_EQ(1, observer.list_changed_counter()); // No changes on the list. | 474 EXPECT_EQ(1, observer.list_changed_counter()); // No changes on the list. |
| 429 EXPECT_EQ(0, observer.tag_updated_counter()); | 475 EXPECT_EQ(0, observer.tag_updated_counter()); |
| 430 } | 476 } |
| 431 | 477 |
| 432 { | 478 { |
| 433 // Lastly, create another recursive observer. That should succeed. | 479 // Lastly, create another recursive observer. That should succeed. |
| 434 Log log; | 480 Log log; |
| 435 provided_file_system_->AddWatcher( | 481 provided_file_system_->AddWatcher( |
| 436 GURL(kOrigin), | 482 GURL(kOrigin), |
| 437 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 483 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
| 438 true /* recursive */, | 484 true /* recursive */, |
| 439 true /* persistent */, | 485 true /* persistent */, |
| 440 base::Bind(&LogStatus, base::Unretained(&log))); | 486 base::Bind(&LogStatus, base::Unretained(&log)), |
| 487 storage::WatcherManager::NotificationCallback()); | |
| 441 base::RunLoop().RunUntilIdle(); | 488 base::RunLoop().RunUntilIdle(); |
| 442 | 489 |
| 443 ASSERT_EQ(1u, log.size()); | 490 ASSERT_EQ(1u, log.size()); |
| 444 EXPECT_EQ(base::File::FILE_OK, log[0]); | 491 EXPECT_EQ(base::File::FILE_OK, log[0]); |
| 445 EXPECT_EQ(2, observer.list_changed_counter()); | 492 EXPECT_EQ(2, observer.list_changed_counter()); |
| 446 EXPECT_EQ(0, observer.tag_updated_counter()); | 493 EXPECT_EQ(0, observer.tag_updated_counter()); |
| 447 } | 494 } |
| 448 | 495 |
| 449 provided_file_system_->RemoveObserver(&observer); | 496 provided_file_system_->RemoveObserver(&observer); |
| 450 } | 497 } |
| 451 | 498 |
| 452 TEST_F(FileSystemProviderProvidedFileSystemTest, AddWatcher_MultipleOrigins) { | 499 TEST_F(FileSystemProviderProvidedFileSystemTest, AddWatcher_MultipleOrigins) { |
| 453 Observer observer; | 500 Observer observer; |
| 454 provided_file_system_->AddObserver(&observer); | 501 provided_file_system_->AddObserver(&observer); |
| 455 | 502 |
| 456 { | 503 { |
| 457 // First watch a directory not recursively. | 504 // First watch a directory not recursively. |
| 458 Log log; | 505 Log log; |
| 506 NotificationLog notification_log; | |
| 507 | |
| 459 provided_file_system_->AddWatcher( | 508 provided_file_system_->AddWatcher( |
| 460 GURL(kOrigin), | 509 GURL(kOrigin), |
| 461 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 510 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
| 462 false /* recursive */, | 511 false /* recursive */, |
| 463 false /* persistent */, | 512 false /* persistent */, |
| 464 base::Bind(&LogStatus, base::Unretained(&log))); | 513 base::Bind(&LogStatus, base::Unretained(&log)), |
| 514 base::Bind(&LogNotification, base::Unretained(¬ification_log))); | |
| 465 base::RunLoop().RunUntilIdle(); | 515 base::RunLoop().RunUntilIdle(); |
| 466 | 516 |
| 467 ASSERT_EQ(1u, log.size()); | 517 ASSERT_EQ(1u, log.size()); |
| 468 EXPECT_EQ(base::File::FILE_OK, log[0]); | 518 EXPECT_EQ(base::File::FILE_OK, log[0]); |
| 469 EXPECT_EQ(1, observer.list_changed_counter()); | 519 EXPECT_EQ(1, observer.list_changed_counter()); |
| 470 EXPECT_EQ(0, observer.tag_updated_counter()); | 520 EXPECT_EQ(0, observer.tag_updated_counter()); |
| 521 EXPECT_EQ(0u, notification_log.size()); | |
| 471 | 522 |
| 472 Watchers* const watchers = provided_file_system_->GetWatchers(); | 523 Watchers* const watchers = provided_file_system_->GetWatchers(); |
| 473 ASSERT_TRUE(watchers); | 524 ASSERT_TRUE(watchers); |
| 474 ASSERT_EQ(1u, watchers->size()); | 525 ASSERT_EQ(1u, watchers->size()); |
| 475 const auto& watcher_it = watchers->find( | 526 const auto& watcher_it = watchers->find( |
| 476 WatcherKey(base::FilePath(FILE_PATH_LITERAL(kDirectoryPath)), | 527 WatcherKey(base::FilePath(FILE_PATH_LITERAL(kDirectoryPath)), |
| 477 false /* recursive */)); | 528 false /* recursive */)); |
| 478 ASSERT_NE(watchers->end(), watcher_it); | 529 ASSERT_NE(watchers->end(), watcher_it); |
| 479 | 530 |
| 480 EXPECT_EQ(1u, watcher_it->second.subscribers.size()); | 531 EXPECT_EQ(1u, watcher_it->second.subscribers.size()); |
| 481 const auto& subscriber_it = | 532 const auto& subscriber_it = |
| 482 watcher_it->second.subscribers.find(GURL(kOrigin)); | 533 watcher_it->second.subscribers.find(GURL(kOrigin)); |
| 483 ASSERT_NE(watcher_it->second.subscribers.end(), subscriber_it); | 534 ASSERT_NE(watcher_it->second.subscribers.end(), subscriber_it); |
| 484 EXPECT_EQ(kOrigin, subscriber_it->first.spec()); | 535 EXPECT_EQ(kOrigin, subscriber_it->first.spec()); |
| 485 EXPECT_EQ(kOrigin, subscriber_it->second.origin.spec()); | 536 EXPECT_EQ(kOrigin, subscriber_it->second.origin.spec()); |
| 486 EXPECT_FALSE(subscriber_it->second.persistent); | 537 EXPECT_FALSE(subscriber_it->second.persistent); |
| 487 } | 538 } |
| 488 | 539 |
| 489 { | 540 { |
| 490 // Create another watcher, but recursive and with a different origin. | 541 // Create another watcher, but recursive and with a different origin. |
| 491 Log log; | 542 Log log; |
| 543 NotificationLog notification_log; | |
| 544 | |
| 492 provided_file_system_->AddWatcher( | 545 provided_file_system_->AddWatcher( |
| 493 GURL(kAnotherOrigin), | 546 GURL(kAnotherOrigin), |
| 494 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 547 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
| 495 true /* recursive */, | 548 true /* recursive */, |
| 496 true /* persistent */, | 549 false /* persistent */, |
| 497 base::Bind(&LogStatus, base::Unretained(&log))); | 550 base::Bind(&LogStatus, base::Unretained(&log)), |
| 551 base::Bind(&LogNotification, base::Unretained(¬ification_log))); | |
| 498 base::RunLoop().RunUntilIdle(); | 552 base::RunLoop().RunUntilIdle(); |
| 499 | 553 |
| 500 ASSERT_EQ(1u, log.size()); | 554 ASSERT_EQ(1u, log.size()); |
| 501 EXPECT_EQ(base::File::FILE_OK, log[0]); | 555 EXPECT_EQ(base::File::FILE_OK, log[0]); |
| 502 EXPECT_EQ(2, observer.list_changed_counter()); | 556 EXPECT_EQ(2, observer.list_changed_counter()); |
| 503 EXPECT_EQ(0, observer.tag_updated_counter()); | 557 EXPECT_EQ(0, observer.tag_updated_counter()); |
| 558 EXPECT_EQ(0u, notification_log.size()); | |
| 504 | 559 |
| 505 Watchers* const watchers = provided_file_system_->GetWatchers(); | 560 Watchers* const watchers = provided_file_system_->GetWatchers(); |
| 506 ASSERT_TRUE(watchers); | 561 ASSERT_TRUE(watchers); |
| 507 ASSERT_EQ(2u, watchers->size()); | 562 ASSERT_EQ(2u, watchers->size()); |
| 508 const auto& watcher_it = watchers->find( | 563 const auto& watcher_it = watchers->find( |
| 509 WatcherKey(base::FilePath(FILE_PATH_LITERAL(kDirectoryPath)), | 564 WatcherKey(base::FilePath(FILE_PATH_LITERAL(kDirectoryPath)), |
| 510 false /* recursive */)); | 565 false /* recursive */)); |
| 511 ASSERT_NE(watchers->end(), watcher_it); | 566 ASSERT_NE(watchers->end(), watcher_it); |
| 512 | 567 |
| 513 EXPECT_EQ(1u, watcher_it->second.subscribers.size()); | 568 EXPECT_EQ(1u, watcher_it->second.subscribers.size()); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 | 626 |
| 572 ASSERT_EQ(1u, log.size()); | 627 ASSERT_EQ(1u, log.size()); |
| 573 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, log[0]); | 628 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, log[0]); |
| 574 EXPECT_EQ(0, observer.list_changed_counter()); | 629 EXPECT_EQ(0, observer.list_changed_counter()); |
| 575 EXPECT_EQ(0, observer.tag_updated_counter()); | 630 EXPECT_EQ(0, observer.tag_updated_counter()); |
| 576 } | 631 } |
| 577 | 632 |
| 578 { | 633 { |
| 579 // Watch a directory not recursively. | 634 // Watch a directory not recursively. |
| 580 Log log; | 635 Log log; |
| 636 NotificationLog notification_log; | |
| 637 | |
| 581 provided_file_system_->AddWatcher( | 638 provided_file_system_->AddWatcher( |
| 582 GURL(kOrigin), | 639 GURL(kOrigin), |
| 583 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 640 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
| 584 false /* recursive */, | 641 false /* recursive */, |
| 585 true /* persistent */, | 642 false /* persistent */, |
| 586 base::Bind(&LogStatus, base::Unretained(&log))); | 643 base::Bind(&LogStatus, base::Unretained(&log)), |
| 644 base::Bind(&LogNotification, base::Unretained(¬ification_log))); | |
| 587 base::RunLoop().RunUntilIdle(); | 645 base::RunLoop().RunUntilIdle(); |
| 588 | 646 |
| 589 ASSERT_EQ(1u, log.size()); | 647 ASSERT_EQ(1u, log.size()); |
| 590 EXPECT_EQ(base::File::FILE_OK, log[0]); | 648 EXPECT_EQ(base::File::FILE_OK, log[0]); |
| 591 EXPECT_EQ(1, observer.list_changed_counter()); | 649 EXPECT_EQ(1, observer.list_changed_counter()); |
| 592 EXPECT_EQ(0, observer.tag_updated_counter()); | 650 EXPECT_EQ(0, observer.tag_updated_counter()); |
| 651 EXPECT_EQ(0u, notification_log.size()); | |
| 593 | 652 |
| 594 Watchers* const watchers = provided_file_system_->GetWatchers(); | 653 Watchers* const watchers = provided_file_system_->GetWatchers(); |
| 595 EXPECT_EQ(1u, watchers->size()); | 654 EXPECT_EQ(1u, watchers->size()); |
| 596 } | 655 } |
| 597 | 656 |
| 598 { | 657 { |
| 599 // Remove a watcher gracefully. | 658 // Remove a watcher gracefully. |
| 600 Log log; | 659 Log log; |
| 601 provided_file_system_->RemoveWatcher( | 660 provided_file_system_->RemoveWatcher( |
| 602 GURL(kOrigin), | 661 GURL(kOrigin), |
| 603 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 662 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
| 604 false /* recursive */, | 663 false /* recursive */, |
| 605 base::Bind(&LogStatus, base::Unretained(&log))); | 664 base::Bind(&LogStatus, base::Unretained(&log))); |
| 606 base::RunLoop().RunUntilIdle(); | 665 base::RunLoop().RunUntilIdle(); |
| 607 | 666 |
| 608 ASSERT_EQ(1u, log.size()); | 667 ASSERT_EQ(1u, log.size()); |
| 609 EXPECT_EQ(base::File::FILE_OK, log[0]); | 668 EXPECT_EQ(base::File::FILE_OK, log[0]); |
| 610 EXPECT_EQ(2, observer.list_changed_counter()); | 669 EXPECT_EQ(2, observer.list_changed_counter()); |
| 611 EXPECT_EQ(0, observer.tag_updated_counter()); | 670 EXPECT_EQ(0, observer.tag_updated_counter()); |
| 612 | 671 |
| 613 Watchers* const watchers = provided_file_system_->GetWatchers(); | 672 Watchers* const watchers = provided_file_system_->GetWatchers(); |
| 614 EXPECT_EQ(0u, watchers->size()); | 673 EXPECT_EQ(0u, watchers->size()); |
| 615 } | 674 } |
| 616 | 675 |
| 617 { | 676 { |
| 618 // Confirm that it's possible to watch it again. | 677 // Confirm that it's possible to watch it again. |
| 619 Log log; | 678 Log log; |
| 679 NotificationLog notification_log; | |
| 680 | |
| 620 provided_file_system_->AddWatcher( | 681 provided_file_system_->AddWatcher( |
| 621 GURL(kOrigin), | 682 GURL(kOrigin), |
| 622 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 683 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
| 623 false /* recursive */, | 684 false /* recursive */, |
| 624 true /* persistent */, | 685 false /* persistent */, |
| 625 base::Bind(&LogStatus, base::Unretained(&log))); | 686 base::Bind(&LogStatus, base::Unretained(&log)), |
| 687 base::Bind(&LogNotification, base::Unretained(¬ification_log))); | |
| 626 base::RunLoop().RunUntilIdle(); | 688 base::RunLoop().RunUntilIdle(); |
| 627 | 689 |
| 628 ASSERT_EQ(1u, log.size()); | 690 ASSERT_EQ(1u, log.size()); |
| 629 EXPECT_EQ(base::File::FILE_OK, log[0]); | 691 EXPECT_EQ(base::File::FILE_OK, log[0]); |
| 630 EXPECT_EQ(3, observer.list_changed_counter()); | 692 EXPECT_EQ(3, observer.list_changed_counter()); |
| 631 EXPECT_EQ(0, observer.tag_updated_counter()); | 693 EXPECT_EQ(0, observer.tag_updated_counter()); |
| 694 EXPECT_EQ(0u, notification_log.size()); | |
| 632 | 695 |
| 633 Watchers* const watchers = provided_file_system_->GetWatchers(); | 696 Watchers* const watchers = provided_file_system_->GetWatchers(); |
| 634 EXPECT_EQ(1u, watchers->size()); | 697 EXPECT_EQ(1u, watchers->size()); |
| 635 } | 698 } |
| 636 | 699 |
| 637 { | 700 { |
| 638 // Finally, remove it, but with an error from extension. That should result | 701 // Finally, remove it, but with an error from extension. That should result |
| 639 // in a removed watcher, anyway. The error code should not be passed. | 702 // in a removed watcher, anyway. The error code should not be passed. |
| 640 event_router_->set_reply_result(base::File::FILE_ERROR_FAILED); | 703 event_router_->set_reply_result(base::File::FILE_ERROR_FAILED); |
| 641 | 704 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 655 Watchers* const watchers = provided_file_system_->GetWatchers(); | 718 Watchers* const watchers = provided_file_system_->GetWatchers(); |
| 656 EXPECT_EQ(0u, watchers->size()); | 719 EXPECT_EQ(0u, watchers->size()); |
| 657 } | 720 } |
| 658 | 721 |
| 659 provided_file_system_->RemoveObserver(&observer); | 722 provided_file_system_->RemoveObserver(&observer); |
| 660 } | 723 } |
| 661 | 724 |
| 662 TEST_F(FileSystemProviderProvidedFileSystemTest, Notify) { | 725 TEST_F(FileSystemProviderProvidedFileSystemTest, Notify) { |
| 663 Observer observer; | 726 Observer observer; |
| 664 provided_file_system_->AddObserver(&observer); | 727 provided_file_system_->AddObserver(&observer); |
| 728 NotificationLog notification_log; | |
| 665 | 729 |
| 666 { | 730 { |
| 667 // Watch a directory. | 731 // Watch a directory. |
| 668 Log log; | 732 Log log; |
| 733 | |
| 669 provided_file_system_->AddWatcher( | 734 provided_file_system_->AddWatcher( |
| 670 GURL(kOrigin), | 735 GURL(kOrigin), |
| 671 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 736 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
| 672 false /* recursive */, | 737 false /* recursive */, |
| 673 true /* persistent */, | 738 false /* persistent */, |
| 674 base::Bind(&LogStatus, base::Unretained(&log))); | 739 base::Bind(&LogStatus, base::Unretained(&log)), |
| 740 base::Bind(&LogNotification, base::Unretained(¬ification_log))); | |
| 675 base::RunLoop().RunUntilIdle(); | 741 base::RunLoop().RunUntilIdle(); |
| 676 | 742 |
| 677 ASSERT_EQ(1u, log.size()); | 743 ASSERT_EQ(1u, log.size()); |
| 678 EXPECT_EQ(base::File::FILE_OK, log[0]); | 744 EXPECT_EQ(base::File::FILE_OK, log[0]); |
| 679 EXPECT_EQ(1, observer.list_changed_counter()); | 745 EXPECT_EQ(1, observer.list_changed_counter()); |
| 680 EXPECT_EQ(0, observer.tag_updated_counter()); | 746 EXPECT_EQ(0, observer.tag_updated_counter()); |
| 747 EXPECT_EQ(0u, notification_log.size()); | |
| 681 | 748 |
| 682 Watchers* const watchers = provided_file_system_->GetWatchers(); | 749 Watchers* const watchers = provided_file_system_->GetWatchers(); |
| 683 EXPECT_EQ(1u, watchers->size()); | 750 EXPECT_EQ(1u, watchers->size()); |
| 684 provided_file_system_->GetWatchers(); | 751 provided_file_system_->GetWatchers(); |
| 685 EXPECT_EQ("", watchers->begin()->second.last_tag); | 752 EXPECT_EQ("", watchers->begin()->second.last_tag); |
| 686 } | 753 } |
| 687 | 754 |
| 688 { | 755 { |
| 689 // Notify about a change. | 756 // Notify about a change. |
| 690 const ProvidedFileSystemObserver::ChangeType change_type = | 757 const storage::WatcherManager::ChangeType change_type = |
| 691 ProvidedFileSystemObserver::CHANGED; | 758 storage::WatcherManager::CHANGED; |
| 692 const std::string tag = "hello-world"; | 759 const std::string tag = "hello-world"; |
| 693 EXPECT_TRUE(provided_file_system_->Notify( | 760 EXPECT_TRUE(provided_file_system_->Notify( |
| 694 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 761 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
| 695 false /* recursive */, | 762 false /* recursive */, |
| 696 change_type, | 763 change_type, |
| 697 make_scoped_ptr(new ProvidedFileSystemObserver::Changes), | 764 make_scoped_ptr(new ProvidedFileSystemObserver::Changes), |
| 698 tag)); | 765 tag)); |
| 699 | 766 |
| 767 // Confirm that the notification callback was called. | |
| 768 ASSERT_EQ(1u, notification_log.size()); | |
| 769 EXPECT_EQ(change_type, notification_log[0]); | |
| 770 | |
| 700 // Verify the observer event. | 771 // Verify the observer event. |
| 701 ASSERT_EQ(1u, observer.change_events().size()); | 772 ASSERT_EQ(1u, observer.change_events().size()); |
| 702 const Observer::ChangeEvent* const change_event = | 773 const Observer::ChangeEvent* const change_event = |
| 703 observer.change_events()[0]; | 774 observer.change_events()[0]; |
| 704 EXPECT_EQ(change_type, change_event->change_type()); | 775 EXPECT_EQ(change_type, change_event->change_type()); |
| 705 EXPECT_EQ(0u, change_event->changes().size()); | 776 EXPECT_EQ(0u, change_event->changes().size()); |
| 706 | 777 |
| 707 // The tag should not be updated in advance, before all observers handle | 778 // The tag should not be updated in advance, before all observers handle |
| 708 // the notification. | 779 // the notification. |
| 709 Watchers* const watchers = provided_file_system_->GetWatchers(); | 780 Watchers* const watchers = provided_file_system_->GetWatchers(); |
| 710 EXPECT_EQ(1u, watchers->size()); | 781 EXPECT_EQ(1u, watchers->size()); |
| 711 provided_file_system_->GetWatchers(); | 782 provided_file_system_->GetWatchers(); |
| 712 EXPECT_EQ("", watchers->begin()->second.last_tag); | 783 EXPECT_EQ("", watchers->begin()->second.last_tag); |
| 713 | 784 |
| 714 // Wait until all observers finish handling the notification. | 785 // Wait until all observers finish handling the notification. |
| 715 base::RunLoop().RunUntilIdle(); | 786 base::RunLoop().RunUntilIdle(); |
| 716 | 787 |
| 717 // Confirm, that the watcher still exists, and that the tag is updated. | 788 // Confirm, that the watcher still exists, and that the tag is updated. |
| 718 ASSERT_EQ(1u, watchers->size()); | 789 ASSERT_EQ(1u, watchers->size()); |
| 719 EXPECT_EQ(tag, watchers->begin()->second.last_tag); | 790 EXPECT_EQ(tag, watchers->begin()->second.last_tag); |
| 720 EXPECT_EQ(1, observer.list_changed_counter()); | 791 EXPECT_EQ(1, observer.list_changed_counter()); |
| 721 EXPECT_EQ(1, observer.tag_updated_counter()); | 792 EXPECT_EQ(1, observer.tag_updated_counter()); |
| 722 } | 793 } |
| 723 | 794 |
| 724 { | 795 { |
| 725 // Notify about deleting of the watched entry. | 796 // Notify about deleting of the watched entry. |
| 726 const ProvidedFileSystemObserver::ChangeType change_type = | 797 const storage::WatcherManager::ChangeType change_type = |
| 727 ProvidedFileSystemObserver::DELETED; | 798 storage::WatcherManager::DELETED; |
| 728 const ProvidedFileSystemObserver::Changes changes; | 799 const ProvidedFileSystemObserver::Changes changes; |
| 729 const std::string tag = "chocolate-disco"; | 800 const std::string tag = "chocolate-disco"; |
| 730 EXPECT_TRUE(provided_file_system_->Notify( | 801 EXPECT_TRUE(provided_file_system_->Notify( |
| 731 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 802 base::FilePath::FromUTF8Unsafe(kDirectoryPath), |
| 732 false /* recursive */, | 803 false /* recursive */, |
| 733 change_type, | 804 change_type, |
| 734 make_scoped_ptr(new ProvidedFileSystemObserver::Changes), | 805 make_scoped_ptr(new ProvidedFileSystemObserver::Changes), |
| 735 tag)); | 806 tag)); |
| 736 base::RunLoop().RunUntilIdle(); | 807 base::RunLoop().RunUntilIdle(); |
| 737 | 808 |
| 809 // Confirm that the notification callback was called. | |
| 810 ASSERT_EQ(2u, notification_log.size()); | |
| 811 EXPECT_EQ(change_type, notification_log[1]); | |
| 812 | |
| 738 // Verify the observer event. | 813 // Verify the observer event. |
| 739 ASSERT_EQ(2u, observer.change_events().size()); | 814 ASSERT_EQ(2u, observer.change_events().size()); |
| 740 const Observer::ChangeEvent* const change_event = | 815 const Observer::ChangeEvent* const change_event = |
| 741 observer.change_events()[1]; | 816 observer.change_events()[1]; |
| 742 EXPECT_EQ(change_type, change_event->change_type()); | 817 EXPECT_EQ(change_type, change_event->change_type()); |
| 743 EXPECT_EQ(0u, change_event->changes().size()); | 818 EXPECT_EQ(0u, change_event->changes().size()); |
| 744 } | 819 } |
| 745 | 820 |
| 746 // Confirm, that the watcher is removed. | 821 // Confirm, that the watcher is removed. |
| 747 { | 822 { |
| 748 Watchers* const watchers = provided_file_system_->GetWatchers(); | 823 Watchers* const watchers = provided_file_system_->GetWatchers(); |
| 749 EXPECT_EQ(0u, watchers->size()); | 824 EXPECT_EQ(0u, watchers->size()); |
| 750 EXPECT_EQ(2, observer.list_changed_counter()); | 825 EXPECT_EQ(2, observer.list_changed_counter()); |
| 751 EXPECT_EQ(2, observer.tag_updated_counter()); | 826 EXPECT_EQ(2, observer.tag_updated_counter()); |
| 752 } | 827 } |
| 753 | 828 |
| 754 provided_file_system_->RemoveObserver(&observer); | 829 provided_file_system_->RemoveObserver(&observer); |
| 755 } | 830 } |
| 756 | 831 |
| 757 } // namespace file_system_provider | 832 } // namespace file_system_provider |
| 758 } // namespace chromeos | 833 } // namespace chromeos |
| OLD | NEW |