OLD | NEW |
---|---|
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 Loading... | |
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 class DispatchDirectoryChangeEventImpl { | |
116 public: | |
117 DispatchDirectoryChangeEventImpl() : counter_(0) {} | |
118 ~DispatchDirectoryChangeEventImpl() {} | |
119 | |
120 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
| |
121 const drive::FileChange* list, | |
122 bool got_error, | |
123 const std::vector<std::string>& extension_ids) { | |
124 counter_++; | |
mtomasz
2014/10/20 07:03:13
nit: ++counter_ for consistency.
yawano
2014/10/20 07:58:30
Done.
| |
125 } | |
126 | |
127 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.
| |
128 return counter_; | |
129 } | |
130 | |
131 private: | |
132 int counter_; | |
133 | |
134 DISALLOW_COPY_AND_ASSIGN(DispatchDirectoryChangeEventImpl); | |
135 }; | |
136 | |
137 drive::FileChange* CreateDirectoryDeletionFileChange( | |
138 const base::FilePath& directory_path) { | |
139 drive::FileChange* file_change = new drive::FileChange; | |
140 file_change->Update(directory_path, | |
141 drive::FileChange::FileType::FILE_TYPE_DIRECTORY, | |
142 drive::FileChange::ChangeType::DELETE); | |
143 | |
144 return file_change; | |
145 } | |
146 | |
147 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.
| |
148 | |
111 } // namespace | 149 } // namespace |
112 | 150 |
113 class FileManagerPrivateApiTest : public ExtensionApiTest { | 151 class FileManagerPrivateApiTest : public ExtensionApiTest { |
114 public: | 152 public: |
115 FileManagerPrivateApiTest() | 153 FileManagerPrivateApiTest() |
116 : disk_mount_manager_mock_(NULL) { | 154 : disk_mount_manager_mock_(NULL) { |
117 InitMountPoints(); | 155 InitMountPoints(); |
118 } | 156 } |
119 | 157 |
120 virtual ~FileManagerPrivateApiTest() { | 158 virtual ~FileManagerPrivateApiTest() { |
121 DCHECK(!disk_mount_manager_mock_); | 159 DCHECK(!disk_mount_manager_mock_); |
160 DCHECK(!testing_profile_); | |
161 DCHECK(!event_router_); | |
122 STLDeleteValues(&volumes_); | 162 STLDeleteValues(&volumes_); |
123 } | 163 } |
124 | 164 |
165 virtual void SetUpOnMainThread() override { | |
166 ExtensionApiTest::SetUpOnMainThread(); | |
167 | |
168 testing_profile_.reset(new TestingProfile()); | |
169 event_router_.reset(new file_manager::EventRouter(testing_profile_.get())); | |
170 } | |
171 | |
172 virtual void TearDownOnMainThread() override { | |
173 event_router_->Shutdown(); | |
174 | |
175 event_router_.reset(); | |
176 testing_profile_.reset(); | |
177 | |
178 ExtensionApiTest::TearDownOnMainThread(); | |
179 } | |
180 | |
125 // ExtensionApiTest override | 181 // ExtensionApiTest override |
126 virtual void SetUpInProcessBrowserTestFixture() override { | 182 virtual void SetUpInProcessBrowserTestFixture() override { |
127 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 183 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
128 | |
129 disk_mount_manager_mock_ = new chromeos::disks::MockDiskMountManager; | 184 disk_mount_manager_mock_ = new chromeos::disks::MockDiskMountManager; |
130 chromeos::disks::DiskMountManager::InitializeForTesting( | 185 chromeos::disks::DiskMountManager::InitializeForTesting( |
131 disk_mount_manager_mock_); | 186 disk_mount_manager_mock_); |
132 disk_mount_manager_mock_->SetupDefaultReplies(); | 187 disk_mount_manager_mock_->SetupDefaultReplies(); |
133 | 188 |
134 // override mock functions. | 189 // override mock functions. |
135 ON_CALL(*disk_mount_manager_mock_, FindDiskBySourcePath(_)).WillByDefault( | 190 ON_CALL(*disk_mount_manager_mock_, FindDiskBySourcePath(_)).WillByDefault( |
136 Invoke(this, &FileManagerPrivateApiTest::FindVolumeBySourcePath)); | 191 Invoke(this, &FileManagerPrivateApiTest::FindVolumeBySourcePath)); |
137 EXPECT_CALL(*disk_mount_manager_mock_, disks()) | 192 EXPECT_CALL(*disk_mount_manager_mock_, disks()) |
138 .WillRepeatedly(ReturnRef(volumes_)); | 193 .WillRepeatedly(ReturnRef(volumes_)); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 const std::string& source_path) { | 289 const std::string& source_path) { |
235 DiskMountManager::DiskMap::const_iterator volume_it = | 290 DiskMountManager::DiskMap::const_iterator volume_it = |
236 volumes_.find(source_path); | 291 volumes_.find(source_path); |
237 return (volume_it == volumes_.end()) ? NULL : volume_it->second; | 292 return (volume_it == volumes_.end()) ? NULL : volume_it->second; |
238 } | 293 } |
239 | 294 |
240 protected: | 295 protected: |
241 chromeos::disks::MockDiskMountManager* disk_mount_manager_mock_; | 296 chromeos::disks::MockDiskMountManager* disk_mount_manager_mock_; |
242 DiskMountManager::DiskMap volumes_; | 297 DiskMountManager::DiskMap volumes_; |
243 DiskMountManager::MountPointMap mount_points_; | 298 DiskMountManager::MountPointMap mount_points_; |
299 scoped_ptr<TestingProfile> testing_profile_; | |
300 scoped_ptr<file_manager::EventRouter> event_router_; | |
244 }; | 301 }; |
245 | 302 |
246 IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, Mount) { | 303 IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, Mount) { |
247 file_manager::test_util::WaitUntilDriveMountPointIsAdded( | 304 file_manager::test_util::WaitUntilDriveMountPointIsAdded( |
248 browser()->profile()); | 305 browser()->profile()); |
249 | 306 |
250 // We will call fileManagerPrivate.unmountVolume once. To test that method, we | 307 // We will call fileManagerPrivate.unmountVolume once. To test that method, we |
251 // check that UnmountPath is really called with the same value. | 308 // check that UnmountPath is really called with the same value. |
252 EXPECT_CALL(*disk_mount_manager_mock_, UnmountPath(_, _, _)) | 309 EXPECT_CALL(*disk_mount_manager_mock_, UnmountPath(_, _, _)) |
253 .Times(0); | 310 .Times(0); |
254 EXPECT_CALL(*disk_mount_manager_mock_, | 311 EXPECT_CALL(*disk_mount_manager_mock_, |
255 UnmountPath( | 312 UnmountPath( |
256 chromeos::CrosDisksClient::GetArchiveMountPoint().AppendASCII( | 313 chromeos::CrosDisksClient::GetArchiveMountPoint().AppendASCII( |
257 "archive_mount_path").AsUTF8Unsafe(), | 314 "archive_mount_path").AsUTF8Unsafe(), |
258 chromeos::UNMOUNT_OPTIONS_NONE, _)).Times(1); | 315 chromeos::UNMOUNT_OPTIONS_NONE, _)).Times(1); |
259 | 316 |
260 ASSERT_TRUE(RunComponentExtensionTest("file_browser/mount_test")) | 317 ASSERT_TRUE(RunComponentExtensionTest("file_browser/mount_test")) |
261 << message_; | 318 << message_; |
262 } | 319 } |
263 | 320 |
264 IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, Permissions) { | 321 IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, Permissions) { |
265 EXPECT_TRUE( | 322 EXPECT_TRUE( |
266 RunExtensionTestIgnoreManifestWarnings("file_browser/permissions")); | 323 RunExtensionTestIgnoreManifestWarnings("file_browser/permissions")); |
267 const extensions::Extension* extension = GetSingleLoadedExtension(); | 324 const extensions::Extension* extension = GetSingleLoadedExtension(); |
268 ASSERT_TRUE(extension); | 325 ASSERT_TRUE(extension); |
269 ASSERT_EQ(1u, extension->install_warnings().size()); | 326 ASSERT_EQ(1u, extension->install_warnings().size()); |
270 const extensions::InstallWarning& warning = extension->install_warnings()[0]; | 327 const extensions::InstallWarning& warning = extension->install_warnings()[0]; |
271 EXPECT_EQ("fileManagerPrivate", warning.key); | 328 EXPECT_EQ("fileManagerPrivate", warning.key); |
272 } | 329 } |
330 | |
331 IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, OnFileChanged) { | |
332 // In drive volume, deletion of a directory is notified via OnFileChanged. | |
333 // Local changes directly come to HandleFileWatchNotification from | |
334 // FileWatcher. | |
335 DispatchDirectoryChangeEventImpl* const dispatch_directory_change_event_impl = | |
336 new DispatchDirectoryChangeEventImpl(); | |
337 | |
338 event_router_->SetDispatchDirectoryChangeEventImplForTesting(base::Bind( | |
339 &DispatchDirectoryChangeEventImpl::Callback, | |
340 base::Owned(dispatch_directory_change_event_impl))); | |
341 | |
342 // /a/b/c and /a/d/e are being watched. | |
343 event_router_->AddFileWatch( | |
344 base::FilePath(FILE_PATH_LITERAL("/no-existing-fs/root/a/b/c")), | |
345 base::FilePath(FILE_PATH_LITERAL("/no-existing-fs-virtual/root/a/b/c")), | |
346 "extension_1", | |
347 base::Bind(&AddFileWatchCallback)); | |
348 | |
349 event_router_->AddFileWatch( | |
350 base::FilePath(FILE_PATH_LITERAL("/no-existing-fs/root/a/d/e")), | |
351 base::FilePath(FILE_PATH_LITERAL("/no-existing-fs-hash/root/a/d/e")), | |
352 "extension_2", | |
353 base::Bind(&AddFileWatchCallback)); | |
354 | |
355 // When /a is deleted (1 and 2 is notified). | |
356 event_router_->OnFileChanged(*CreateDirectoryDeletionFileChange( | |
357 base::FilePath(FILE_PATH_LITERAL("/no-existing-fs/root/a")))); | |
358 EXPECT_EQ(2, dispatch_directory_change_event_impl->Count()); | |
359 | |
360 // When /a/b/c is deleted (1 is notified). | |
361 event_router_->OnFileChanged(*CreateDirectoryDeletionFileChange( | |
362 base::FilePath(FILE_PATH_LITERAL("/no-existing-fs/root/a/b/c")))); | |
363 EXPECT_EQ(3, dispatch_directory_change_event_impl->Count()); | |
364 | |
365 // When /z/y is deleted (Not notified). | |
366 event_router_->OnFileChanged(*CreateDirectoryDeletionFileChange( | |
367 base::FilePath(FILE_PATH_LITERAL("/no-existing-fs/root/z/y")))); | |
368 EXPECT_EQ(3, dispatch_directory_change_event_impl->Count()); | |
369 } | |
OLD | NEW |