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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 | 224 |
207 bool recursive = false; | 225 bool recursive = false; |
208 EXPECT_TRUE(observed_entry->GetBooleanWithoutPathExpansion( | 226 EXPECT_TRUE(observed_entry->GetBooleanWithoutPathExpansion( |
209 kPrefKeyObservedEntryRecursive, &recursive)); | 227 kPrefKeyObservedEntryRecursive, &recursive)); |
210 EXPECT_EQ(fake_observed_entry_.recursive, recursive); | 228 EXPECT_EQ(fake_observed_entry_.recursive, recursive); |
211 | 229 |
212 std::string last_tag; | 230 std::string last_tag; |
213 EXPECT_TRUE(observed_entry->GetStringWithoutPathExpansion( | 231 EXPECT_TRUE(observed_entry->GetStringWithoutPathExpansion( |
214 kPrefKeyObservedEntryLastTag, &last_tag)); | 232 kPrefKeyObservedEntryLastTag, &last_tag)); |
215 EXPECT_EQ(fake_observed_entry_.last_tag, last_tag); | 233 EXPECT_EQ(fake_observed_entry_.last_tag, last_tag); |
| 234 |
| 235 const base::ListValue* persistent_origins = NULL; |
| 236 ASSERT_TRUE(observed_entry->GetListWithoutPathExpansion( |
| 237 kPrefKeyObservedEntryPersistentOrigins, &persistent_origins)); |
| 238 ASSERT_GT(fake_observed_entry_.subscribers.size(), |
| 239 persistent_origins->GetSize()); |
| 240 ASSERT_EQ(1u, persistent_origins->GetSize()); |
| 241 std::string persistent_origin; |
| 242 EXPECT_TRUE(persistent_origins->GetString(0, &persistent_origin)); |
| 243 const auto& fake_subscriber_it = |
| 244 fake_observed_entry_.subscribers.find(GURL(persistent_origin)); |
| 245 ASSERT_NE(fake_observed_entry_.subscribers.end(), fake_subscriber_it); |
| 246 EXPECT_TRUE(fake_subscriber_it->second.persistent); |
216 } | 247 } |
217 | 248 |
218 TEST_F(FileSystemProviderRegistryTest, ForgetFileSystem) { | 249 TEST_F(FileSystemProviderRegistryTest, ForgetFileSystem) { |
219 // Create a fake file systems in the preferences. | 250 // Create a fake file systems in the preferences. |
220 RememberFakeFileSystem(profile_, | 251 RememberFakeFileSystem(profile_, |
221 kExtensionId, | 252 kExtensionId, |
222 kFileSystemId, | 253 kFileSystemId, |
223 kDisplayName, | 254 kDisplayName, |
224 true /* writable */, | 255 true /* writable */, |
225 true /* supports_notify_tag */, | 256 true /* supports_notify_tag */, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 ASSERT_TRUE(extensions->GetDictionaryWithoutPathExpansion(kExtensionId, | 299 ASSERT_TRUE(extensions->GetDictionaryWithoutPathExpansion(kExtensionId, |
269 &file_systems)); | 300 &file_systems)); |
270 EXPECT_EQ(1u, file_systems->size()); | 301 EXPECT_EQ(1u, file_systems->size()); |
271 | 302 |
272 const base::Value* file_system_value = NULL; | 303 const base::Value* file_system_value = NULL; |
273 const base::DictionaryValue* file_system = NULL; | 304 const base::DictionaryValue* file_system = NULL; |
274 ASSERT_TRUE( | 305 ASSERT_TRUE( |
275 file_systems->GetWithoutPathExpansion(kFileSystemId, &file_system_value)); | 306 file_systems->GetWithoutPathExpansion(kFileSystemId, &file_system_value)); |
276 ASSERT_TRUE(file_system_value->GetAsDictionary(&file_system)); | 307 ASSERT_TRUE(file_system_value->GetAsDictionary(&file_system)); |
277 | 308 |
278 std::string file_system_id; | |
279 EXPECT_TRUE(file_system->GetStringWithoutPathExpansion(kPrefKeyFileSystemId, | |
280 &file_system_id)); | |
281 EXPECT_EQ(kFileSystemId, file_system_id); | |
282 | |
283 std::string display_name; | |
284 EXPECT_TRUE(file_system->GetStringWithoutPathExpansion(kPrefKeyDisplayName, | |
285 &display_name)); | |
286 EXPECT_EQ(kDisplayName, display_name); | |
287 | |
288 bool writable = false; | |
289 EXPECT_TRUE( | |
290 file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable, &writable)); | |
291 EXPECT_TRUE(writable); | |
292 | |
293 bool supports_notify_tag = false; | |
294 EXPECT_TRUE(file_system->GetBooleanWithoutPathExpansion( | |
295 kPrefKeySupportsNotifyTag, &supports_notify_tag)); | |
296 EXPECT_TRUE(supports_notify_tag); | |
297 | |
298 const base::DictionaryValue* observed_entries_value = NULL; | 309 const base::DictionaryValue* observed_entries_value = NULL; |
299 ASSERT_TRUE(file_system->GetDictionaryWithoutPathExpansion( | 310 ASSERT_TRUE(file_system->GetDictionaryWithoutPathExpansion( |
300 kPrefKeyObservedEntries, &observed_entries_value)); | 311 kPrefKeyObservedEntries, &observed_entries_value)); |
301 | 312 |
302 const base::DictionaryValue* observed_entry = NULL; | 313 const base::DictionaryValue* observed_entry = NULL; |
303 ASSERT_TRUE(observed_entries_value->GetDictionaryWithoutPathExpansion( | 314 ASSERT_TRUE(observed_entries_value->GetDictionaryWithoutPathExpansion( |
304 fake_observed_entry_.entry_path.value(), &observed_entry)); | 315 fake_observed_entry_.entry_path.value(), &observed_entry)); |
305 | 316 |
306 std::string entry_path; | |
307 EXPECT_TRUE(observed_entry->GetStringWithoutPathExpansion( | |
308 kPrefKeyObservedEntryEntryPath, &entry_path)); | |
309 EXPECT_EQ(fake_observed_entry_.entry_path.value(), entry_path); | |
310 | |
311 bool recursive = false; | |
312 EXPECT_TRUE(observed_entry->GetBooleanWithoutPathExpansion( | |
313 kPrefKeyObservedEntryRecursive, &recursive)); | |
314 EXPECT_EQ(fake_observed_entry_.recursive, recursive); | |
315 | |
316 std::string last_tag; | 317 std::string last_tag; |
317 EXPECT_TRUE(observed_entry->GetStringWithoutPathExpansion( | 318 EXPECT_TRUE(observed_entry->GetStringWithoutPathExpansion( |
318 kPrefKeyObservedEntryLastTag, &last_tag)); | 319 kPrefKeyObservedEntryLastTag, &last_tag)); |
319 EXPECT_EQ(fake_observed_entry_.last_tag, last_tag); | 320 EXPECT_EQ(fake_observed_entry_.last_tag, last_tag); |
320 } | 321 } |
321 | 322 |
322 } // namespace file_system_provider | 323 } // namespace file_system_provider |
323 } // namespace chromeos | 324 } // namespace chromeos |
OLD | NEW |