| 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 17 matching lines...) Expand all Loading... |
| 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 | 32 |
| 33 // 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 |
| 34 // 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 |
| 35 // 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. |
| 36 const char kFileSystemId[] = "camera/pictures/id .!@#$%^&*()_+"; | 36 const char kFileSystemId[] = "camera/pictures/id .!@#$%^&*()_+"; |
| 37 | 37 |
| 38 const int kOpenedFilesLimit = 5; |
| 39 |
| 38 // Stores a provided file system information in preferences together with a | 40 // Stores a provided file system information in preferences together with a |
| 39 // fake watcher. | 41 // fake watcher. |
| 40 void RememberFakeFileSystem(TestingProfile* profile, | 42 void RememberFakeFileSystem(TestingProfile* profile, |
| 41 const std::string& extension_id, | 43 const std::string& extension_id, |
| 42 const std::string& file_system_id, | 44 const std::string& file_system_id, |
| 43 const std::string& display_name, | 45 const std::string& display_name, |
| 44 bool writable, | 46 bool writable, |
| 45 bool supports_notify_tag, | 47 bool supports_notify_tag, |
| 48 int opened_files_limit, |
| 46 const Watcher& watcher) { | 49 const Watcher& watcher) { |
| 47 // Warning. Updating this code means that backward compatibility may be | 50 // Warning. Updating this code means that backward compatibility may be |
| 48 // broken, what is unexpected and should be avoided. | 51 // broken, what is unexpected and should be avoided. |
| 49 TestingPrefServiceSyncable* const pref_service = | 52 TestingPrefServiceSyncable* const pref_service = |
| 50 profile->GetTestingPrefService(); | 53 profile->GetTestingPrefService(); |
| 51 ASSERT_TRUE(pref_service); | 54 ASSERT_TRUE(pref_service); |
| 52 | 55 |
| 53 base::DictionaryValue extensions; | 56 base::DictionaryValue extensions; |
| 54 base::DictionaryValue* const file_systems = new base::DictionaryValue(); | 57 base::DictionaryValue* const file_systems = new base::DictionaryValue(); |
| 55 base::DictionaryValue* const file_system = new base::DictionaryValue(); | 58 base::DictionaryValue* const file_system = new base::DictionaryValue(); |
| 56 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, | 59 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, |
| 57 kFileSystemId); | 60 kFileSystemId); |
| 58 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, kDisplayName); | 61 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, kDisplayName); |
| 59 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable, writable); | 62 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable, writable); |
| 60 file_system->SetBooleanWithoutPathExpansion(kPrefKeySupportsNotifyTag, | 63 file_system->SetBooleanWithoutPathExpansion(kPrefKeySupportsNotifyTag, |
| 61 supports_notify_tag); | 64 supports_notify_tag); |
| 65 file_system->SetIntegerWithoutPathExpansion(kPrefKeyOpenedFilesLimit, |
| 66 opened_files_limit); |
| 62 file_systems->SetWithoutPathExpansion(kFileSystemId, file_system); | 67 file_systems->SetWithoutPathExpansion(kFileSystemId, file_system); |
| 63 extensions.SetWithoutPathExpansion(kExtensionId, file_systems); | 68 extensions.SetWithoutPathExpansion(kExtensionId, file_systems); |
| 64 | 69 |
| 65 // Remember watchers. | 70 // Remember watchers. |
| 66 base::DictionaryValue* const watchers = new base::DictionaryValue(); | 71 base::DictionaryValue* const watchers = new base::DictionaryValue(); |
| 67 file_system->SetWithoutPathExpansion(kPrefKeyWatchers, watchers); | 72 file_system->SetWithoutPathExpansion(kPrefKeyWatchers, watchers); |
| 68 base::DictionaryValue* const watcher_value = new base::DictionaryValue(); | 73 base::DictionaryValue* const watcher_value = new base::DictionaryValue(); |
| 69 watchers->SetWithoutPathExpansion(watcher.entry_path.value(), watcher_value); | 74 watchers->SetWithoutPathExpansion(watcher.entry_path.value(), watcher_value); |
| 70 watcher_value->SetStringWithoutPathExpansion(kPrefKeyWatcherEntryPath, | 75 watcher_value->SetStringWithoutPathExpansion(kPrefKeyWatcherEntryPath, |
| 71 watcher.entry_path.value()); | 76 watcher.entry_path.value()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 116 |
| 112 content::TestBrowserThreadBundle thread_bundle_; | 117 content::TestBrowserThreadBundle thread_bundle_; |
| 113 scoped_ptr<TestingProfileManager> profile_manager_; | 118 scoped_ptr<TestingProfileManager> profile_manager_; |
| 114 TestingProfile* profile_; | 119 TestingProfile* profile_; |
| 115 scoped_ptr<RegistryInterface> registry_; | 120 scoped_ptr<RegistryInterface> registry_; |
| 116 Watcher fake_watcher_; | 121 Watcher fake_watcher_; |
| 117 }; | 122 }; |
| 118 | 123 |
| 119 TEST_F(FileSystemProviderRegistryTest, RestoreFileSystems) { | 124 TEST_F(FileSystemProviderRegistryTest, RestoreFileSystems) { |
| 120 // Create a fake entry in the preferences. | 125 // Create a fake entry in the preferences. |
| 121 RememberFakeFileSystem(profile_, | 126 RememberFakeFileSystem(profile_, kExtensionId, kFileSystemId, kDisplayName, |
| 122 kExtensionId, | 127 true /* writable */, true /* supports_notify_tag */, |
| 123 kFileSystemId, | 128 kOpenedFilesLimit, fake_watcher_); |
| 124 kDisplayName, | |
| 125 true /* writable */, | |
| 126 true /* supports_notify_tag */, | |
| 127 fake_watcher_); | |
| 128 | 129 |
| 129 scoped_ptr<RegistryInterface::RestoredFileSystems> restored_file_systems = | 130 scoped_ptr<RegistryInterface::RestoredFileSystems> restored_file_systems = |
| 130 registry_->RestoreFileSystems(kExtensionId); | 131 registry_->RestoreFileSystems(kExtensionId); |
| 131 | 132 |
| 132 ASSERT_EQ(1u, restored_file_systems->size()); | 133 ASSERT_EQ(1u, restored_file_systems->size()); |
| 133 const RegistryInterface::RestoredFileSystem& restored_file_system = | 134 const RegistryInterface::RestoredFileSystem& restored_file_system = |
| 134 restored_file_systems->at(0); | 135 restored_file_systems->at(0); |
| 135 EXPECT_EQ(kExtensionId, restored_file_system.extension_id); | 136 EXPECT_EQ(kExtensionId, restored_file_system.extension_id); |
| 136 EXPECT_EQ(kFileSystemId, restored_file_system.options.file_system_id); | 137 EXPECT_EQ(kFileSystemId, restored_file_system.options.file_system_id); |
| 137 EXPECT_EQ(kDisplayName, restored_file_system.options.display_name); | 138 EXPECT_EQ(kDisplayName, restored_file_system.options.display_name); |
| 138 EXPECT_TRUE(restored_file_system.options.writable); | 139 EXPECT_TRUE(restored_file_system.options.writable); |
| 139 EXPECT_TRUE(restored_file_system.options.supports_notify_tag); | 140 EXPECT_TRUE(restored_file_system.options.supports_notify_tag); |
| 141 EXPECT_EQ(kOpenedFilesLimit, restored_file_system.options.opened_files_limit); |
| 140 | 142 |
| 141 ASSERT_EQ(1u, restored_file_system.watchers.size()); | 143 ASSERT_EQ(1u, restored_file_system.watchers.size()); |
| 142 const auto& restored_watcher_it = restored_file_system.watchers.find( | 144 const auto& restored_watcher_it = restored_file_system.watchers.find( |
| 143 WatcherKey(fake_watcher_.entry_path, fake_watcher_.recursive)); | 145 WatcherKey(fake_watcher_.entry_path, fake_watcher_.recursive)); |
| 144 ASSERT_NE(restored_file_system.watchers.end(), restored_watcher_it); | 146 ASSERT_NE(restored_file_system.watchers.end(), restored_watcher_it); |
| 145 | 147 |
| 146 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); |
| 147 EXPECT_EQ(fake_watcher_.recursive, restored_watcher_it->second.recursive); | 149 EXPECT_EQ(fake_watcher_.recursive, restored_watcher_it->second.recursive); |
| 148 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); |
| 149 } | 151 } |
| 150 | 152 |
| 151 TEST_F(FileSystemProviderRegistryTest, RememberFileSystem) { | 153 TEST_F(FileSystemProviderRegistryTest, RememberFileSystem) { |
| 152 MountOptions options(kFileSystemId, kDisplayName); | 154 MountOptions options(kFileSystemId, kDisplayName); |
| 153 options.writable = true; | 155 options.writable = true; |
| 154 options.supports_notify_tag = true; | 156 options.supports_notify_tag = true; |
| 157 options.opened_files_limit = kOpenedFilesLimit; |
| 155 | 158 |
| 156 ProvidedFileSystemInfo file_system_info( | 159 ProvidedFileSystemInfo file_system_info( |
| 157 kExtensionId, options, base::FilePath(FILE_PATH_LITERAL("/a/b/c"))); | 160 kExtensionId, options, base::FilePath(FILE_PATH_LITERAL("/a/b/c"))); |
| 158 | 161 |
| 159 Watchers watchers; | 162 Watchers watchers; |
| 160 watchers[WatcherKey(fake_watcher_.entry_path, fake_watcher_.recursive)] = | 163 watchers[WatcherKey(fake_watcher_.entry_path, fake_watcher_.recursive)] = |
| 161 fake_watcher_; | 164 fake_watcher_; |
| 162 | 165 |
| 163 registry_->RememberFileSystem(file_system_info, watchers); | 166 registry_->RememberFileSystem(file_system_info, watchers); |
| 164 | 167 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 194 bool writable = false; | 197 bool writable = false; |
| 195 EXPECT_TRUE( | 198 EXPECT_TRUE( |
| 196 file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable, &writable)); | 199 file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable, &writable)); |
| 197 EXPECT_TRUE(writable); | 200 EXPECT_TRUE(writable); |
| 198 | 201 |
| 199 bool supports_notify_tag = false; | 202 bool supports_notify_tag = false; |
| 200 EXPECT_TRUE(file_system->GetBooleanWithoutPathExpansion( | 203 EXPECT_TRUE(file_system->GetBooleanWithoutPathExpansion( |
| 201 kPrefKeySupportsNotifyTag, &supports_notify_tag)); | 204 kPrefKeySupportsNotifyTag, &supports_notify_tag)); |
| 202 EXPECT_TRUE(supports_notify_tag); | 205 EXPECT_TRUE(supports_notify_tag); |
| 203 | 206 |
| 207 int opened_files_limit = 0; |
| 208 EXPECT_TRUE(file_system->GetIntegerWithoutPathExpansion( |
| 209 kPrefKeyOpenedFilesLimit, &opened_files_limit)); |
| 210 EXPECT_EQ(kOpenedFilesLimit, opened_files_limit); |
| 211 |
| 204 const base::DictionaryValue* watchers_value = NULL; | 212 const base::DictionaryValue* watchers_value = NULL; |
| 205 ASSERT_TRUE(file_system->GetDictionaryWithoutPathExpansion(kPrefKeyWatchers, | 213 ASSERT_TRUE(file_system->GetDictionaryWithoutPathExpansion(kPrefKeyWatchers, |
| 206 &watchers_value)); | 214 &watchers_value)); |
| 207 | 215 |
| 208 const base::DictionaryValue* watcher = NULL; | 216 const base::DictionaryValue* watcher = NULL; |
| 209 ASSERT_TRUE(watchers_value->GetDictionaryWithoutPathExpansion( | 217 ASSERT_TRUE(watchers_value->GetDictionaryWithoutPathExpansion( |
| 210 fake_watcher_.entry_path.value(), &watcher)); | 218 fake_watcher_.entry_path.value(), &watcher)); |
| 211 | 219 |
| 212 std::string entry_path; | 220 std::string entry_path; |
| 213 EXPECT_TRUE(watcher->GetStringWithoutPathExpansion(kPrefKeyWatcherEntryPath, | 221 EXPECT_TRUE(watcher->GetStringWithoutPathExpansion(kPrefKeyWatcherEntryPath, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 232 std::string persistent_origin; | 240 std::string persistent_origin; |
| 233 EXPECT_TRUE(persistent_origins->GetString(0, &persistent_origin)); | 241 EXPECT_TRUE(persistent_origins->GetString(0, &persistent_origin)); |
| 234 const auto& fake_subscriber_it = | 242 const auto& fake_subscriber_it = |
| 235 fake_watcher_.subscribers.find(GURL(persistent_origin)); | 243 fake_watcher_.subscribers.find(GURL(persistent_origin)); |
| 236 ASSERT_NE(fake_watcher_.subscribers.end(), fake_subscriber_it); | 244 ASSERT_NE(fake_watcher_.subscribers.end(), fake_subscriber_it); |
| 237 EXPECT_TRUE(fake_subscriber_it->second.persistent); | 245 EXPECT_TRUE(fake_subscriber_it->second.persistent); |
| 238 } | 246 } |
| 239 | 247 |
| 240 TEST_F(FileSystemProviderRegistryTest, ForgetFileSystem) { | 248 TEST_F(FileSystemProviderRegistryTest, ForgetFileSystem) { |
| 241 // Create a fake file systems in the preferences. | 249 // Create a fake file systems in the preferences. |
| 242 RememberFakeFileSystem(profile_, | 250 RememberFakeFileSystem(profile_, kExtensionId, kFileSystemId, kDisplayName, |
| 243 kExtensionId, | 251 true /* writable */, true /* supports_notify_tag */, |
| 244 kFileSystemId, | 252 kOpenedFilesLimit, fake_watcher_); |
| 245 kDisplayName, | |
| 246 true /* writable */, | |
| 247 true /* supports_notify_tag */, | |
| 248 fake_watcher_); | |
| 249 | 253 |
| 250 registry_->ForgetFileSystem(kExtensionId, kFileSystemId); | 254 registry_->ForgetFileSystem(kExtensionId, kFileSystemId); |
| 251 | 255 |
| 252 TestingPrefServiceSyncable* const pref_service = | 256 TestingPrefServiceSyncable* const pref_service = |
| 253 profile_->GetTestingPrefService(); | 257 profile_->GetTestingPrefService(); |
| 254 ASSERT_TRUE(pref_service); | 258 ASSERT_TRUE(pref_service); |
| 255 | 259 |
| 256 const base::DictionaryValue* const extensions = | 260 const base::DictionaryValue* const extensions = |
| 257 pref_service->GetDictionary(prefs::kFileSystemProviderMounted); | 261 pref_service->GetDictionary(prefs::kFileSystemProviderMounted); |
| 258 ASSERT_TRUE(extensions); | 262 ASSERT_TRUE(extensions); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 fake_watcher_.entry_path.value(), &watcher)); | 311 fake_watcher_.entry_path.value(), &watcher)); |
| 308 | 312 |
| 309 std::string last_tag; | 313 std::string last_tag; |
| 310 EXPECT_TRUE(watcher->GetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, | 314 EXPECT_TRUE(watcher->GetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, |
| 311 &last_tag)); | 315 &last_tag)); |
| 312 EXPECT_EQ(fake_watcher_.last_tag, last_tag); | 316 EXPECT_EQ(fake_watcher_.last_tag, last_tag); |
| 313 } | 317 } |
| 314 | 318 |
| 315 } // namespace file_system_provider | 319 } // namespace file_system_provider |
| 316 } // namespace chromeos | 320 } // namespace chromeos |
| OLD | NEW |