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