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