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..ba835de4ad602fc20373e71c35003b096d4f730a 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,25 @@ TestDiskInfo kTestDisks[] = { |
| } |
| }; |
| +void DispatchDirectoryChangeEventImpl( |
| + int* counter, const base::FilePath& virtual_path, |
| + const drive::FileChange* list, bool got_error, |
| + const std::vector<std::string>& extension_ids) { |
| + ++(*counter); |
| +} |
| + |
| +drive::FileChange* CreateDirectoryDeletionFileChange( |
|
mtomasz
2014/10/20 08:05:23
Is the pointer ownership properly managed, and the
yawano
2014/10/20 08:45:15
Done. Changed to use scoped_ptr.
|
| + const base::FilePath& directory_path) { |
| + drive::FileChange* file_change = new drive::FileChange; |
|
mtomasz
2014/10/20 08:05:22
nit: This can be "drive::FileChange* const file_ch
yawano
2014/10/20 08:45:15
Acknowledged.
|
| + file_change->Update(directory_path, |
| + drive::FileChange::FileType::FILE_TYPE_DIRECTORY, |
| + drive::FileChange::ChangeType::DELETE); |
| + |
| + return file_change; |
| +} |
| + |
| +void AddFileWatchCallback(bool success) {} |
| + |
| } // namespace |
| class FileManagerPrivateApiTest : public ExtensionApiTest { |
| @@ -119,13 +142,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 +281,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 +312,41 @@ 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. |
| + int counter = 0; |
| + event_router_->SetDispatchDirectoryChangeEventImplForTesting( |
| + base::Bind(&DispatchDirectoryChangeEventImpl, &counter)); |
| + |
| + // /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, counter); |
| + |
| + // 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, counter); |
| + |
| + // 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, counter); |
| +} |