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