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

Side by Side 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: Changed to fix OnFileChanged rather than HandleFileWatchNotification. 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/stl_util.h" 5 #include "base/stl_util.h"
6 #include "chrome/browser/chromeos/drive/file_change.h"
7 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h"
6 #include "chrome/browser/chromeos/file_manager/drive_test_util.h" 8 #include "chrome/browser/chromeos/file_manager/drive_test_util.h"
9 #include "chrome/browser/chromeos/file_manager/file_watcher.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/test/base/testing_profile.h"
8 #include "chromeos/dbus/cros_disks_client.h" 12 #include "chromeos/dbus/cros_disks_client.h"
9 #include "chromeos/disks/mock_disk_mount_manager.h" 13 #include "chromeos/disks/mock_disk_mount_manager.h"
10 #include "extensions/common/extension.h" 14 #include "extensions/common/extension.h"
11 #include "extensions/common/install_warning.h" 15 #include "extensions/common/install_warning.h"
12 16
13 using ::testing::_; 17 using ::testing::_;
14 using ::testing::ReturnRef; 18 using ::testing::ReturnRef;
15 19
16 using chromeos::disks::DiskMountManager; 20 using chromeos::disks::DiskMountManager;
17 21
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 chromeos::DEVICE_TYPE_OPTICAL_DISC, 105 chromeos::DEVICE_TYPE_OPTICAL_DISC,
102 0, 106 0,
103 true, 107 true,
104 false, 108 false,
105 false, 109 false,
106 true, 110 true,
107 false 111 false
108 } 112 }
109 }; 113 };
110 114
115 struct DispatchDirectoryChangeEvent {
mtomasz 2014/10/17 05:26:57 nit: This can be a nested struct in DispatchDirect
yawano 2014/10/20 00:49:48 Acknowledged.
116 base::FilePath virtual_path;
117 std::vector<std::string> extension_ids;
118 };
119
120 class DispatchDirectoryChangeEventImpl {
121 public:
122 std::vector<DispatchDirectoryChangeEvent> events;
123
124 void Callback(const base::FilePath& virtual_path,
125 const drive::FileChange* list,
126 bool got_error,
127 const std::vector<std::string>& extension_ids) {
128 DispatchDirectoryChangeEvent dispatch_directory_change_event;
129 dispatch_directory_change_event.virtual_path = virtual_path;
130 dispatch_directory_change_event.extension_ids = extension_ids;
131 events.push_back(dispatch_directory_change_event);
132 }
mtomasz 2014/10/17 05:26:57 Please use DISALLOW_COPY_AND_ASSIGN macro on class
yawano 2014/10/20 00:49:48 Done.
133 };
134
135 drive::FileChange* CreateDirectoryDeletionFileChange(
136 const base::FilePath& directory_path) {
137 drive::FileChange* file_change = new drive::FileChange;
138 file_change->Update(directory_path,
139 drive::FileChange::FileType::FILE_TYPE_DIRECTORY,
140 drive::FileChange::ChangeType::DELETE);
141
142 return file_change;
143 }
144
145 void AddFileWatchCallback(bool b) { }
mtomasz 2014/10/17 05:26:57 Please avoid abbreviations (except common ones): h
yawano 2014/10/20 00:49:48 Done.
146
111 } // namespace 147 } // namespace
112 148
113 class FileManagerPrivateApiTest : public ExtensionApiTest { 149 class FileManagerPrivateApiTest : public ExtensionApiTest {
114 public: 150 public:
115 FileManagerPrivateApiTest() 151 FileManagerPrivateApiTest()
116 : disk_mount_manager_mock_(NULL) { 152 : disk_mount_manager_mock_(NULL) {
117 InitMountPoints(); 153 InitMountPoints();
118 } 154 }
119 155
120 virtual ~FileManagerPrivateApiTest() { 156 virtual ~FileManagerPrivateApiTest() {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 299
264 IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, Permissions) { 300 IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, Permissions) {
265 EXPECT_TRUE( 301 EXPECT_TRUE(
266 RunExtensionTestIgnoreManifestWarnings("file_browser/permissions")); 302 RunExtensionTestIgnoreManifestWarnings("file_browser/permissions"));
267 const extensions::Extension* extension = GetSingleLoadedExtension(); 303 const extensions::Extension* extension = GetSingleLoadedExtension();
268 ASSERT_TRUE(extension); 304 ASSERT_TRUE(extension);
269 ASSERT_EQ(1u, extension->install_warnings().size()); 305 ASSERT_EQ(1u, extension->install_warnings().size());
270 const extensions::InstallWarning& warning = extension->install_warnings()[0]; 306 const extensions::InstallWarning& warning = extension->install_warnings()[0];
271 EXPECT_EQ("fileManagerPrivate", warning.key); 307 EXPECT_EQ("fileManagerPrivate", warning.key);
272 } 308 }
309
310 IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, OnFileChanged) {
311 // In drive volume, deletion of a directory is notified via OnFileChanged.
312 // Local changes directly come to HandleFileWatchNotification from
313 // FileWatcher.
314
315 TestingProfile profile;
316 file_manager::EventRouter event_router(&profile);
317
318 DispatchDirectoryChangeEventImpl dispatch_directory_change_event_impl;
319 event_router.SetDispatchDirectoryChangeEventImplForTesting(base::Bind(
320 &DispatchDirectoryChangeEventImpl::Callback,
321 base::Unretained(&dispatch_directory_change_event_impl)));
322
323 // /a/b/c and /a/d/e are being watched.
324 // In this test case, we assume these pathes does not actually exist in the
mtomasz 2014/10/17 05:26:57 nit: does -> do [for plural]
mtomasz 2014/10/17 05:26:57 typo: paths
yawano 2014/10/20 00:49:48 Sorry, these comments are for old patches. I delet
yawano 2014/10/20 00:49:48 Acknowledged.
325 // machine. (EventRouter does not notify event if the child directory still
326 // exists).
327 event_router.AddFileWatch(base::FilePath("no-existing-fs/root/a/b/c"),
328 base::FilePath("no-existing-fs-virtual/root/a/b/c"),
329 "extension_1",
330 base::Bind(&AddFileWatchCallback));
331
332 event_router.AddFileWatch(base::FilePath("no-existing-fs/root/a/d/e"),
mtomasz 2014/10/17 05:26:57 Please use FILE_PATH_LITERAL.
yawano 2014/10/20 00:49:48 Done.
333 base::FilePath("no-existing-fs-hash/root/a/d/e"),
334 "extension_2",
335 base::Bind(&AddFileWatchCallback));
336
337 // When /a is deleted (1 and 2 is notified).
338 event_router.OnFileChanged(*CreateDirectoryDeletionFileChange(
339 base::FilePath("no-existing-fs/root/a")));
340 ASSERT_EQ(2lu, dispatch_directory_change_event_impl.events.size());
mtomasz 2014/10/17 05:26:57 Please either validate event members, or replace D
yawano 2014/10/20 00:49:48 Done.
341
342 // When /a/b/c is deleted (1 is notified).
343 event_router.OnFileChanged(*CreateDirectoryDeletionFileChange(
344 base::FilePath("no-existing-fs/root/a/b/c")));
345 ASSERT_EQ(3lu, dispatch_directory_change_event_impl.events.size());
mtomasz 2014/10/17 05:26:57 Isn't 3u enough?
yawano 2014/10/20 00:49:48 Done.
346
347 // When /z/y is deleted (Not notified)
348 event_router.OnFileChanged(*CreateDirectoryDeletionFileChange(
349 base::FilePath("no-existing-fs/root/z/y")));
350 ASSERT_EQ(3lu, dispatch_directory_change_event_impl.events.size());
351
352 event_router.Shutdown();
mtomasz 2014/10/17 05:26:57 If a test case fails on an assert, then EventRoute
yawano 2014/10/20 00:49:48 Done. Yes. I also think it makes safer to move in
353 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698