Chromium Code Reviews| Index: chrome/browser/chromeos/extensions/file_manager/file_manager_private_apitest.cc |
| diff --git a/chrome/browser/chromeos/extensions/file_manager/file_manager_private_apitest.cc b/chrome/browser/chromeos/extensions/file_manager/file_manager_private_apitest.cc |
| index 7644101eb3c72bf575a6503586bd681bc4e6ee5b..b7b905b451b214d4b8602f44347115cca494be72 100644 |
| --- a/chrome/browser/chromeos/extensions/file_manager/file_manager_private_apitest.cc |
| +++ b/chrome/browser/chromeos/extensions/file_manager/file_manager_private_apitest.cc |
| @@ -3,8 +3,12 @@ |
| // found in the LICENSE file. |
| #include "base/stl_util.h" |
| +#include "chrome/browser/chromeos/drive/file_change.h" |
| +#include "chrome/browser/chromeos/extensions/file_manager/event_router.h" |
| #include "chrome/browser/chromeos/file_manager/drive_test_util.h" |
| +#include "chrome/browser/chromeos/file_manager/file_watcher.h" |
| #include "chrome/browser/extensions/extension_apitest.h" |
| +#include "chrome/test/base/testing_profile.h" |
| #include "chromeos/dbus/cros_disks_client.h" |
| #include "chromeos/disks/mock_disk_mount_manager.h" |
| #include "extensions/common/extension.h" |
| @@ -108,6 +112,40 @@ TestDiskInfo kTestDisks[] = { |
| } |
| }; |
| +class DispatchDirectoryChangeEventImpl { |
| + public: |
| + DispatchDirectoryChangeEventImpl() : counter_(0) {} |
| + ~DispatchDirectoryChangeEventImpl() {} |
| + |
| + void Callback(const base::FilePath& virtual_path, |
|
mtomasz
2014/10/20 07:03:13
Note, that actually we don't need this entire clas
yawano
2014/10/20 07:58:30
Done. Thank you for this suggestion. I haven't com
|
| + const drive::FileChange* list, |
| + bool got_error, |
| + const std::vector<std::string>& extension_ids) { |
| + counter_++; |
|
mtomasz
2014/10/20 07:03:13
nit: ++counter_ for consistency.
yawano
2014/10/20 07:58:30
Done.
|
| + } |
| + |
| + int Count() { |
|
mtomasz
2014/10/20 07:03:13
We can write it as a getter:
int counter() const
yawano
2014/10/20 07:58:30
Acknowledged.
|
| + return counter_; |
| + } |
| + |
| + private: |
| + int counter_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DispatchDirectoryChangeEventImpl); |
| +}; |
| + |
| +drive::FileChange* CreateDirectoryDeletionFileChange( |
| + const base::FilePath& directory_path) { |
| + drive::FileChange* file_change = new drive::FileChange; |
| + file_change->Update(directory_path, |
| + drive::FileChange::FileType::FILE_TYPE_DIRECTORY, |
| + drive::FileChange::ChangeType::DELETE); |
| + |
| + return file_change; |
| +} |
| + |
| +void AddFileWatchCallback(bool success) { } |
|
mtomasz
2014/10/20 07:03:13
nit: Please use "git cl format".
yawano
2014/10/20 07:58:30
Done.
|
| + |
| } // namespace |
| class FileManagerPrivateApiTest : public ExtensionApiTest { |
| @@ -119,13 +157,30 @@ class FileManagerPrivateApiTest : public ExtensionApiTest { |
| virtual ~FileManagerPrivateApiTest() { |
| DCHECK(!disk_mount_manager_mock_); |
| + DCHECK(!testing_profile_); |
| + DCHECK(!event_router_); |
| STLDeleteValues(&volumes_); |
| } |
| + virtual void SetUpOnMainThread() override { |
| + ExtensionApiTest::SetUpOnMainThread(); |
| + |
| + testing_profile_.reset(new TestingProfile()); |
| + event_router_.reset(new file_manager::EventRouter(testing_profile_.get())); |
| + } |
| + |
| + virtual void TearDownOnMainThread() override { |
| + event_router_->Shutdown(); |
| + |
| + event_router_.reset(); |
| + testing_profile_.reset(); |
| + |
| + ExtensionApiTest::TearDownOnMainThread(); |
| + } |
| + |
| // ExtensionApiTest override |
| virtual void SetUpInProcessBrowserTestFixture() override { |
| ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| - |
| disk_mount_manager_mock_ = new chromeos::disks::MockDiskMountManager; |
| chromeos::disks::DiskMountManager::InitializeForTesting( |
| disk_mount_manager_mock_); |
| @@ -241,6 +296,8 @@ class FileManagerPrivateApiTest : public ExtensionApiTest { |
| chromeos::disks::MockDiskMountManager* disk_mount_manager_mock_; |
| DiskMountManager::DiskMap volumes_; |
| DiskMountManager::MountPointMap mount_points_; |
| + scoped_ptr<TestingProfile> testing_profile_; |
| + scoped_ptr<file_manager::EventRouter> event_router_; |
| }; |
| IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, Mount) { |
| @@ -270,3 +327,43 @@ IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, Permissions) { |
| const extensions::InstallWarning& warning = extension->install_warnings()[0]; |
| EXPECT_EQ("fileManagerPrivate", warning.key); |
| } |
| + |
| +IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, OnFileChanged) { |
| + // In drive volume, deletion of a directory is notified via OnFileChanged. |
| + // Local changes directly come to HandleFileWatchNotification from |
| + // FileWatcher. |
| + DispatchDirectoryChangeEventImpl* const dispatch_directory_change_event_impl = |
| + new DispatchDirectoryChangeEventImpl(); |
| + |
| + event_router_->SetDispatchDirectoryChangeEventImplForTesting(base::Bind( |
| + &DispatchDirectoryChangeEventImpl::Callback, |
| + base::Owned(dispatch_directory_change_event_impl))); |
| + |
| + // /a/b/c and /a/d/e are being watched. |
| + event_router_->AddFileWatch( |
| + base::FilePath(FILE_PATH_LITERAL("/no-existing-fs/root/a/b/c")), |
| + base::FilePath(FILE_PATH_LITERAL("/no-existing-fs-virtual/root/a/b/c")), |
| + "extension_1", |
| + base::Bind(&AddFileWatchCallback)); |
| + |
| + event_router_->AddFileWatch( |
| + base::FilePath(FILE_PATH_LITERAL("/no-existing-fs/root/a/d/e")), |
| + base::FilePath(FILE_PATH_LITERAL("/no-existing-fs-hash/root/a/d/e")), |
| + "extension_2", |
| + base::Bind(&AddFileWatchCallback)); |
| + |
| + // When /a is deleted (1 and 2 is notified). |
| + event_router_->OnFileChanged(*CreateDirectoryDeletionFileChange( |
| + base::FilePath(FILE_PATH_LITERAL("/no-existing-fs/root/a")))); |
| + EXPECT_EQ(2, dispatch_directory_change_event_impl->Count()); |
| + |
| + // When /a/b/c is deleted (1 is notified). |
| + event_router_->OnFileChanged(*CreateDirectoryDeletionFileChange( |
| + base::FilePath(FILE_PATH_LITERAL("/no-existing-fs/root/a/b/c")))); |
| + EXPECT_EQ(3, dispatch_directory_change_event_impl->Count()); |
| + |
| + // When /z/y is deleted (Not notified). |
| + event_router_->OnFileChanged(*CreateDirectoryDeletionFileChange( |
| + base::FilePath(FILE_PATH_LITERAL("/no-existing-fs/root/z/y")))); |
| + EXPECT_EQ(3, dispatch_directory_change_event_impl->Count()); |
| +} |