| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/file_system_provider/registry.h" | 5 #include "chrome/browser/chromeos/file_system_provider/registry.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 namespace chromeos { | 22 namespace chromeos { |
| 23 namespace file_system_provider { | 23 namespace file_system_provider { |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const char kTemporaryOrigin[] = | 26 const char kTemporaryOrigin[] = |
| 27 "chrome-extension://abcabcabcabcabcabcabcabcabcabcabcabca/"; | 27 "chrome-extension://abcabcabcabcabcabcabcabcabcabcabcabca/"; |
| 28 const char kPersistentOrigin[] = | 28 const char kPersistentOrigin[] = |
| 29 "chrome-extension://efgefgefgefgefgefgefgefgefgefgefgefge/"; | 29 "chrome-extension://efgefgefgefgefgefgefgefgefgefgefgefge/"; |
| 30 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; | 30 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; |
| 31 const char kDisplayName[] = "Camera Pictures"; | 31 const char kDisplayName[] = "Camera Pictures"; |
| 32 const Source kSource = SOURCE_NETWORK; | |
| 33 | 32 |
| 34 // The dot in the file system ID is there in order to check that saving to | 33 // The dot in the file system ID is there in order to check that saving to |
| 35 // preferences works correctly. File System ID is used as a key in | 34 // preferences works correctly. File System ID is used as a key in |
| 36 // a base::DictionaryValue, so it has to be stored without path expansion. | 35 // a base::DictionaryValue, so it has to be stored without path expansion. |
| 37 const char kFileSystemId[] = "camera/pictures/id .!@#$%^&*()_+"; | 36 const char kFileSystemId[] = "camera/pictures/id .!@#$%^&*()_+"; |
| 38 | 37 |
| 39 const int kOpenedFilesLimit = 5; | 38 const int kOpenedFilesLimit = 5; |
| 40 | 39 |
| 41 // Stores a provided file system information in preferences together with a | 40 // Stores a provided file system information in preferences together with a |
| 42 // fake watcher. | 41 // fake watcher. |
| 43 void RememberFakeFileSystem(TestingProfile* profile, | 42 void RememberFakeFileSystem(TestingProfile* profile, |
| 44 const std::string& extension_id, | 43 const std::string& extension_id, |
| 45 const std::string& file_system_id, | 44 const std::string& file_system_id, |
| 46 const std::string& display_name, | 45 const std::string& display_name, |
| 47 bool writable, | 46 bool writable, |
| 48 Source source, | |
| 49 bool supports_notify_tag, | 47 bool supports_notify_tag, |
| 50 int opened_files_limit, | 48 int opened_files_limit, |
| 51 const Watcher& watcher) { | 49 const Watcher& watcher) { |
| 52 // Warning. Updating this code means that backward compatibility may be | 50 // Warning. Updating this code means that backward compatibility may be |
| 53 // broken, what is unexpected and should be avoided. | 51 // broken, what is unexpected and should be avoided. |
| 54 TestingPrefServiceSyncable* const pref_service = | 52 TestingPrefServiceSyncable* const pref_service = |
| 55 profile->GetTestingPrefService(); | 53 profile->GetTestingPrefService(); |
| 56 ASSERT_TRUE(pref_service); | 54 ASSERT_TRUE(pref_service); |
| 57 | 55 |
| 58 base::DictionaryValue extensions; | 56 base::DictionaryValue extensions; |
| 59 base::DictionaryValue* const file_systems = new base::DictionaryValue(); | 57 base::DictionaryValue* const file_systems = new base::DictionaryValue(); |
| 60 base::DictionaryValue* const file_system = new base::DictionaryValue(); | 58 base::DictionaryValue* const file_system = new base::DictionaryValue(); |
| 61 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, | 59 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, |
| 62 kFileSystemId); | 60 kFileSystemId); |
| 63 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, kDisplayName); | 61 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, kDisplayName); |
| 64 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable, writable); | 62 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable, writable); |
| 65 file_system->SetStringWithoutPathExpansion(kPrefKeySource, | |
| 66 SourceToString(source)); | |
| 67 file_system->SetBooleanWithoutPathExpansion(kPrefKeySupportsNotifyTag, | 63 file_system->SetBooleanWithoutPathExpansion(kPrefKeySupportsNotifyTag, |
| 68 supports_notify_tag); | 64 supports_notify_tag); |
| 69 file_system->SetIntegerWithoutPathExpansion(kPrefKeyOpenedFilesLimit, | 65 file_system->SetIntegerWithoutPathExpansion(kPrefKeyOpenedFilesLimit, |
| 70 opened_files_limit); | 66 opened_files_limit); |
| 71 file_systems->SetWithoutPathExpansion(kFileSystemId, file_system); | 67 file_systems->SetWithoutPathExpansion(kFileSystemId, file_system); |
| 72 extensions.SetWithoutPathExpansion(kExtensionId, file_systems); | 68 extensions.SetWithoutPathExpansion(kExtensionId, file_systems); |
| 73 | 69 |
| 74 // Remember watchers. | 70 // Remember watchers. |
| 75 base::DictionaryValue* const watchers = new base::DictionaryValue(); | 71 base::DictionaryValue* const watchers = new base::DictionaryValue(); |
| 76 file_system->SetWithoutPathExpansion(kPrefKeyWatchers, watchers); | 72 file_system->SetWithoutPathExpansion(kPrefKeyWatchers, watchers); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 content::TestBrowserThreadBundle thread_bundle_; | 117 content::TestBrowserThreadBundle thread_bundle_; |
| 122 scoped_ptr<TestingProfileManager> profile_manager_; | 118 scoped_ptr<TestingProfileManager> profile_manager_; |
| 123 TestingProfile* profile_; | 119 TestingProfile* profile_; |
| 124 scoped_ptr<RegistryInterface> registry_; | 120 scoped_ptr<RegistryInterface> registry_; |
| 125 Watcher fake_watcher_; | 121 Watcher fake_watcher_; |
| 126 }; | 122 }; |
| 127 | 123 |
| 128 TEST_F(FileSystemProviderRegistryTest, RestoreFileSystems) { | 124 TEST_F(FileSystemProviderRegistryTest, RestoreFileSystems) { |
| 129 // Create a fake entry in the preferences. | 125 // Create a fake entry in the preferences. |
| 130 RememberFakeFileSystem(profile_, kExtensionId, kFileSystemId, kDisplayName, | 126 RememberFakeFileSystem(profile_, kExtensionId, kFileSystemId, kDisplayName, |
| 131 true /* writable */, kSource, | 127 true /* writable */, true /* supports_notify_tag */, |
| 132 true /* supports_notify_tag */, kOpenedFilesLimit, | 128 kOpenedFilesLimit, fake_watcher_); |
| 133 fake_watcher_); | |
| 134 | 129 |
| 135 scoped_ptr<RegistryInterface::RestoredFileSystems> restored_file_systems = | 130 scoped_ptr<RegistryInterface::RestoredFileSystems> restored_file_systems = |
| 136 registry_->RestoreFileSystems(kExtensionId); | 131 registry_->RestoreFileSystems(kExtensionId); |
| 137 | 132 |
| 138 ASSERT_EQ(1u, restored_file_systems->size()); | 133 ASSERT_EQ(1u, restored_file_systems->size()); |
| 139 const RegistryInterface::RestoredFileSystem& restored_file_system = | 134 const RegistryInterface::RestoredFileSystem& restored_file_system = |
| 140 restored_file_systems->at(0); | 135 restored_file_systems->at(0); |
| 141 EXPECT_EQ(kExtensionId, restored_file_system.extension_id); | 136 EXPECT_EQ(kExtensionId, restored_file_system.extension_id); |
| 142 EXPECT_EQ(kFileSystemId, restored_file_system.options.file_system_id); | 137 EXPECT_EQ(kFileSystemId, restored_file_system.options.file_system_id); |
| 143 EXPECT_EQ(kDisplayName, restored_file_system.options.display_name); | 138 EXPECT_EQ(kDisplayName, restored_file_system.options.display_name); |
| 144 EXPECT_TRUE(restored_file_system.options.writable); | 139 EXPECT_TRUE(restored_file_system.options.writable); |
| 145 EXPECT_EQ(kSource, restored_file_system.options.source); | |
| 146 EXPECT_TRUE(restored_file_system.options.supports_notify_tag); | 140 EXPECT_TRUE(restored_file_system.options.supports_notify_tag); |
| 147 EXPECT_EQ(kOpenedFilesLimit, restored_file_system.options.opened_files_limit); | 141 EXPECT_EQ(kOpenedFilesLimit, restored_file_system.options.opened_files_limit); |
| 148 | 142 |
| 149 ASSERT_EQ(1u, restored_file_system.watchers.size()); | 143 ASSERT_EQ(1u, restored_file_system.watchers.size()); |
| 150 const auto& restored_watcher_it = restored_file_system.watchers.find( | 144 const auto& restored_watcher_it = restored_file_system.watchers.find( |
| 151 WatcherKey(fake_watcher_.entry_path, fake_watcher_.recursive)); | 145 WatcherKey(fake_watcher_.entry_path, fake_watcher_.recursive)); |
| 152 ASSERT_NE(restored_file_system.watchers.end(), restored_watcher_it); | 146 ASSERT_NE(restored_file_system.watchers.end(), restored_watcher_it); |
| 153 | 147 |
| 154 EXPECT_EQ(fake_watcher_.entry_path, restored_watcher_it->second.entry_path); | 148 EXPECT_EQ(fake_watcher_.entry_path, restored_watcher_it->second.entry_path); |
| 155 EXPECT_EQ(fake_watcher_.recursive, restored_watcher_it->second.recursive); | 149 EXPECT_EQ(fake_watcher_.recursive, restored_watcher_it->second.recursive); |
| 156 EXPECT_EQ(fake_watcher_.last_tag, restored_watcher_it->second.last_tag); | 150 EXPECT_EQ(fake_watcher_.last_tag, restored_watcher_it->second.last_tag); |
| 157 } | 151 } |
| 158 | 152 |
| 159 TEST_F(FileSystemProviderRegistryTest, RememberFileSystem) { | 153 TEST_F(FileSystemProviderRegistryTest, RememberFileSystem) { |
| 160 MountOptions options(kFileSystemId, kDisplayName); | 154 MountOptions options(kFileSystemId, kDisplayName); |
| 161 options.writable = true; | 155 options.writable = true; |
| 162 options.source = kSource; | |
| 163 options.supports_notify_tag = true; | 156 options.supports_notify_tag = true; |
| 164 options.opened_files_limit = kOpenedFilesLimit; | 157 options.opened_files_limit = kOpenedFilesLimit; |
| 165 | 158 |
| 166 ProvidedFileSystemInfo file_system_info( | 159 ProvidedFileSystemInfo file_system_info( |
| 167 kExtensionId, options, base::FilePath(FILE_PATH_LITERAL("/a/b/c"))); | 160 kExtensionId, options, base::FilePath(FILE_PATH_LITERAL("/a/b/c"))); |
| 168 | 161 |
| 169 Watchers watchers; | 162 Watchers watchers; |
| 170 watchers[WatcherKey(fake_watcher_.entry_path, fake_watcher_.recursive)] = | 163 watchers[WatcherKey(fake_watcher_.entry_path, fake_watcher_.recursive)] = |
| 171 fake_watcher_; | 164 fake_watcher_; |
| 172 | 165 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 199 std::string display_name; | 192 std::string display_name; |
| 200 EXPECT_TRUE(file_system->GetStringWithoutPathExpansion(kPrefKeyDisplayName, | 193 EXPECT_TRUE(file_system->GetStringWithoutPathExpansion(kPrefKeyDisplayName, |
| 201 &display_name)); | 194 &display_name)); |
| 202 EXPECT_EQ(kDisplayName, display_name); | 195 EXPECT_EQ(kDisplayName, display_name); |
| 203 | 196 |
| 204 bool writable = false; | 197 bool writable = false; |
| 205 EXPECT_TRUE( | 198 EXPECT_TRUE( |
| 206 file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable, &writable)); | 199 file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable, &writable)); |
| 207 EXPECT_TRUE(writable); | 200 EXPECT_TRUE(writable); |
| 208 | 201 |
| 209 std::string source_as_string; | |
| 210 EXPECT_TRUE(file_system->GetStringWithoutPathExpansion(kPrefKeySource, | |
| 211 &source_as_string)); | |
| 212 EXPECT_EQ("network", source_as_string); | |
| 213 | |
| 214 bool supports_notify_tag = false; | 202 bool supports_notify_tag = false; |
| 215 EXPECT_TRUE(file_system->GetBooleanWithoutPathExpansion( | 203 EXPECT_TRUE(file_system->GetBooleanWithoutPathExpansion( |
| 216 kPrefKeySupportsNotifyTag, &supports_notify_tag)); | 204 kPrefKeySupportsNotifyTag, &supports_notify_tag)); |
| 217 EXPECT_TRUE(supports_notify_tag); | 205 EXPECT_TRUE(supports_notify_tag); |
| 218 | 206 |
| 219 int opened_files_limit = 0; | 207 int opened_files_limit = 0; |
| 220 EXPECT_TRUE(file_system->GetIntegerWithoutPathExpansion( | 208 EXPECT_TRUE(file_system->GetIntegerWithoutPathExpansion( |
| 221 kPrefKeyOpenedFilesLimit, &opened_files_limit)); | 209 kPrefKeyOpenedFilesLimit, &opened_files_limit)); |
| 222 EXPECT_EQ(kOpenedFilesLimit, opened_files_limit); | 210 EXPECT_EQ(kOpenedFilesLimit, opened_files_limit); |
| 223 | 211 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 253 EXPECT_TRUE(persistent_origins->GetString(0, &persistent_origin)); | 241 EXPECT_TRUE(persistent_origins->GetString(0, &persistent_origin)); |
| 254 const auto& fake_subscriber_it = | 242 const auto& fake_subscriber_it = |
| 255 fake_watcher_.subscribers.find(GURL(persistent_origin)); | 243 fake_watcher_.subscribers.find(GURL(persistent_origin)); |
| 256 ASSERT_NE(fake_watcher_.subscribers.end(), fake_subscriber_it); | 244 ASSERT_NE(fake_watcher_.subscribers.end(), fake_subscriber_it); |
| 257 EXPECT_TRUE(fake_subscriber_it->second.persistent); | 245 EXPECT_TRUE(fake_subscriber_it->second.persistent); |
| 258 } | 246 } |
| 259 | 247 |
| 260 TEST_F(FileSystemProviderRegistryTest, ForgetFileSystem) { | 248 TEST_F(FileSystemProviderRegistryTest, ForgetFileSystem) { |
| 261 // Create a fake file systems in the preferences. | 249 // Create a fake file systems in the preferences. |
| 262 RememberFakeFileSystem(profile_, kExtensionId, kFileSystemId, kDisplayName, | 250 RememberFakeFileSystem(profile_, kExtensionId, kFileSystemId, kDisplayName, |
| 263 true /* writable */, kSource, | 251 true /* writable */, true /* supports_notify_tag */, |
| 264 true /* supports_notify_tag */, kOpenedFilesLimit, | 252 kOpenedFilesLimit, fake_watcher_); |
| 265 fake_watcher_); | |
| 266 | 253 |
| 267 registry_->ForgetFileSystem(kExtensionId, kFileSystemId); | 254 registry_->ForgetFileSystem(kExtensionId, kFileSystemId); |
| 268 | 255 |
| 269 TestingPrefServiceSyncable* const pref_service = | 256 TestingPrefServiceSyncable* const pref_service = |
| 270 profile_->GetTestingPrefService(); | 257 profile_->GetTestingPrefService(); |
| 271 ASSERT_TRUE(pref_service); | 258 ASSERT_TRUE(pref_service); |
| 272 | 259 |
| 273 const base::DictionaryValue* const extensions = | 260 const base::DictionaryValue* const extensions = |
| 274 pref_service->GetDictionary(prefs::kFileSystemProviderMounted); | 261 pref_service->GetDictionary(prefs::kFileSystemProviderMounted); |
| 275 ASSERT_TRUE(extensions); | 262 ASSERT_TRUE(extensions); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 const base::DictionaryValue* watcher = NULL; | 309 const base::DictionaryValue* watcher = NULL; |
| 323 ASSERT_TRUE(watchers_value->GetDictionaryWithoutPathExpansion( | 310 ASSERT_TRUE(watchers_value->GetDictionaryWithoutPathExpansion( |
| 324 fake_watcher_.entry_path.value(), &watcher)); | 311 fake_watcher_.entry_path.value(), &watcher)); |
| 325 | 312 |
| 326 std::string last_tag; | 313 std::string last_tag; |
| 327 EXPECT_TRUE(watcher->GetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, | 314 EXPECT_TRUE(watcher->GetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, |
| 328 &last_tag)); | 315 &last_tag)); |
| 329 EXPECT_EQ(fake_watcher_.last_tag, last_tag); | 316 EXPECT_EQ(fake_watcher_.last_tag, last_tag); |
| 330 } | 317 } |
| 331 | 318 |
| 332 TEST_F(FileSystemProviderRegistryTest, SourceToString) { | |
| 333 { | |
| 334 Source result = SOURCE_UNKNOWN; | |
| 335 EXPECT_TRUE(StringToSource(SourceToString(SOURCE_FILE), &result)); | |
| 336 EXPECT_EQ(SOURCE_FILE, result); | |
| 337 } | |
| 338 { | |
| 339 Source result = SOURCE_UNKNOWN; | |
| 340 EXPECT_TRUE(StringToSource(SourceToString(SOURCE_DEVICE), &result)); | |
| 341 EXPECT_EQ(SOURCE_DEVICE, result); | |
| 342 } | |
| 343 { | |
| 344 Source result = SOURCE_UNKNOWN; | |
| 345 EXPECT_TRUE(StringToSource(SourceToString(SOURCE_NETWORK), &result)); | |
| 346 EXPECT_EQ(SOURCE_NETWORK, result); | |
| 347 } | |
| 348 { | |
| 349 Source result = SOURCE_FILE; | |
| 350 EXPECT_TRUE(StringToSource(SourceToString(SOURCE_UNKNOWN), &result)); | |
| 351 EXPECT_EQ(SOURCE_UNKNOWN, result); | |
| 352 } | |
| 353 } | |
| 354 | |
| 355 } // namespace file_system_provider | 319 } // namespace file_system_provider |
| 356 } // namespace chromeos | 320 } // namespace chromeos |
| OLD | NEW |