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" | |
8 #include "chrome/browser/chromeos/file_manager/drive_test_util.h" | 6 #include "chrome/browser/chromeos/file_manager/drive_test_util.h" |
9 #include "chrome/browser/chromeos/file_manager/file_watcher.h" | |
10 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
11 #include "chrome/test/base/testing_profile.h" | |
12 #include "chromeos/dbus/cros_disks_client.h" | 8 #include "chromeos/dbus/cros_disks_client.h" |
13 #include "chromeos/disks/mock_disk_mount_manager.h" | 9 #include "chromeos/disks/mock_disk_mount_manager.h" |
14 #include "extensions/common/extension.h" | 10 #include "extensions/common/extension.h" |
15 #include "extensions/common/install_warning.h" | 11 #include "extensions/common/install_warning.h" |
16 | 12 |
17 using ::testing::_; | 13 using ::testing::_; |
18 using ::testing::ReturnRef; | 14 using ::testing::ReturnRef; |
19 | 15 |
20 using chromeos::disks::DiskMountManager; | 16 using chromeos::disks::DiskMountManager; |
21 | 17 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 chromeos::DEVICE_TYPE_OPTICAL_DISC, | 101 chromeos::DEVICE_TYPE_OPTICAL_DISC, |
106 0, | 102 0, |
107 true, | 103 true, |
108 false, | 104 false, |
109 false, | 105 false, |
110 true, | 106 true, |
111 false | 107 false |
112 } | 108 } |
113 }; | 109 }; |
114 | 110 |
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 | |
126 } // namespace | 111 } // namespace |
127 | 112 |
128 class FileManagerPrivateApiTest : public ExtensionApiTest { | 113 class FileManagerPrivateApiTest : public ExtensionApiTest { |
129 public: | 114 public: |
130 FileManagerPrivateApiTest() | 115 FileManagerPrivateApiTest() |
131 : disk_mount_manager_mock_(NULL) { | 116 : disk_mount_manager_mock_(NULL) { |
132 InitMountPoints(); | 117 InitMountPoints(); |
133 } | 118 } |
134 | 119 |
135 virtual ~FileManagerPrivateApiTest() { | 120 virtual ~FileManagerPrivateApiTest() { |
136 DCHECK(!disk_mount_manager_mock_); | 121 DCHECK(!disk_mount_manager_mock_); |
137 DCHECK(!testing_profile_); | |
138 DCHECK(!event_router_); | |
139 STLDeleteValues(&volumes_); | 122 STLDeleteValues(&volumes_); |
140 } | 123 } |
141 | 124 |
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 | |
158 // ExtensionApiTest override | 125 // ExtensionApiTest override |
159 virtual void SetUpInProcessBrowserTestFixture() override { | 126 virtual void SetUpInProcessBrowserTestFixture() override { |
160 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 127 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 128 |
161 disk_mount_manager_mock_ = new chromeos::disks::MockDiskMountManager; | 129 disk_mount_manager_mock_ = new chromeos::disks::MockDiskMountManager; |
162 chromeos::disks::DiskMountManager::InitializeForTesting( | 130 chromeos::disks::DiskMountManager::InitializeForTesting( |
163 disk_mount_manager_mock_); | 131 disk_mount_manager_mock_); |
164 disk_mount_manager_mock_->SetupDefaultReplies(); | 132 disk_mount_manager_mock_->SetupDefaultReplies(); |
165 | 133 |
166 // override mock functions. | 134 // override mock functions. |
167 ON_CALL(*disk_mount_manager_mock_, FindDiskBySourcePath(_)).WillByDefault( | 135 ON_CALL(*disk_mount_manager_mock_, FindDiskBySourcePath(_)).WillByDefault( |
168 Invoke(this, &FileManagerPrivateApiTest::FindVolumeBySourcePath)); | 136 Invoke(this, &FileManagerPrivateApiTest::FindVolumeBySourcePath)); |
169 EXPECT_CALL(*disk_mount_manager_mock_, disks()) | 137 EXPECT_CALL(*disk_mount_manager_mock_, disks()) |
170 .WillRepeatedly(ReturnRef(volumes_)); | 138 .WillRepeatedly(ReturnRef(volumes_)); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 const std::string& source_path) { | 234 const std::string& source_path) { |
267 DiskMountManager::DiskMap::const_iterator volume_it = | 235 DiskMountManager::DiskMap::const_iterator volume_it = |
268 volumes_.find(source_path); | 236 volumes_.find(source_path); |
269 return (volume_it == volumes_.end()) ? NULL : volume_it->second; | 237 return (volume_it == volumes_.end()) ? NULL : volume_it->second; |
270 } | 238 } |
271 | 239 |
272 protected: | 240 protected: |
273 chromeos::disks::MockDiskMountManager* disk_mount_manager_mock_; | 241 chromeos::disks::MockDiskMountManager* disk_mount_manager_mock_; |
274 DiskMountManager::DiskMap volumes_; | 242 DiskMountManager::DiskMap volumes_; |
275 DiskMountManager::MountPointMap mount_points_; | 243 DiskMountManager::MountPointMap mount_points_; |
276 scoped_ptr<TestingProfile> testing_profile_; | |
277 scoped_ptr<file_manager::EventRouter> event_router_; | |
278 }; | 244 }; |
279 | 245 |
280 IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, Mount) { | 246 IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, Mount) { |
281 file_manager::test_util::WaitUntilDriveMountPointIsAdded( | 247 file_manager::test_util::WaitUntilDriveMountPointIsAdded( |
282 browser()->profile()); | 248 browser()->profile()); |
283 | 249 |
284 // We will call fileManagerPrivate.unmountVolume once. To test that method, we | 250 // We will call fileManagerPrivate.unmountVolume once. To test that method, we |
285 // check that UnmountPath is really called with the same value. | 251 // check that UnmountPath is really called with the same value. |
286 EXPECT_CALL(*disk_mount_manager_mock_, UnmountPath(_, _, _)) | 252 EXPECT_CALL(*disk_mount_manager_mock_, UnmountPath(_, _, _)) |
287 .Times(0); | 253 .Times(0); |
288 EXPECT_CALL(*disk_mount_manager_mock_, | 254 EXPECT_CALL(*disk_mount_manager_mock_, |
289 UnmountPath( | 255 UnmountPath( |
290 chromeos::CrosDisksClient::GetArchiveMountPoint().AppendASCII( | 256 chromeos::CrosDisksClient::GetArchiveMountPoint().AppendASCII( |
291 "archive_mount_path").AsUTF8Unsafe(), | 257 "archive_mount_path").AsUTF8Unsafe(), |
292 chromeos::UNMOUNT_OPTIONS_NONE, _)).Times(1); | 258 chromeos::UNMOUNT_OPTIONS_NONE, _)).Times(1); |
293 | 259 |
294 ASSERT_TRUE(RunComponentExtensionTest("file_browser/mount_test")) | 260 ASSERT_TRUE(RunComponentExtensionTest("file_browser/mount_test")) |
295 << message_; | 261 << message_; |
296 } | 262 } |
297 | 263 |
298 IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, Permissions) { | 264 IN_PROC_BROWSER_TEST_F(FileManagerPrivateApiTest, Permissions) { |
299 EXPECT_TRUE( | 265 EXPECT_TRUE( |
300 RunExtensionTestIgnoreManifestWarnings("file_browser/permissions")); | 266 RunExtensionTestIgnoreManifestWarnings("file_browser/permissions")); |
301 const extensions::Extension* extension = GetSingleLoadedExtension(); | 267 const extensions::Extension* extension = GetSingleLoadedExtension(); |
302 ASSERT_TRUE(extension); | 268 ASSERT_TRUE(extension); |
303 ASSERT_EQ(1u, extension->install_warnings().size()); | 269 ASSERT_EQ(1u, extension->install_warnings().size()); |
304 const extensions::InstallWarning& warning = extension->install_warnings()[0]; | 270 const extensions::InstallWarning& warning = extension->install_warnings()[0]; |
305 EXPECT_EQ("fileManagerPrivate", warning.key); | 271 EXPECT_EQ("fileManagerPrivate", warning.key); |
306 } | 272 } |
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 |