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