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