| 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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" | 12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" |
| 13 #include "chrome/browser/chromeos/file_system_provider/registry.h" | |
| 14 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/test/base/testing_browser_process.h" | 14 #include "chrome/test/base/testing_browser_process.h" |
| 16 #include "chrome/test/base/testing_pref_service_syncable.h" | 15 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 18 #include "chrome/test/base/testing_profile_manager.h" | 17 #include "chrome/test/base/testing_profile_manager.h" |
| 19 #include "components/user_prefs/user_prefs.h" | 18 #include "components/user_prefs/user_prefs.h" |
| 20 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 21 |
| 23 namespace chromeos { | 22 namespace chromeos { |
| 24 namespace file_system_provider { | 23 namespace file_system_provider { |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 26 const char kTemporaryOrigin[] = |
| 27 "chrome-extension://abcabcabcabcabcabcabcabcabcabcabcabca/"; |
| 28 const char kPersistentOrigin[] = |
| 29 "chrome-extension://efgefgefgefgefgefgefgefgefgefgefgefge/"; |
| 27 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; | 30 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; |
| 28 const char kDisplayName[] = "Camera Pictures"; | 31 const char kDisplayName[] = "Camera Pictures"; |
| 29 | 32 |
| 30 // 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 |
| 31 // 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 |
| 32 // 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. |
| 33 const char kFileSystemId[] = "camera/pictures/id .!@#$%^&*()_+"; | 36 const char kFileSystemId[] = "camera/pictures/id .!@#$%^&*()_+"; |
| 34 | 37 |
| 35 // Stores a provided file system information in preferences together with a | 38 // Stores a provided file system information in preferences together with a |
| 36 // fake observed entry. | 39 // fake observed entry. |
| 37 void RememberFakeFileSystem(TestingProfile* profile, | 40 void RememberFakeFileSystem(TestingProfile* profile, |
| 38 const std::string& extension_id, | 41 const std::string& extension_id, |
| 39 const std::string& file_system_id, | 42 const std::string& file_system_id, |
| 40 const std::string& display_name, | 43 const std::string& display_name, |
| 41 bool writable, | 44 bool writable, |
| 42 bool supports_notify_tag, | 45 bool supports_notify_tag, |
| 43 const ObservedEntry& observed_entry) { | 46 const ObservedEntry& observed_entry) { |
| 47 // Warning. Updating this code means that backward compatibility may be |
| 48 // broken, what is unexpected and should be avoided. |
| 44 TestingPrefServiceSyncable* const pref_service = | 49 TestingPrefServiceSyncable* const pref_service = |
| 45 profile->GetTestingPrefService(); | 50 profile->GetTestingPrefService(); |
| 46 ASSERT_TRUE(pref_service); | 51 ASSERT_TRUE(pref_service); |
| 47 | 52 |
| 48 base::DictionaryValue extensions; | 53 base::DictionaryValue extensions; |
| 49 base::DictionaryValue* const file_systems = new base::DictionaryValue(); | 54 base::DictionaryValue* const file_systems = new base::DictionaryValue(); |
| 50 base::DictionaryValue* const file_system = new base::DictionaryValue(); | 55 base::DictionaryValue* const file_system = new base::DictionaryValue(); |
| 51 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, | 56 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, |
| 52 kFileSystemId); | 57 kFileSystemId); |
| 53 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, kDisplayName); | 58 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, kDisplayName); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 64 base::DictionaryValue* const observed_entry_value = | 69 base::DictionaryValue* const observed_entry_value = |
| 65 new base::DictionaryValue(); | 70 new base::DictionaryValue(); |
| 66 observed_entries->SetWithoutPathExpansion(observed_entry.entry_path.value(), | 71 observed_entries->SetWithoutPathExpansion(observed_entry.entry_path.value(), |
| 67 observed_entry_value); | 72 observed_entry_value); |
| 68 observed_entry_value->SetStringWithoutPathExpansion( | 73 observed_entry_value->SetStringWithoutPathExpansion( |
| 69 kPrefKeyObservedEntryEntryPath, observed_entry.entry_path.value()); | 74 kPrefKeyObservedEntryEntryPath, observed_entry.entry_path.value()); |
| 70 observed_entry_value->SetBooleanWithoutPathExpansion( | 75 observed_entry_value->SetBooleanWithoutPathExpansion( |
| 71 kPrefKeyObservedEntryRecursive, observed_entry.recursive); | 76 kPrefKeyObservedEntryRecursive, observed_entry.recursive); |
| 72 observed_entry_value->SetStringWithoutPathExpansion( | 77 observed_entry_value->SetStringWithoutPathExpansion( |
| 73 kPrefKeyObservedEntryLastTag, observed_entry.last_tag); | 78 kPrefKeyObservedEntryLastTag, observed_entry.last_tag); |
| 79 base::ListValue* const persistent_origins_value = new base::ListValue(); |
| 80 observed_entry_value->SetWithoutPathExpansion( |
| 81 kPrefKeyObservedEntryPersistentOrigins, persistent_origins_value); |
| 82 for (const auto& subscriber_it : observed_entry.subscribers) { |
| 83 if (subscriber_it.second.persistent) |
| 84 persistent_origins_value->AppendString(subscriber_it.first.spec()); |
| 85 } |
| 74 | 86 |
| 75 pref_service->Set(prefs::kFileSystemProviderMounted, extensions); | 87 pref_service->Set(prefs::kFileSystemProviderMounted, extensions); |
| 76 } | 88 } |
| 77 | 89 |
| 78 } // namespace | 90 } // namespace |
| 79 | 91 |
| 80 class FileSystemProviderRegistryTest : public testing::Test { | 92 class FileSystemProviderRegistryTest : public testing::Test { |
| 81 protected: | 93 protected: |
| 82 FileSystemProviderRegistryTest() : profile_(NULL) {} | 94 FileSystemProviderRegistryTest() : profile_(NULL) {} |
| 83 | 95 |
| 84 virtual ~FileSystemProviderRegistryTest() {} | 96 virtual ~FileSystemProviderRegistryTest() {} |
| 85 | 97 |
| 86 virtual void SetUp() override { | 98 virtual void SetUp() override { |
| 87 profile_manager_.reset( | 99 profile_manager_.reset( |
| 88 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 100 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
| 89 ASSERT_TRUE(profile_manager_->SetUp()); | 101 ASSERT_TRUE(profile_manager_->SetUp()); |
| 90 profile_ = profile_manager_->CreateTestingProfile("test-user@example.com"); | 102 profile_ = profile_manager_->CreateTestingProfile("test-user@example.com"); |
| 91 registry_.reset(new Registry(profile_)); | 103 registry_.reset(new Registry(profile_)); |
| 92 fake_observed_entry_.entry_path = | 104 fake_observed_entry_.entry_path = |
| 93 base::FilePath(FILE_PATH_LITERAL("/a/b/c")); | 105 base::FilePath(FILE_PATH_LITERAL("/a/b/c")); |
| 94 fake_observed_entry_.recursive = true; | 106 fake_observed_entry_.recursive = true; |
| 107 fake_observed_entry_.subscribers[GURL(kTemporaryOrigin)].origin = |
| 108 GURL(kTemporaryOrigin); |
| 109 fake_observed_entry_.subscribers[GURL(kTemporaryOrigin)].persistent = false; |
| 110 fake_observed_entry_.subscribers[GURL(kPersistentOrigin)].origin = |
| 111 GURL(kPersistentOrigin); |
| 112 fake_observed_entry_.subscribers[GURL(kPersistentOrigin)].persistent = true; |
| 95 fake_observed_entry_.last_tag = "hello-world"; | 113 fake_observed_entry_.last_tag = "hello-world"; |
| 96 } | 114 } |
| 97 | 115 |
| 98 content::TestBrowserThreadBundle thread_bundle_; | 116 content::TestBrowserThreadBundle thread_bundle_; |
| 99 scoped_ptr<TestingProfileManager> profile_manager_; | 117 scoped_ptr<TestingProfileManager> profile_manager_; |
| 100 TestingProfile* profile_; | 118 TestingProfile* profile_; |
| 101 scoped_ptr<RegistryInterface> registry_; | 119 scoped_ptr<RegistryInterface> registry_; |
| 102 ObservedEntry fake_observed_entry_; | 120 ObservedEntry fake_observed_entry_; |
| 103 }; | 121 }; |
| 104 | 122 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 226 |
| 209 bool recursive = false; | 227 bool recursive = false; |
| 210 EXPECT_TRUE(observed_entry->GetBooleanWithoutPathExpansion( | 228 EXPECT_TRUE(observed_entry->GetBooleanWithoutPathExpansion( |
| 211 kPrefKeyObservedEntryRecursive, &recursive)); | 229 kPrefKeyObservedEntryRecursive, &recursive)); |
| 212 EXPECT_EQ(fake_observed_entry_.recursive, recursive); | 230 EXPECT_EQ(fake_observed_entry_.recursive, recursive); |
| 213 | 231 |
| 214 std::string last_tag; | 232 std::string last_tag; |
| 215 EXPECT_TRUE(observed_entry->GetStringWithoutPathExpansion( | 233 EXPECT_TRUE(observed_entry->GetStringWithoutPathExpansion( |
| 216 kPrefKeyObservedEntryLastTag, &last_tag)); | 234 kPrefKeyObservedEntryLastTag, &last_tag)); |
| 217 EXPECT_EQ(fake_observed_entry_.last_tag, last_tag); | 235 EXPECT_EQ(fake_observed_entry_.last_tag, last_tag); |
| 236 |
| 237 const base::ListValue* persistent_origins = NULL; |
| 238 ASSERT_TRUE(observed_entry->GetListWithoutPathExpansion( |
| 239 kPrefKeyObservedEntryPersistentOrigins, &persistent_origins)); |
| 240 ASSERT_GT(fake_observed_entry_.subscribers.size(), |
| 241 persistent_origins->GetSize()); |
| 242 ASSERT_EQ(1u, persistent_origins->GetSize()); |
| 243 std::string persistent_origin; |
| 244 EXPECT_TRUE(persistent_origins->GetString(0, &persistent_origin)); |
| 245 const auto& fake_subscriber_it = |
| 246 fake_observed_entry_.subscribers.find(GURL(persistent_origin)); |
| 247 ASSERT_NE(fake_observed_entry_.subscribers.end(), fake_subscriber_it); |
| 248 EXPECT_TRUE(fake_subscriber_it->second.persistent); |
| 218 } | 249 } |
| 219 | 250 |
| 220 TEST_F(FileSystemProviderRegistryTest, ForgetFileSystem) { | 251 TEST_F(FileSystemProviderRegistryTest, ForgetFileSystem) { |
| 221 // Create a fake file systems in the preferences. | 252 // Create a fake file systems in the preferences. |
| 222 RememberFakeFileSystem(profile_, | 253 RememberFakeFileSystem(profile_, |
| 223 kExtensionId, | 254 kExtensionId, |
| 224 kFileSystemId, | 255 kFileSystemId, |
| 225 kDisplayName, | 256 kDisplayName, |
| 226 true /* writable */, | 257 true /* writable */, |
| 227 true /* supports_notify_tag */, | 258 true /* supports_notify_tag */, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 ASSERT_TRUE(extensions->GetDictionaryWithoutPathExpansion(kExtensionId, | 303 ASSERT_TRUE(extensions->GetDictionaryWithoutPathExpansion(kExtensionId, |
| 273 &file_systems)); | 304 &file_systems)); |
| 274 EXPECT_EQ(1u, file_systems->size()); | 305 EXPECT_EQ(1u, file_systems->size()); |
| 275 | 306 |
| 276 const base::Value* file_system_value = NULL; | 307 const base::Value* file_system_value = NULL; |
| 277 const base::DictionaryValue* file_system = NULL; | 308 const base::DictionaryValue* file_system = NULL; |
| 278 ASSERT_TRUE( | 309 ASSERT_TRUE( |
| 279 file_systems->GetWithoutPathExpansion(kFileSystemId, &file_system_value)); | 310 file_systems->GetWithoutPathExpansion(kFileSystemId, &file_system_value)); |
| 280 ASSERT_TRUE(file_system_value->GetAsDictionary(&file_system)); | 311 ASSERT_TRUE(file_system_value->GetAsDictionary(&file_system)); |
| 281 | 312 |
| 282 std::string file_system_id; | |
| 283 EXPECT_TRUE(file_system->GetStringWithoutPathExpansion(kPrefKeyFileSystemId, | |
| 284 &file_system_id)); | |
| 285 EXPECT_EQ(kFileSystemId, file_system_id); | |
| 286 | |
| 287 std::string display_name; | |
| 288 EXPECT_TRUE(file_system->GetStringWithoutPathExpansion(kPrefKeyDisplayName, | |
| 289 &display_name)); | |
| 290 EXPECT_EQ(kDisplayName, display_name); | |
| 291 | |
| 292 bool writable = false; | |
| 293 EXPECT_TRUE( | |
| 294 file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable, &writable)); | |
| 295 EXPECT_TRUE(writable); | |
| 296 | |
| 297 bool supports_notify_tag = false; | |
| 298 EXPECT_TRUE(file_system->GetBooleanWithoutPathExpansion( | |
| 299 kPrefKeySupportsNotifyTag, &supports_notify_tag)); | |
| 300 EXPECT_TRUE(supports_notify_tag); | |
| 301 | |
| 302 const base::DictionaryValue* observed_entries_value = NULL; | 313 const base::DictionaryValue* observed_entries_value = NULL; |
| 303 ASSERT_TRUE(file_system->GetDictionaryWithoutPathExpansion( | 314 ASSERT_TRUE(file_system->GetDictionaryWithoutPathExpansion( |
| 304 kPrefKeyObservedEntries, &observed_entries_value)); | 315 kPrefKeyObservedEntries, &observed_entries_value)); |
| 305 | 316 |
| 306 const base::DictionaryValue* observed_entry = NULL; | 317 const base::DictionaryValue* observed_entry = NULL; |
| 307 ASSERT_TRUE(observed_entries_value->GetDictionaryWithoutPathExpansion( | 318 ASSERT_TRUE(observed_entries_value->GetDictionaryWithoutPathExpansion( |
| 308 fake_observed_entry_.entry_path.value(), &observed_entry)); | 319 fake_observed_entry_.entry_path.value(), &observed_entry)); |
| 309 | 320 |
| 310 std::string entry_path; | |
| 311 EXPECT_TRUE(observed_entry->GetStringWithoutPathExpansion( | |
| 312 kPrefKeyObservedEntryEntryPath, &entry_path)); | |
| 313 EXPECT_EQ(fake_observed_entry_.entry_path.value(), entry_path); | |
| 314 | |
| 315 bool recursive = false; | |
| 316 EXPECT_TRUE(observed_entry->GetBooleanWithoutPathExpansion( | |
| 317 kPrefKeyObservedEntryRecursive, &recursive)); | |
| 318 EXPECT_EQ(fake_observed_entry_.recursive, recursive); | |
| 319 | |
| 320 std::string last_tag; | 321 std::string last_tag; |
| 321 EXPECT_TRUE(observed_entry->GetStringWithoutPathExpansion( | 322 EXPECT_TRUE(observed_entry->GetStringWithoutPathExpansion( |
| 322 kPrefKeyObservedEntryLastTag, &last_tag)); | 323 kPrefKeyObservedEntryLastTag, &last_tag)); |
| 323 EXPECT_EQ(fake_observed_entry_.last_tag, last_tag); | 324 EXPECT_EQ(fake_observed_entry_.last_tag, last_tag); |
| 324 } | 325 } |
| 325 | 326 |
| 326 } // namespace file_system_provider | 327 } // namespace file_system_provider |
| 327 } // namespace chromeos | 328 } // namespace chromeos |
| OLD | NEW |