Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1108)

Side by Side Diff: chrome/browser/chromeos/file_system_provider/registry_unittest.cc

Issue 1055183003: Add a data source field for volumes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed a typo. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 11 matching lines...) Expand all
22 namespace chromeos { 22 namespace chromeos {
23 namespace file_system_provider { 23 namespace file_system_provider {
24 namespace { 24 namespace {
25 25
26 const char kTemporaryOrigin[] = 26 const char kTemporaryOrigin[] =
27 "chrome-extension://abcabcabcabcabcabcabcabcabcabcabcabca/"; 27 "chrome-extension://abcabcabcabcabcabcabcabcabcabcabcabca/";
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 const Source kSource = SOURCE_NETWORK;
32 33
33 // The dot in the file system ID is there in order to check that saving to 34 // 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 35 // 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. 36 // a base::DictionaryValue, so it has to be stored without path expansion.
36 const char kFileSystemId[] = "camera/pictures/id .!@#$%^&*()_+"; 37 const char kFileSystemId[] = "camera/pictures/id .!@#$%^&*()_+";
37 38
38 const int kOpenedFilesLimit = 5; 39 const int kOpenedFilesLimit = 5;
39 40
40 // Stores a provided file system information in preferences together with a 41 // Stores a provided file system information in preferences together with a
41 // fake watcher. 42 // fake watcher.
42 void RememberFakeFileSystem(TestingProfile* profile, 43 void RememberFakeFileSystem(TestingProfile* profile,
43 const std::string& extension_id, 44 const std::string& extension_id,
44 const std::string& file_system_id, 45 const std::string& file_system_id,
45 const std::string& display_name, 46 const std::string& display_name,
46 bool writable, 47 bool writable,
48 Source source,
47 bool supports_notify_tag, 49 bool supports_notify_tag,
48 int opened_files_limit, 50 int opened_files_limit,
49 const Watcher& watcher) { 51 const Watcher& watcher) {
50 // Warning. Updating this code means that backward compatibility may be 52 // Warning. Updating this code means that backward compatibility may be
51 // broken, what is unexpected and should be avoided. 53 // broken, what is unexpected and should be avoided.
52 TestingPrefServiceSyncable* const pref_service = 54 TestingPrefServiceSyncable* const pref_service =
53 profile->GetTestingPrefService(); 55 profile->GetTestingPrefService();
54 ASSERT_TRUE(pref_service); 56 ASSERT_TRUE(pref_service);
55 57
56 base::DictionaryValue extensions; 58 base::DictionaryValue extensions;
57 base::DictionaryValue* const file_systems = new base::DictionaryValue(); 59 base::DictionaryValue* const file_systems = new base::DictionaryValue();
58 base::DictionaryValue* const file_system = new base::DictionaryValue(); 60 base::DictionaryValue* const file_system = new base::DictionaryValue();
59 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, 61 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId,
60 kFileSystemId); 62 kFileSystemId);
61 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, kDisplayName); 63 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, kDisplayName);
62 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable, writable); 64 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable, writable);
65 file_system->SetStringWithoutPathExpansion(kPrefKeySource,
66 SourceToString(source));
63 file_system->SetBooleanWithoutPathExpansion(kPrefKeySupportsNotifyTag, 67 file_system->SetBooleanWithoutPathExpansion(kPrefKeySupportsNotifyTag,
64 supports_notify_tag); 68 supports_notify_tag);
65 file_system->SetIntegerWithoutPathExpansion(kPrefKeyOpenedFilesLimit, 69 file_system->SetIntegerWithoutPathExpansion(kPrefKeyOpenedFilesLimit,
66 opened_files_limit); 70 opened_files_limit);
67 file_systems->SetWithoutPathExpansion(kFileSystemId, file_system); 71 file_systems->SetWithoutPathExpansion(kFileSystemId, file_system);
68 extensions.SetWithoutPathExpansion(kExtensionId, file_systems); 72 extensions.SetWithoutPathExpansion(kExtensionId, file_systems);
69 73
70 // Remember watchers. 74 // Remember watchers.
71 base::DictionaryValue* const watchers = new base::DictionaryValue(); 75 base::DictionaryValue* const watchers = new base::DictionaryValue();
72 file_system->SetWithoutPathExpansion(kPrefKeyWatchers, watchers); 76 file_system->SetWithoutPathExpansion(kPrefKeyWatchers, watchers);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 content::TestBrowserThreadBundle thread_bundle_; 121 content::TestBrowserThreadBundle thread_bundle_;
118 scoped_ptr<TestingProfileManager> profile_manager_; 122 scoped_ptr<TestingProfileManager> profile_manager_;
119 TestingProfile* profile_; 123 TestingProfile* profile_;
120 scoped_ptr<RegistryInterface> registry_; 124 scoped_ptr<RegistryInterface> registry_;
121 Watcher fake_watcher_; 125 Watcher fake_watcher_;
122 }; 126 };
123 127
124 TEST_F(FileSystemProviderRegistryTest, RestoreFileSystems) { 128 TEST_F(FileSystemProviderRegistryTest, RestoreFileSystems) {
125 // Create a fake entry in the preferences. 129 // Create a fake entry in the preferences.
126 RememberFakeFileSystem(profile_, kExtensionId, kFileSystemId, kDisplayName, 130 RememberFakeFileSystem(profile_, kExtensionId, kFileSystemId, kDisplayName,
127 true /* writable */, true /* supports_notify_tag */, 131 true /* writable */, kSource,
128 kOpenedFilesLimit, fake_watcher_); 132 true /* supports_notify_tag */, kOpenedFilesLimit,
133 fake_watcher_);
129 134
130 scoped_ptr<RegistryInterface::RestoredFileSystems> restored_file_systems = 135 scoped_ptr<RegistryInterface::RestoredFileSystems> restored_file_systems =
131 registry_->RestoreFileSystems(kExtensionId); 136 registry_->RestoreFileSystems(kExtensionId);
132 137
133 ASSERT_EQ(1u, restored_file_systems->size()); 138 ASSERT_EQ(1u, restored_file_systems->size());
134 const RegistryInterface::RestoredFileSystem& restored_file_system = 139 const RegistryInterface::RestoredFileSystem& restored_file_system =
135 restored_file_systems->at(0); 140 restored_file_systems->at(0);
136 EXPECT_EQ(kExtensionId, restored_file_system.extension_id); 141 EXPECT_EQ(kExtensionId, restored_file_system.extension_id);
137 EXPECT_EQ(kFileSystemId, restored_file_system.options.file_system_id); 142 EXPECT_EQ(kFileSystemId, restored_file_system.options.file_system_id);
138 EXPECT_EQ(kDisplayName, restored_file_system.options.display_name); 143 EXPECT_EQ(kDisplayName, restored_file_system.options.display_name);
139 EXPECT_TRUE(restored_file_system.options.writable); 144 EXPECT_TRUE(restored_file_system.options.writable);
145 EXPECT_EQ(kSource, restored_file_system.options.source);
140 EXPECT_TRUE(restored_file_system.options.supports_notify_tag); 146 EXPECT_TRUE(restored_file_system.options.supports_notify_tag);
141 EXPECT_EQ(kOpenedFilesLimit, restored_file_system.options.opened_files_limit); 147 EXPECT_EQ(kOpenedFilesLimit, restored_file_system.options.opened_files_limit);
142 148
143 ASSERT_EQ(1u, restored_file_system.watchers.size()); 149 ASSERT_EQ(1u, restored_file_system.watchers.size());
144 const auto& restored_watcher_it = restored_file_system.watchers.find( 150 const auto& restored_watcher_it = restored_file_system.watchers.find(
145 WatcherKey(fake_watcher_.entry_path, fake_watcher_.recursive)); 151 WatcherKey(fake_watcher_.entry_path, fake_watcher_.recursive));
146 ASSERT_NE(restored_file_system.watchers.end(), restored_watcher_it); 152 ASSERT_NE(restored_file_system.watchers.end(), restored_watcher_it);
147 153
148 EXPECT_EQ(fake_watcher_.entry_path, restored_watcher_it->second.entry_path); 154 EXPECT_EQ(fake_watcher_.entry_path, restored_watcher_it->second.entry_path);
149 EXPECT_EQ(fake_watcher_.recursive, restored_watcher_it->second.recursive); 155 EXPECT_EQ(fake_watcher_.recursive, restored_watcher_it->second.recursive);
150 EXPECT_EQ(fake_watcher_.last_tag, restored_watcher_it->second.last_tag); 156 EXPECT_EQ(fake_watcher_.last_tag, restored_watcher_it->second.last_tag);
151 } 157 }
152 158
153 TEST_F(FileSystemProviderRegistryTest, RememberFileSystem) { 159 TEST_F(FileSystemProviderRegistryTest, RememberFileSystem) {
154 MountOptions options(kFileSystemId, kDisplayName); 160 MountOptions options(kFileSystemId, kDisplayName);
155 options.writable = true; 161 options.writable = true;
162 options.source = kSource;
156 options.supports_notify_tag = true; 163 options.supports_notify_tag = true;
157 options.opened_files_limit = kOpenedFilesLimit; 164 options.opened_files_limit = kOpenedFilesLimit;
158 165
159 ProvidedFileSystemInfo file_system_info( 166 ProvidedFileSystemInfo file_system_info(
160 kExtensionId, options, base::FilePath(FILE_PATH_LITERAL("/a/b/c"))); 167 kExtensionId, options, base::FilePath(FILE_PATH_LITERAL("/a/b/c")));
161 168
162 Watchers watchers; 169 Watchers watchers;
163 watchers[WatcherKey(fake_watcher_.entry_path, fake_watcher_.recursive)] = 170 watchers[WatcherKey(fake_watcher_.entry_path, fake_watcher_.recursive)] =
164 fake_watcher_; 171 fake_watcher_;
165 172
(...skipping 26 matching lines...) Expand all
192 std::string display_name; 199 std::string display_name;
193 EXPECT_TRUE(file_system->GetStringWithoutPathExpansion(kPrefKeyDisplayName, 200 EXPECT_TRUE(file_system->GetStringWithoutPathExpansion(kPrefKeyDisplayName,
194 &display_name)); 201 &display_name));
195 EXPECT_EQ(kDisplayName, display_name); 202 EXPECT_EQ(kDisplayName, display_name);
196 203
197 bool writable = false; 204 bool writable = false;
198 EXPECT_TRUE( 205 EXPECT_TRUE(
199 file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable, &writable)); 206 file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable, &writable));
200 EXPECT_TRUE(writable); 207 EXPECT_TRUE(writable);
201 208
209 std::string source_as_string;
210 EXPECT_TRUE(file_system->GetStringWithoutPathExpansion(kPrefKeySource,
211 &source_as_string));
212 EXPECT_EQ("network", source_as_string);
213
202 bool supports_notify_tag = false; 214 bool supports_notify_tag = false;
203 EXPECT_TRUE(file_system->GetBooleanWithoutPathExpansion( 215 EXPECT_TRUE(file_system->GetBooleanWithoutPathExpansion(
204 kPrefKeySupportsNotifyTag, &supports_notify_tag)); 216 kPrefKeySupportsNotifyTag, &supports_notify_tag));
205 EXPECT_TRUE(supports_notify_tag); 217 EXPECT_TRUE(supports_notify_tag);
206 218
207 int opened_files_limit = 0; 219 int opened_files_limit = 0;
208 EXPECT_TRUE(file_system->GetIntegerWithoutPathExpansion( 220 EXPECT_TRUE(file_system->GetIntegerWithoutPathExpansion(
209 kPrefKeyOpenedFilesLimit, &opened_files_limit)); 221 kPrefKeyOpenedFilesLimit, &opened_files_limit));
210 EXPECT_EQ(kOpenedFilesLimit, opened_files_limit); 222 EXPECT_EQ(kOpenedFilesLimit, opened_files_limit);
211 223
(...skipping 29 matching lines...) Expand all
241 EXPECT_TRUE(persistent_origins->GetString(0, &persistent_origin)); 253 EXPECT_TRUE(persistent_origins->GetString(0, &persistent_origin));
242 const auto& fake_subscriber_it = 254 const auto& fake_subscriber_it =
243 fake_watcher_.subscribers.find(GURL(persistent_origin)); 255 fake_watcher_.subscribers.find(GURL(persistent_origin));
244 ASSERT_NE(fake_watcher_.subscribers.end(), fake_subscriber_it); 256 ASSERT_NE(fake_watcher_.subscribers.end(), fake_subscriber_it);
245 EXPECT_TRUE(fake_subscriber_it->second.persistent); 257 EXPECT_TRUE(fake_subscriber_it->second.persistent);
246 } 258 }
247 259
248 TEST_F(FileSystemProviderRegistryTest, ForgetFileSystem) { 260 TEST_F(FileSystemProviderRegistryTest, ForgetFileSystem) {
249 // Create a fake file systems in the preferences. 261 // Create a fake file systems in the preferences.
250 RememberFakeFileSystem(profile_, kExtensionId, kFileSystemId, kDisplayName, 262 RememberFakeFileSystem(profile_, kExtensionId, kFileSystemId, kDisplayName,
251 true /* writable */, true /* supports_notify_tag */, 263 true /* writable */, kSource,
252 kOpenedFilesLimit, fake_watcher_); 264 true /* supports_notify_tag */, kOpenedFilesLimit,
265 fake_watcher_);
253 266
254 registry_->ForgetFileSystem(kExtensionId, kFileSystemId); 267 registry_->ForgetFileSystem(kExtensionId, kFileSystemId);
255 268
256 TestingPrefServiceSyncable* const pref_service = 269 TestingPrefServiceSyncable* const pref_service =
257 profile_->GetTestingPrefService(); 270 profile_->GetTestingPrefService();
258 ASSERT_TRUE(pref_service); 271 ASSERT_TRUE(pref_service);
259 272
260 const base::DictionaryValue* const extensions = 273 const base::DictionaryValue* const extensions =
261 pref_service->GetDictionary(prefs::kFileSystemProviderMounted); 274 pref_service->GetDictionary(prefs::kFileSystemProviderMounted);
262 ASSERT_TRUE(extensions); 275 ASSERT_TRUE(extensions);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 const base::DictionaryValue* watcher = NULL; 322 const base::DictionaryValue* watcher = NULL;
310 ASSERT_TRUE(watchers_value->GetDictionaryWithoutPathExpansion( 323 ASSERT_TRUE(watchers_value->GetDictionaryWithoutPathExpansion(
311 fake_watcher_.entry_path.value(), &watcher)); 324 fake_watcher_.entry_path.value(), &watcher));
312 325
313 std::string last_tag; 326 std::string last_tag;
314 EXPECT_TRUE(watcher->GetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, 327 EXPECT_TRUE(watcher->GetStringWithoutPathExpansion(kPrefKeyWatcherLastTag,
315 &last_tag)); 328 &last_tag));
316 EXPECT_EQ(fake_watcher_.last_tag, last_tag); 329 EXPECT_EQ(fake_watcher_.last_tag, last_tag);
317 } 330 }
318 331
332 TEST_F(FileSystemProviderRegistryTest, SourceToString) {
333 {
334 Source result = SOURCE_UNKNOWN;
335 EXPECT_TRUE(StringToSource(SourceToString(SOURCE_FILE), &result));
336 EXPECT_EQ(SOURCE_FILE, result);
337 }
338 {
339 Source result = SOURCE_UNKNOWN;
340 EXPECT_TRUE(StringToSource(SourceToString(SOURCE_DEVICE), &result));
341 EXPECT_EQ(SOURCE_DEVICE, result);
342 }
343 {
344 Source result = SOURCE_UNKNOWN;
345 EXPECT_TRUE(StringToSource(SourceToString(SOURCE_NETWORK), &result));
346 EXPECT_EQ(SOURCE_NETWORK, result);
347 }
348 {
349 Source result = SOURCE_FILE;
350 EXPECT_TRUE(StringToSource(SourceToString(SOURCE_UNKNOWN), &result));
351 EXPECT_EQ(SOURCE_UNKNOWN, result);
352 }
353 }
354
319 } // namespace file_system_provider 355 } // namespace file_system_provider
320 } // namespace chromeos 356 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_system_provider/registry.cc ('k') | chrome/common/extensions/api/file_manager_private.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698