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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
25 #include "extensions/common/manifest_constants.h" | 25 #include "extensions/common/manifest_constants.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "webkit/browser/fileapi/external_mount_points.h" | 27 #include "webkit/browser/fileapi/external_mount_points.h" |
28 | 28 |
29 namespace chromeos { | 29 namespace chromeos { |
30 namespace file_system_provider { | 30 namespace file_system_provider { |
31 namespace { | 31 namespace { |
32 | 32 |
33 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; | 33 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; |
34 const char kFileSystemId[] = "camera/pictures/id !@#$%^&*()_+"; | 34 const char kFileSystemId[] = "camera/pictures/id .!@#$%^&*()_+"; |
hashimoto
2014/07/02 08:59:37
What is the point of this change?
mtomasz
2014/07/03 05:24:07
File system IDs are used as keys in preferences. T
hashimoto
2014/07/04 06:38:41
Then "." here has a special role unlike other rand
mtomasz
2014/07/04 07:50:42
Done.
| |
35 const char kFileSystemName[] = "Camera Pictures"; | 35 const char kFileSystemName[] = "Camera Pictures"; |
36 | 36 |
37 // Utility observer, logging events from file_system_provider::Service. | 37 // Utility observer, logging events from file_system_provider::Service. |
38 class LoggingObserver : public Observer { | 38 class LoggingObserver : public Observer { |
39 public: | 39 public: |
40 class Event { | 40 class Event { |
41 public: | 41 public: |
42 Event(const ProvidedFileSystemInfo& file_system_info, | 42 Event(const ProvidedFileSystemInfo& file_system_info, |
43 base::File::Error error) | 43 base::File::Error error) |
44 : file_system_info_(file_system_info), error_(error) {} | 44 : file_system_info_(file_system_info), error_(error) {} |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 | 91 |
92 // Stores a provided file system information in preferences. | 92 // Stores a provided file system information in preferences. |
93 void RememberFakeFileSystem(TestingProfile* profile, | 93 void RememberFakeFileSystem(TestingProfile* profile, |
94 const std::string& extension_id, | 94 const std::string& extension_id, |
95 const std::string& file_system_id, | 95 const std::string& file_system_id, |
96 const std::string& file_system_name) { | 96 const std::string& file_system_name) { |
97 TestingPrefServiceSyncable* pref_service = profile->GetTestingPrefService(); | 97 TestingPrefServiceSyncable* pref_service = profile->GetTestingPrefService(); |
98 ASSERT_TRUE(pref_service); | 98 ASSERT_TRUE(pref_service); |
99 | 99 |
100 base::DictionaryValue extensions; | 100 base::DictionaryValue extensions; |
101 base::ListValue* file_systems = new base::ListValue(); | 101 base::DictionaryValue* file_systems = new base::DictionaryValue(); |
102 base::DictionaryValue* file_system = new base::DictionaryValue(); | 102 base::DictionaryValue* file_system = new base::DictionaryValue(); |
103 file_system->SetString(kPrefKeyFileSystemId, kFileSystemId); | 103 file_system->SetString(kPrefKeyFileSystemId, kFileSystemId); |
104 file_system->SetString(kPrefKeyFileSystemName, kFileSystemName); | 104 file_system->SetString(kPrefKeyFileSystemName, kFileSystemName); |
105 file_systems->Append(file_system); | 105 file_systems->SetWithoutPathExpansion(kFileSystemId, file_system); |
106 extensions.Set(kExtensionId, file_systems); | 106 extensions.Set(kExtensionId, file_systems); |
107 | 107 |
108 pref_service->Set(prefs::kFileSystemProviderMounted, extensions); | 108 pref_service->Set(prefs::kFileSystemProviderMounted, extensions); |
109 } | 109 } |
110 | 110 |
111 } // namespace | 111 } // namespace |
112 | 112 |
113 class FileSystemProviderServiceTest : public testing::Test { | 113 class FileSystemProviderServiceTest : public testing::Test { |
114 protected: | 114 protected: |
115 FileSystemProviderServiceTest() {} | 115 FileSystemProviderServiceTest() {} |
116 virtual ~FileSystemProviderServiceTest() {} | 116 virtual ~FileSystemProviderServiceTest() {} |
117 | 117 |
118 virtual void SetUp() OVERRIDE { | 118 virtual void SetUp() OVERRIDE { |
119 profile_.reset(new TestingProfile); | 119 profile_.reset(new TestingProfile); |
120 user_manager_ = new FakeUserManager(); | 120 user_manager_ = new FakeUserManager(); |
121 user_manager_->AddUser(profile_->GetProfileName()); | 121 user_manager_->AddUser(profile_->GetProfileName()); |
122 user_manager_enabler_.reset(new ScopedUserManagerEnabler(user_manager_)); | 122 user_manager_enabler_.reset(new ScopedUserManagerEnabler(user_manager_)); |
123 extension_registry_.reset( | 123 extension_registry_.reset( |
124 new extensions::ExtensionRegistry(profile_.get())); | 124 new extensions::ExtensionRegistry(profile_.get())); |
125 file_system_provider_service_.reset( | 125 service_.reset(new Service(profile_.get(), extension_registry_.get())); |
126 new Service(profile_.get(), extension_registry_.get())); | 126 service_->SetFileSystemFactoryForTesting( |
127 file_system_provider_service_->SetFileSystemFactoryForTesting( | |
128 base::Bind(&FakeProvidedFileSystem::Create)); | 127 base::Bind(&FakeProvidedFileSystem::Create)); |
129 extension_ = createFakeExtension(kExtensionId); | 128 extension_ = createFakeExtension(kExtensionId); |
130 } | 129 } |
131 | 130 |
132 content::TestBrowserThreadBundle thread_bundle_; | 131 content::TestBrowserThreadBundle thread_bundle_; |
133 scoped_ptr<TestingProfile> profile_; | 132 scoped_ptr<TestingProfile> profile_; |
134 FakeUserManager* user_manager_; | 133 FakeUserManager* user_manager_; |
135 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; | 134 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; |
136 scoped_ptr<extensions::ExtensionRegistry> extension_registry_; | 135 scoped_ptr<extensions::ExtensionRegistry> extension_registry_; |
137 scoped_ptr<Service> file_system_provider_service_; | 136 scoped_ptr<Service> service_; |
138 scoped_refptr<extensions::Extension> extension_; | 137 scoped_refptr<extensions::Extension> extension_; |
139 }; | 138 }; |
140 | 139 |
141 TEST_F(FileSystemProviderServiceTest, MountFileSystem) { | 140 TEST_F(FileSystemProviderServiceTest, MountFileSystem) { |
142 LoggingObserver observer; | 141 LoggingObserver observer; |
143 file_system_provider_service_->AddObserver(&observer); | 142 service_->AddObserver(&observer); |
144 | 143 |
145 const bool result = file_system_provider_service_->MountFileSystem( | 144 const bool result = |
146 kExtensionId, kFileSystemId, kFileSystemName); | 145 service_->MountFileSystem(kExtensionId, kFileSystemId, kFileSystemName); |
147 EXPECT_TRUE(result); | 146 EXPECT_TRUE(result); |
148 | 147 |
149 ASSERT_EQ(1u, observer.mounts.size()); | 148 ASSERT_EQ(1u, observer.mounts.size()); |
150 EXPECT_EQ(kExtensionId, observer.mounts[0].file_system_info().extension_id()); | 149 EXPECT_EQ(kExtensionId, observer.mounts[0].file_system_info().extension_id()); |
151 EXPECT_EQ(kFileSystemId, | 150 EXPECT_EQ(kFileSystemId, |
152 observer.mounts[0].file_system_info().file_system_id()); | 151 observer.mounts[0].file_system_info().file_system_id()); |
153 base::FilePath expected_mount_path = | 152 base::FilePath expected_mount_path = |
154 util::GetMountPath(profile_.get(), kExtensionId, kFileSystemId); | 153 util::GetMountPath(profile_.get(), kExtensionId, kFileSystemId); |
155 EXPECT_EQ(expected_mount_path.AsUTF8Unsafe(), | 154 EXPECT_EQ(expected_mount_path.AsUTF8Unsafe(), |
156 observer.mounts[0].file_system_info().mount_path().AsUTF8Unsafe()); | 155 observer.mounts[0].file_system_info().mount_path().AsUTF8Unsafe()); |
157 EXPECT_EQ(kFileSystemName, | 156 EXPECT_EQ(kFileSystemName, |
158 observer.mounts[0].file_system_info().file_system_name()); | 157 observer.mounts[0].file_system_info().file_system_name()); |
159 EXPECT_EQ(base::File::FILE_OK, observer.mounts[0].error()); | 158 EXPECT_EQ(base::File::FILE_OK, observer.mounts[0].error()); |
160 ASSERT_EQ(0u, observer.unmounts.size()); | 159 ASSERT_EQ(0u, observer.unmounts.size()); |
161 | 160 |
162 std::vector<ProvidedFileSystemInfo> file_system_info_list = | 161 std::vector<ProvidedFileSystemInfo> file_system_info_list = |
163 file_system_provider_service_->GetProvidedFileSystemInfoList(); | 162 service_->GetProvidedFileSystemInfoList(); |
164 ASSERT_EQ(1u, file_system_info_list.size()); | 163 ASSERT_EQ(1u, file_system_info_list.size()); |
165 | 164 |
166 file_system_provider_service_->RemoveObserver(&observer); | 165 service_->RemoveObserver(&observer); |
167 } | 166 } |
168 | 167 |
169 TEST_F(FileSystemProviderServiceTest, MountFileSystem_UniqueIds) { | 168 TEST_F(FileSystemProviderServiceTest, MountFileSystem_UniqueIds) { |
170 LoggingObserver observer; | 169 LoggingObserver observer; |
171 file_system_provider_service_->AddObserver(&observer); | 170 service_->AddObserver(&observer); |
172 | 171 |
173 const bool result = file_system_provider_service_->MountFileSystem( | 172 const bool result = |
174 kExtensionId, kFileSystemId, kFileSystemName); | 173 service_->MountFileSystem(kExtensionId, kFileSystemId, kFileSystemName); |
175 EXPECT_TRUE(result); | 174 EXPECT_TRUE(result); |
176 | 175 |
177 const bool second_result = file_system_provider_service_->MountFileSystem( | 176 const bool second_result = |
178 kExtensionId, kFileSystemId, kFileSystemName); | 177 service_->MountFileSystem(kExtensionId, kFileSystemId, kFileSystemName); |
179 EXPECT_FALSE(second_result); | 178 EXPECT_FALSE(second_result); |
180 | 179 |
181 ASSERT_EQ(2u, observer.mounts.size()); | 180 ASSERT_EQ(2u, observer.mounts.size()); |
182 EXPECT_EQ(base::File::FILE_OK, observer.mounts[0].error()); | 181 EXPECT_EQ(base::File::FILE_OK, observer.mounts[0].error()); |
183 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, observer.mounts[1].error()); | 182 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, observer.mounts[1].error()); |
184 | 183 |
185 std::vector<ProvidedFileSystemInfo> file_system_info_list = | 184 std::vector<ProvidedFileSystemInfo> file_system_info_list = |
186 file_system_provider_service_->GetProvidedFileSystemInfoList(); | 185 service_->GetProvidedFileSystemInfoList(); |
187 ASSERT_EQ(1u, file_system_info_list.size()); | 186 ASSERT_EQ(1u, file_system_info_list.size()); |
188 | 187 |
189 file_system_provider_service_->RemoveObserver(&observer); | 188 service_->RemoveObserver(&observer); |
190 } | 189 } |
191 | 190 |
192 TEST_F(FileSystemProviderServiceTest, MountFileSystem_StressTest) { | 191 TEST_F(FileSystemProviderServiceTest, MountFileSystem_StressTest) { |
193 LoggingObserver observer; | 192 LoggingObserver observer; |
194 file_system_provider_service_->AddObserver(&observer); | 193 service_->AddObserver(&observer); |
195 | 194 |
196 const size_t kMaxFileSystems = 16; | 195 const size_t kMaxFileSystems = 16; |
197 for (size_t i = 0; i < kMaxFileSystems; ++i) { | 196 for (size_t i = 0; i < kMaxFileSystems; ++i) { |
198 const std::string file_system_id = | 197 const std::string file_system_id = |
199 std::string("test-") + base::IntToString(i); | 198 std::string("test-") + base::IntToString(i); |
200 const bool result = file_system_provider_service_->MountFileSystem( | 199 const bool result = service_->MountFileSystem( |
201 kExtensionId, file_system_id, kFileSystemName); | 200 kExtensionId, file_system_id, kFileSystemName); |
202 EXPECT_TRUE(result); | 201 EXPECT_TRUE(result); |
203 } | 202 } |
204 ASSERT_EQ(kMaxFileSystems, observer.mounts.size()); | 203 ASSERT_EQ(kMaxFileSystems, observer.mounts.size()); |
205 | 204 |
206 // The next file system is out of limit, and registering it should fail. | 205 // The next file system is out of limit, and registering it should fail. |
207 const bool result = file_system_provider_service_->MountFileSystem( | 206 const bool result = |
208 kExtensionId, kFileSystemId, kFileSystemName); | 207 service_->MountFileSystem(kExtensionId, kFileSystemId, kFileSystemName); |
209 EXPECT_FALSE(result); | 208 EXPECT_FALSE(result); |
210 | 209 |
211 ASSERT_EQ(kMaxFileSystems + 1, observer.mounts.size()); | 210 ASSERT_EQ(kMaxFileSystems + 1, observer.mounts.size()); |
212 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, | 211 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, |
213 observer.mounts[kMaxFileSystems].error()); | 212 observer.mounts[kMaxFileSystems].error()); |
214 | 213 |
215 std::vector<ProvidedFileSystemInfo> file_system_info_list = | 214 std::vector<ProvidedFileSystemInfo> file_system_info_list = |
216 file_system_provider_service_->GetProvidedFileSystemInfoList(); | 215 service_->GetProvidedFileSystemInfoList(); |
217 ASSERT_EQ(kMaxFileSystems, file_system_info_list.size()); | 216 ASSERT_EQ(kMaxFileSystems, file_system_info_list.size()); |
218 | 217 |
219 file_system_provider_service_->RemoveObserver(&observer); | 218 service_->RemoveObserver(&observer); |
220 } | 219 } |
221 | 220 |
222 TEST_F(FileSystemProviderServiceTest, UnmountFileSystem) { | 221 TEST_F(FileSystemProviderServiceTest, UnmountFileSystem) { |
223 LoggingObserver observer; | 222 LoggingObserver observer; |
224 file_system_provider_service_->AddObserver(&observer); | 223 service_->AddObserver(&observer); |
225 | 224 |
226 const bool result = file_system_provider_service_->MountFileSystem( | 225 const bool result = |
227 kExtensionId, kFileSystemId, kFileSystemName); | 226 service_->MountFileSystem(kExtensionId, kFileSystemId, kFileSystemName); |
228 EXPECT_TRUE(result); | 227 EXPECT_TRUE(result); |
229 ASSERT_EQ(1u, observer.mounts.size()); | 228 ASSERT_EQ(1u, observer.mounts.size()); |
230 | 229 |
231 const bool unmount_result = file_system_provider_service_->UnmountFileSystem( | 230 const bool unmount_result = service_->UnmountFileSystem( |
232 kExtensionId, kFileSystemId); | 231 kExtensionId, kFileSystemId, Service::UNMOUNT_MODE_USER); |
233 EXPECT_TRUE(unmount_result); | 232 EXPECT_TRUE(unmount_result); |
234 ASSERT_EQ(1u, observer.unmounts.size()); | 233 ASSERT_EQ(1u, observer.unmounts.size()); |
235 EXPECT_EQ(base::File::FILE_OK, observer.unmounts[0].error()); | 234 EXPECT_EQ(base::File::FILE_OK, observer.unmounts[0].error()); |
236 | 235 |
237 EXPECT_EQ(kExtensionId, | 236 EXPECT_EQ(kExtensionId, |
238 observer.unmounts[0].file_system_info().extension_id()); | 237 observer.unmounts[0].file_system_info().extension_id()); |
239 EXPECT_EQ(kFileSystemId, | 238 EXPECT_EQ(kFileSystemId, |
240 observer.unmounts[0].file_system_info().file_system_id()); | 239 observer.unmounts[0].file_system_info().file_system_id()); |
241 | 240 |
242 std::vector<ProvidedFileSystemInfo> file_system_info_list = | 241 std::vector<ProvidedFileSystemInfo> file_system_info_list = |
243 file_system_provider_service_->GetProvidedFileSystemInfoList(); | 242 service_->GetProvidedFileSystemInfoList(); |
244 ASSERT_EQ(0u, file_system_info_list.size()); | 243 ASSERT_EQ(0u, file_system_info_list.size()); |
245 | 244 |
246 file_system_provider_service_->RemoveObserver(&observer); | 245 service_->RemoveObserver(&observer); |
247 } | 246 } |
248 | 247 |
249 TEST_F(FileSystemProviderServiceTest, UnmountFileSystem_OnExtensionUnload) { | 248 TEST_F(FileSystemProviderServiceTest, UnmountFileSystem_OnExtensionUnload) { |
250 LoggingObserver observer; | 249 LoggingObserver observer; |
251 file_system_provider_service_->AddObserver(&observer); | 250 service_->AddObserver(&observer); |
252 | 251 |
253 const bool result = file_system_provider_service_->MountFileSystem( | 252 const bool result = |
254 kExtensionId, kFileSystemId, kFileSystemName); | 253 service_->MountFileSystem(kExtensionId, kFileSystemId, kFileSystemName); |
255 EXPECT_TRUE(result); | 254 EXPECT_TRUE(result); |
256 ASSERT_EQ(1u, observer.mounts.size()); | 255 ASSERT_EQ(1u, observer.mounts.size()); |
257 | 256 |
258 // Directly call the observer's method. | 257 // Directly call the observer's method. |
259 file_system_provider_service_->OnExtensionUnloaded( | 258 service_->OnExtensionUnloaded( |
260 profile_.get(), | 259 profile_.get(), |
261 extension_.get(), | 260 extension_.get(), |
262 extensions::UnloadedExtensionInfo::REASON_DISABLE); | 261 extensions::UnloadedExtensionInfo::REASON_DISABLE); |
263 | 262 |
264 ASSERT_EQ(1u, observer.unmounts.size()); | 263 ASSERT_EQ(1u, observer.unmounts.size()); |
265 EXPECT_EQ(base::File::FILE_OK, observer.unmounts[0].error()); | 264 EXPECT_EQ(base::File::FILE_OK, observer.unmounts[0].error()); |
266 | 265 |
267 EXPECT_EQ(kExtensionId, | 266 EXPECT_EQ(kExtensionId, |
268 observer.unmounts[0].file_system_info().extension_id()); | 267 observer.unmounts[0].file_system_info().extension_id()); |
269 EXPECT_EQ(kFileSystemId, | 268 EXPECT_EQ(kFileSystemId, |
270 observer.unmounts[0].file_system_info().file_system_id()); | 269 observer.unmounts[0].file_system_info().file_system_id()); |
271 | 270 |
272 std::vector<ProvidedFileSystemInfo> file_system_info_list = | 271 std::vector<ProvidedFileSystemInfo> file_system_info_list = |
273 file_system_provider_service_->GetProvidedFileSystemInfoList(); | 272 service_->GetProvidedFileSystemInfoList(); |
274 ASSERT_EQ(0u, file_system_info_list.size()); | 273 ASSERT_EQ(0u, file_system_info_list.size()); |
275 | 274 |
276 file_system_provider_service_->RemoveObserver(&observer); | 275 service_->RemoveObserver(&observer); |
277 } | 276 } |
278 | 277 |
279 TEST_F(FileSystemProviderServiceTest, UnmountFileSystem_WrongExtensionId) { | 278 TEST_F(FileSystemProviderServiceTest, UnmountFileSystem_WrongExtensionId) { |
280 LoggingObserver observer; | 279 LoggingObserver observer; |
281 file_system_provider_service_->AddObserver(&observer); | 280 service_->AddObserver(&observer); |
282 | 281 |
283 const std::string kWrongExtensionId = "helloworldhelloworldhelloworldhe"; | 282 const std::string kWrongExtensionId = "helloworldhelloworldhelloworldhe"; |
284 | 283 |
285 const bool result = file_system_provider_service_->MountFileSystem( | 284 const bool result = |
286 kExtensionId, kFileSystemId, kFileSystemName); | 285 service_->MountFileSystem(kExtensionId, kFileSystemId, kFileSystemName); |
287 EXPECT_TRUE(result); | 286 EXPECT_TRUE(result); |
288 ASSERT_EQ(1u, observer.mounts.size()); | 287 ASSERT_EQ(1u, observer.mounts.size()); |
289 ASSERT_EQ( | 288 ASSERT_EQ(1u, service_->GetProvidedFileSystemInfoList().size()); |
290 1u, | |
291 file_system_provider_service_->GetProvidedFileSystemInfoList().size()); | |
292 | 289 |
293 const bool unmount_result = file_system_provider_service_->UnmountFileSystem( | 290 const bool unmount_result = service_->UnmountFileSystem( |
294 kWrongExtensionId, kFileSystemId); | 291 kWrongExtensionId, kFileSystemId, Service::UNMOUNT_MODE_USER); |
295 EXPECT_FALSE(unmount_result); | 292 EXPECT_FALSE(unmount_result); |
296 ASSERT_EQ(1u, observer.unmounts.size()); | 293 ASSERT_EQ(1u, observer.unmounts.size()); |
297 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, observer.unmounts[0].error()); | 294 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, observer.unmounts[0].error()); |
298 ASSERT_EQ( | 295 ASSERT_EQ(1u, service_->GetProvidedFileSystemInfoList().size()); |
299 1u, | |
300 file_system_provider_service_->GetProvidedFileSystemInfoList().size()); | |
301 | 296 |
302 std::vector<ProvidedFileSystemInfo> file_system_info_list = | 297 std::vector<ProvidedFileSystemInfo> file_system_info_list = |
303 file_system_provider_service_->GetProvidedFileSystemInfoList(); | 298 service_->GetProvidedFileSystemInfoList(); |
304 ASSERT_EQ(1u, file_system_info_list.size()); | 299 ASSERT_EQ(1u, file_system_info_list.size()); |
305 | 300 |
306 file_system_provider_service_->RemoveObserver(&observer); | 301 service_->RemoveObserver(&observer); |
307 } | 302 } |
308 | 303 |
309 TEST_F(FileSystemProviderServiceTest, RestoreFileSystem_OnExtensionLoad) { | 304 TEST_F(FileSystemProviderServiceTest, RestoreFileSystem_OnExtensionLoad) { |
310 LoggingObserver observer; | |
311 file_system_provider_service_->AddObserver(&observer); | |
312 | |
313 // Create a fake entry in the preferences. | 305 // Create a fake entry in the preferences. |
314 RememberFakeFileSystem( | 306 RememberFakeFileSystem( |
315 profile_.get(), kExtensionId, kFileSystemId, kFileSystemName); | 307 profile_.get(), kExtensionId, kFileSystemId, kFileSystemName); |
316 | 308 |
317 EXPECT_EQ(0u, observer.mounts.size()); | 309 { |
hashimoto
2014/07/02 08:59:37
Why do we need a scope here?
mtomasz
2014/07/03 05:24:07
Not needed. Done.
| |
310 scoped_ptr<Service> service( | |
hashimoto
2014/07/02 08:59:37
Why can't you call reset() against |service_| here
mtomasz
2014/07/03 05:24:07
Sure I can, but is it better? The new instance is
hashimoto
2014/07/04 06:38:41
Having |service| and |service_| in the same scope
mtomasz
2014/07/04 07:50:42
Done.
hashimoto
2014/07/07 11:07:46
|file_system_provider_service| does not tell how i
mtomasz
2014/07/08 01:52:08
Done.
| |
311 new Service(profile_.get(), extension_registry_.get())); | |
hashimoto
2014/07/02 08:59:37
Please add a comment to describe that you want to
mtomasz
2014/07/03 05:24:07
Done.
| |
312 LoggingObserver observer; | |
313 service->AddObserver(&observer); | |
318 | 314 |
319 // Directly call the observer's method. | 315 service->SetFileSystemFactoryForTesting( |
320 file_system_provider_service_->OnExtensionLoaded(profile_.get(), | 316 base::Bind(&FakeProvidedFileSystem::Create)); |
321 extension_.get()); | |
322 | 317 |
323 ASSERT_EQ(1u, observer.mounts.size()); | 318 EXPECT_EQ(0u, observer.mounts.size()); |
324 EXPECT_EQ(base::File::FILE_OK, observer.mounts[0].error()); | |
325 | 319 |
326 EXPECT_EQ(kExtensionId, observer.mounts[0].file_system_info().extension_id()); | 320 // Directly call the observer's method. |
327 EXPECT_EQ(kFileSystemId, | 321 service->OnExtensionLoaded(profile_.get(), extension_.get()); |
328 observer.mounts[0].file_system_info().file_system_id()); | |
329 | 322 |
330 std::vector<ProvidedFileSystemInfo> file_system_info_list = | 323 ASSERT_EQ(1u, observer.mounts.size()); |
331 file_system_provider_service_->GetProvidedFileSystemInfoList(); | 324 EXPECT_EQ(base::File::FILE_OK, observer.mounts[0].error()); |
332 ASSERT_EQ(1u, file_system_info_list.size()); | |
333 | 325 |
334 file_system_provider_service_->RemoveObserver(&observer); | 326 EXPECT_EQ(kExtensionId, |
327 observer.mounts[0].file_system_info().extension_id()); | |
328 EXPECT_EQ(kFileSystemId, | |
329 observer.mounts[0].file_system_info().file_system_id()); | |
330 | |
331 std::vector<ProvidedFileSystemInfo> file_system_info_list = | |
332 service->GetProvidedFileSystemInfoList(); | |
333 ASSERT_EQ(1u, file_system_info_list.size()); | |
334 | |
335 service->RemoveObserver(&observer); | |
336 } | |
335 } | 337 } |
336 | 338 |
337 TEST_F(FileSystemProviderServiceTest, ForgetFileSystem_OnExtensionUnload) { | 339 TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnMount) { |
338 LoggingObserver observer; | 340 LoggingObserver observer; |
339 file_system_provider_service_->AddObserver(&observer); | 341 service_->AddObserver(&observer); |
340 | 342 |
341 // Create a fake entry in the preferences. | 343 const bool result = |
342 RememberFakeFileSystem( | 344 service_->MountFileSystem(kExtensionId, kFileSystemId, kFileSystemName); |
343 profile_.get(), kExtensionId, kFileSystemId, kFileSystemName); | 345 EXPECT_TRUE(result); |
346 ASSERT_EQ(1u, observer.mounts.size()); | |
344 | 347 |
345 // Directly call the observer's methods. | 348 TestingPrefServiceSyncable* const pref_service = |
346 file_system_provider_service_->OnExtensionLoaded(profile_.get(), | 349 profile_->GetTestingPrefService(); |
347 extension_.get()); | |
348 | |
349 file_system_provider_service_->OnExtensionUnloaded( | |
350 profile_.get(), | |
351 extension_.get(), | |
352 extensions::UnloadedExtensionInfo::REASON_DISABLE); | |
353 | |
354 ASSERT_EQ(1u, observer.mounts.size()); | |
355 EXPECT_EQ(base::File::FILE_OK, observer.mounts[0].error()); | |
356 ASSERT_EQ(1u, observer.unmounts.size()); | |
357 EXPECT_EQ(base::File::FILE_OK, observer.unmounts[0].error()); | |
358 | |
359 TestingPrefServiceSyncable* pref_service = profile_->GetTestingPrefService(); | |
360 ASSERT_TRUE(pref_service); | 350 ASSERT_TRUE(pref_service); |
361 | 351 |
362 const base::DictionaryValue* extensions = | 352 const base::DictionaryValue* const extensions = |
363 pref_service->GetDictionary(prefs::kFileSystemProviderMounted); | 353 pref_service->GetDictionary(prefs::kFileSystemProviderMounted); |
364 ASSERT_TRUE(extensions); | 354 ASSERT_TRUE(extensions); |
365 | 355 |
366 const base::ListValue* file_systems; | 356 const base::DictionaryValue* file_systems; |
367 EXPECT_FALSE(extensions->GetList(kExtensionId, &file_systems)); | 357 ASSERT_TRUE(extensions->GetDictionary(kExtensionId, &file_systems)); |
358 ASSERT_EQ(1u, file_systems->size()); | |
368 | 359 |
369 file_system_provider_service_->RemoveObserver(&observer); | 360 const base::Value* file_system_value = NULL; |
370 } | |
371 | |
372 TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnShutdown) { | |
373 { | |
374 scoped_ptr<Service> service( | |
375 new Service(profile_.get(), extension_registry_.get())); | |
376 service->SetFileSystemFactoryForTesting( | |
377 base::Bind(&FakeProvidedFileSystem::Create)); | |
378 | |
379 LoggingObserver observer; | |
380 service->AddObserver(&observer); | |
381 | |
382 const bool result = | |
383 service->MountFileSystem(kExtensionId, kFileSystemId, kFileSystemName); | |
384 EXPECT_TRUE(result); | |
385 ASSERT_EQ(1u, observer.mounts.size()); | |
386 | |
387 service->RemoveObserver(&observer); | |
388 } | |
389 | |
390 TestingPrefServiceSyncable* pref_service = profile_->GetTestingPrefService(); | |
391 ASSERT_TRUE(pref_service); | |
392 | |
393 const base::DictionaryValue* extensions = | |
394 pref_service->GetDictionary(prefs::kFileSystemProviderMounted); | |
395 ASSERT_TRUE(extensions); | |
396 | |
397 const base::ListValue* file_systems; | |
398 ASSERT_TRUE(extensions->GetList(kExtensionId, &file_systems)); | |
399 ASSERT_EQ(1u, file_systems->GetSize()); | |
400 | |
401 const base::DictionaryValue* file_system = NULL; | 361 const base::DictionaryValue* file_system = NULL; |
402 ASSERT_TRUE(file_systems->GetDictionary(0, &file_system)); | 362 ASSERT_TRUE( |
363 file_systems->GetWithoutPathExpansion(kFileSystemId, &file_system_value)); | |
364 ASSERT_TRUE(file_system_value->GetAsDictionary(&file_system)); | |
403 | 365 |
404 std::string file_system_id; | 366 std::string file_system_id; |
405 file_system->GetString(kPrefKeyFileSystemId, &file_system_id); | 367 file_system->GetString(kPrefKeyFileSystemId, &file_system_id); |
406 EXPECT_EQ(kFileSystemId, file_system_id); | 368 EXPECT_EQ(kFileSystemId, file_system_id); |
407 | 369 |
408 std::string file_system_name; | 370 std::string file_system_name; |
409 file_system->GetString(kPrefKeyFileSystemName, &file_system_name); | 371 file_system->GetString(kPrefKeyFileSystemName, &file_system_name); |
410 EXPECT_EQ(kFileSystemName, file_system_name); | 372 EXPECT_EQ(kFileSystemName, file_system_name); |
373 | |
374 service_->RemoveObserver(&observer); | |
375 } | |
376 | |
377 TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnUnmountByUser) { | |
hashimoto
2014/07/02 08:59:38
What is the relationship between these two new tes
mtomasz
2014/07/03 05:24:07
ForgetFileSystem_OnExtensionUnload -> RememberFile
hashimoto
2014/07/04 06:38:41
Why did you change the order?
Even if you need to
mtomasz
2014/07/04 07:50:42
I flipped the order, but the diff doesn't look muc
| |
378 LoggingObserver observer; | |
379 service_->AddObserver(&observer); | |
380 | |
381 TestingPrefServiceSyncable* const pref_service = | |
382 profile_->GetTestingPrefService(); | |
383 ASSERT_TRUE(pref_service); | |
384 | |
385 { | |
386 const bool mount_result = | |
387 service_->MountFileSystem(kExtensionId, kFileSystemId, kFileSystemName); | |
388 EXPECT_TRUE(mount_result); | |
389 ASSERT_EQ(1u, observer.mounts.size()); | |
390 | |
391 const base::DictionaryValue* extensions = | |
392 pref_service->GetDictionary(prefs::kFileSystemProviderMounted); | |
393 ASSERT_TRUE(extensions); | |
394 | |
395 const base::DictionaryValue* file_systems; | |
396 ASSERT_TRUE(extensions->GetDictionary(kExtensionId, &file_systems)); | |
397 EXPECT_EQ(1u, file_systems->size()); | |
398 } | |
399 | |
400 { | |
401 const bool unmount_result = service_->UnmountFileSystem( | |
402 kExtensionId, kFileSystemId, Service::UNMOUNT_MODE_USER); | |
403 EXPECT_TRUE(unmount_result); | |
404 | |
405 const base::DictionaryValue* const extensions = | |
406 pref_service->GetDictionary(prefs::kFileSystemProviderMounted); | |
407 ASSERT_TRUE(extensions); | |
408 | |
409 const base::DictionaryValue* file_systems; | |
410 EXPECT_FALSE(extensions->GetDictionary(kExtensionId, &file_systems)); | |
411 } | |
412 | |
413 service_->RemoveObserver(&observer); | |
414 } | |
415 | |
416 TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnUnmountOnShutdown) { | |
417 LoggingObserver observer; | |
418 service_->AddObserver(&observer); | |
419 | |
420 TestingPrefServiceSyncable* const pref_service = | |
421 profile_->GetTestingPrefService(); | |
422 ASSERT_TRUE(pref_service); | |
423 | |
424 { | |
425 const bool mount_result = | |
426 service_->MountFileSystem(kExtensionId, kFileSystemId, kFileSystemName); | |
427 EXPECT_TRUE(mount_result); | |
428 ASSERT_EQ(1u, observer.mounts.size()); | |
429 | |
430 const base::DictionaryValue* extensions = | |
431 pref_service->GetDictionary(prefs::kFileSystemProviderMounted); | |
432 ASSERT_TRUE(extensions); | |
433 | |
434 const base::DictionaryValue* file_systems; | |
435 ASSERT_TRUE(extensions->GetDictionary(kExtensionId, &file_systems)); | |
436 EXPECT_EQ(1u, file_systems->size()); | |
437 } | |
438 | |
439 { | |
440 const bool unmount_result = service_->UnmountFileSystem( | |
441 kExtensionId, kFileSystemId, Service::UNMOUNT_MODE_SHUTDOWN); | |
442 EXPECT_TRUE(unmount_result); | |
443 | |
444 const base::DictionaryValue* const extensions = | |
445 pref_service->GetDictionary(prefs::kFileSystemProviderMounted); | |
446 ASSERT_TRUE(extensions); | |
447 | |
448 const base::DictionaryValue* file_systems; | |
449 ASSERT_TRUE(extensions->GetDictionary(kExtensionId, &file_systems)); | |
450 EXPECT_EQ(1u, file_systems->size()); | |
451 } | |
452 | |
453 service_->RemoveObserver(&observer); | |
411 } | 454 } |
412 | 455 |
413 } // namespace file_system_provider | 456 } // namespace file_system_provider |
414 } // namespace chromeos | 457 } // namespace chromeos |
OLD | NEW |