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 <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | |
10 #include <vector> | 9 #include <vector> |
11 | 10 |
12 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
13 #include "base/memory/ptr_util.h" | |
14 #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" |
15 #include "chrome/common/extensions/api/file_system_provider_capabilities/file_sy
stem_provider_capabilities_handler.h" | 13 #include "chrome/common/extensions/api/file_system_provider_capabilities/file_sy
stem_provider_capabilities_handler.h" |
16 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
17 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
18 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
19 #include "chrome/test/base/testing_profile_manager.h" | 17 #include "chrome/test/base/testing_profile_manager.h" |
20 #include "components/sync_preferences/testing_pref_service_syncable.h" | 18 #include "components/sync_preferences/testing_pref_service_syncable.h" |
21 #include "components/user_prefs/user_prefs.h" | 19 #include "components/user_prefs/user_prefs.h" |
22 #include "content/public/test/test_browser_thread_bundle.h" | 20 #include "content/public/test/test_browser_thread_bundle.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 26 matching lines...) Expand all Loading... |
50 bool supports_notify_tag, | 48 bool supports_notify_tag, |
51 int opened_files_limit, | 49 int opened_files_limit, |
52 const Watcher& watcher) { | 50 const Watcher& watcher) { |
53 // Warning. Updating this code means that backward compatibility may be | 51 // Warning. Updating this code means that backward compatibility may be |
54 // broken, what is unexpected and should be avoided. | 52 // broken, what is unexpected and should be avoided. |
55 sync_preferences::TestingPrefServiceSyncable* const pref_service = | 53 sync_preferences::TestingPrefServiceSyncable* const pref_service = |
56 profile->GetTestingPrefService(); | 54 profile->GetTestingPrefService(); |
57 ASSERT_TRUE(pref_service); | 55 ASSERT_TRUE(pref_service); |
58 | 56 |
59 base::DictionaryValue extensions; | 57 base::DictionaryValue extensions; |
60 auto file_system = base::MakeUnique<base::DictionaryValue>(); | 58 base::DictionaryValue* const file_systems = new base::DictionaryValue(); |
| 59 base::DictionaryValue* const file_system = new base::DictionaryValue(); |
61 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, | 60 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, |
62 kFileSystemId); | 61 kFileSystemId); |
63 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, kDisplayName); | 62 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, kDisplayName); |
64 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable, writable); | 63 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable, writable); |
65 file_system->SetBooleanWithoutPathExpansion(kPrefKeySupportsNotifyTag, | 64 file_system->SetBooleanWithoutPathExpansion(kPrefKeySupportsNotifyTag, |
66 supports_notify_tag); | 65 supports_notify_tag); |
67 file_system->SetIntegerWithoutPathExpansion(kPrefKeyOpenedFilesLimit, | 66 file_system->SetIntegerWithoutPathExpansion(kPrefKeyOpenedFilesLimit, |
68 opened_files_limit); | 67 opened_files_limit); |
| 68 file_systems->SetWithoutPathExpansion(kFileSystemId, file_system); |
| 69 extensions.SetWithoutPathExpansion(kExtensionId, file_systems); |
69 | 70 |
70 // Remember watchers. | 71 // Remember watchers. |
71 auto watcher_value = base::MakeUnique<base::DictionaryValue>(); | 72 base::DictionaryValue* const watchers = new base::DictionaryValue(); |
| 73 file_system->SetWithoutPathExpansion(kPrefKeyWatchers, watchers); |
| 74 base::DictionaryValue* const watcher_value = new base::DictionaryValue(); |
| 75 watchers->SetWithoutPathExpansion(watcher.entry_path.value(), watcher_value); |
72 watcher_value->SetStringWithoutPathExpansion(kPrefKeyWatcherEntryPath, | 76 watcher_value->SetStringWithoutPathExpansion(kPrefKeyWatcherEntryPath, |
73 watcher.entry_path.value()); | 77 watcher.entry_path.value()); |
74 watcher_value->SetBooleanWithoutPathExpansion(kPrefKeyWatcherRecursive, | 78 watcher_value->SetBooleanWithoutPathExpansion(kPrefKeyWatcherRecursive, |
75 watcher.recursive); | 79 watcher.recursive); |
76 watcher_value->SetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, | 80 watcher_value->SetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, |
77 watcher.last_tag); | 81 watcher.last_tag); |
78 auto persistent_origins_value = base::MakeUnique<base::ListValue>(); | 82 base::ListValue* const persistent_origins_value = new base::ListValue(); |
| 83 watcher_value->SetWithoutPathExpansion(kPrefKeyWatcherPersistentOrigins, |
| 84 persistent_origins_value); |
79 for (const auto& subscriber_it : watcher.subscribers) { | 85 for (const auto& subscriber_it : watcher.subscribers) { |
80 if (subscriber_it.second.persistent) | 86 if (subscriber_it.second.persistent) |
81 persistent_origins_value->AppendString(subscriber_it.first.spec()); | 87 persistent_origins_value->AppendString(subscriber_it.first.spec()); |
82 } | 88 } |
83 | 89 |
84 watcher_value->SetWithoutPathExpansion(kPrefKeyWatcherPersistentOrigins, | |
85 std::move(persistent_origins_value)); | |
86 auto watchers = base::MakeUnique<base::DictionaryValue>(); | |
87 watchers->SetWithoutPathExpansion(watcher.entry_path.value(), | |
88 std::move(watcher_value)); | |
89 file_system->SetWithoutPathExpansion(kPrefKeyWatchers, std::move(watchers)); | |
90 auto file_systems = base::MakeUnique<base::DictionaryValue>(); | |
91 file_systems->SetWithoutPathExpansion(kFileSystemId, std::move(file_system)); | |
92 extensions.SetWithoutPathExpansion(kExtensionId, std::move(file_systems)); | |
93 pref_service->Set(prefs::kFileSystemProviderMounted, extensions); | 90 pref_service->Set(prefs::kFileSystemProviderMounted, extensions); |
94 } | 91 } |
95 | 92 |
96 } // namespace | 93 } // namespace |
97 | 94 |
98 class FileSystemProviderRegistryTest : public testing::Test { | 95 class FileSystemProviderRegistryTest : public testing::Test { |
99 protected: | 96 protected: |
100 FileSystemProviderRegistryTest() : profile_(NULL) {} | 97 FileSystemProviderRegistryTest() : profile_(NULL) {} |
101 | 98 |
102 ~FileSystemProviderRegistryTest() override {} | 99 ~FileSystemProviderRegistryTest() override {} |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 fake_watcher_.entry_path.value(), &watcher)); | 314 fake_watcher_.entry_path.value(), &watcher)); |
318 | 315 |
319 std::string last_tag; | 316 std::string last_tag; |
320 EXPECT_TRUE(watcher->GetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, | 317 EXPECT_TRUE(watcher->GetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, |
321 &last_tag)); | 318 &last_tag)); |
322 EXPECT_EQ(fake_watcher_.last_tag, last_tag); | 319 EXPECT_EQ(fake_watcher_.last_tag, last_tag); |
323 } | 320 } |
324 | 321 |
325 } // namespace file_system_provider | 322 } // namespace file_system_provider |
326 } // namespace chromeos | 323 } // namespace chromeos |
OLD | NEW |