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

Unified Diff: chrome/browser/chromeos/extensions/file_manager/file_manager_private_apitest.cc

Issue 658013002: Changed api to notify when watched directory is deleted. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added periods to the end of comments. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/extensions/file_manager/event_router.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..31ba876245d328acf570c13463b00d4847c27ba0 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,24 +112,80 @@ TestDiskInfo kTestDisks[] = {
}
};
+class DispatchDirectoryChangeEventImpl {
+ public:
+ DispatchDirectoryChangeEventImpl() {}
+ ~DispatchDirectoryChangeEventImpl() {}
+
+ void Callback(const base::FilePath& virtual_path,
+ const drive::FileChange* list,
+ bool got_error,
+ const std::vector<std::string>& extension_ids) {
+ counter_++;
+ }
+
+ int Count() {
+ return counter_;
+ }
+
+ private:
+ int counter_ = 0;
mtomasz 2014/10/20 01:02:51 In Chromium we use initializer lists to initialize
yawano 2014/10/20 06:49:20 Done.
+
+ 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) { }
+
} // namespace
class FileManagerPrivateApiTest : public ExtensionApiTest {
public:
FileManagerPrivateApiTest()
- : disk_mount_manager_mock_(NULL) {
+ : disk_mount_manager_mock_(NULL),
+ testing_profile_(NULL),
+ event_router_(NULL) {
InitMountPoints();
}
virtual ~FileManagerPrivateApiTest() {
DCHECK(!disk_mount_manager_mock_);
+ DCHECK(!testing_profile_);
+ DCHECK(!event_router_);
STLDeleteValues(&volumes_);
}
+ virtual void SetUpOnMainThread() override {
+ ExtensionApiTest::SetUpOnMainThread();
+
+ testing_profile_ = new TestingProfile();
+ event_router_ = new file_manager::EventRouter(testing_profile_);
+ }
+
+ virtual void TearDownOnMainThread() override {
+ event_router_->Shutdown();
+
+ delete event_router_;
mtomasz 2014/10/20 01:02:51 Please use scoped_ptr instead of manually maintain
yawano 2014/10/20 06:49:20 Done.
+ event_router_ = NULL;
+
+ delete testing_profile_;
+ testing_profile_ = NULL;
+
+ 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 +301,8 @@ class FileManagerPrivateApiTest : public ExtensionApiTest {
chromeos::disks::MockDiskMountManager* disk_mount_manager_mock_;
DiskMountManager::DiskMap volumes_;
DiskMountManager::MountPointMap mount_points_;
+ TestingProfile* testing_profile_;
+ file_manager::EventRouter* event_router_;
};
IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, Mount) {
@@ -270,3 +332,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* dispatch_directory_change_event_impl =
mtomasz 2014/10/20 01:02:51 nit: This can be: "DispatchDirectoryChangeEventImp
yawano 2014/10/20 06:49:20 Done.
+ 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(
mtomasz 2014/10/20 01:02:51 nit: It can be EXPECT_EQ.
yawano 2014/10/20 06:49:20 Done.
+ base::FilePath(FILE_PATH_LITERAL("/no-existing-fs/root/a"))));
+ ASSERT_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"))));
+ ASSERT_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"))));
+ ASSERT_EQ(3, dispatch_directory_change_event_impl->Count());
+}
« no previous file with comments | « chrome/browser/chromeos/extensions/file_manager/event_router.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698