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

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

Issue 442043002: ProfileManager doesn't depend on "--login-profile" switch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More tests fixed. Created 6 years, 4 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 | Annotate | Revision Log
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/service.h" 5 #include "chrome/browser/chromeos/file_system_provider/service.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/files/file.h" 10 #include "base/files/file.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system .h" 14 #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system .h"
15 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" 15 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h"
16 #include "chrome/browser/chromeos/file_system_provider/observer.h" 16 #include "chrome/browser/chromeos/file_system_provider/observer.h"
17 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h" 17 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h"
18 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" 18 #include "chrome/browser/chromeos/login/users/fake_user_manager.h"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "chrome/test/base/testing_browser_process.h"
20 #include "chrome/test/base/testing_pref_service_syncable.h" 21 #include "chrome/test/base/testing_pref_service_syncable.h"
21 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
23 #include "chrome/test/base/testing_profile_manager.h"
22 #include "components/user_prefs/user_prefs.h" 24 #include "components/user_prefs/user_prefs.h"
23 #include "content/public/test/test_browser_thread_bundle.h" 25 #include "content/public/test/test_browser_thread_bundle.h"
24 #include "extensions/browser/extension_registry.h" 26 #include "extensions/browser/extension_registry.h"
25 #include "extensions/common/extension.h" 27 #include "extensions/common/extension.h"
26 #include "extensions/common/manifest_constants.h" 28 #include "extensions/common/manifest_constants.h"
27 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
28 #include "webkit/browser/fileapi/external_mount_points.h" 30 #include "webkit/browser/fileapi/external_mount_points.h"
29 31
30 namespace chromeos { 32 namespace chromeos {
31 namespace file_system_provider { 33 namespace file_system_provider {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 file_systems->SetWithoutPathExpansion(kFileSystemId, file_system); 118 file_systems->SetWithoutPathExpansion(kFileSystemId, file_system);
117 extensions.SetWithoutPathExpansion(kExtensionId, file_systems); 119 extensions.SetWithoutPathExpansion(kExtensionId, file_systems);
118 120
119 pref_service->Set(prefs::kFileSystemProviderMounted, extensions); 121 pref_service->Set(prefs::kFileSystemProviderMounted, extensions);
120 } 122 }
121 123
122 } // namespace 124 } // namespace
123 125
124 class FileSystemProviderServiceTest : public testing::Test { 126 class FileSystemProviderServiceTest : public testing::Test {
125 protected: 127 protected:
126 FileSystemProviderServiceTest() {} 128 FileSystemProviderServiceTest() : profile_(NULL) {}
129
127 virtual ~FileSystemProviderServiceTest() {} 130 virtual ~FileSystemProviderServiceTest() {}
128 131
129 virtual void SetUp() OVERRIDE { 132 virtual void SetUp() OVERRIDE {
130 profile_.reset(new TestingProfile); 133 profile_manager_.reset(
134 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
135 ASSERT_TRUE(profile_manager_->SetUp());
136 profile_ = profile_manager_->CreateTestingProfile("test-user@example.com");
131 user_manager_ = new FakeUserManager(); 137 user_manager_ = new FakeUserManager();
132 user_manager_->AddUser(profile_->GetProfileName()); 138 user_manager_->AddUser(profile_->GetProfileName());
133 user_manager_enabler_.reset(new ScopedUserManagerEnabler(user_manager_)); 139 user_manager_enabler_.reset(new ScopedUserManagerEnabler(user_manager_));
134 extension_registry_.reset( 140 extension_registry_.reset(new extensions::ExtensionRegistry(profile_));
135 new extensions::ExtensionRegistry(profile_.get())); 141 service_.reset(new Service(profile_, extension_registry_.get()));
136 service_.reset(new Service(profile_.get(), extension_registry_.get()));
137 service_->SetFileSystemFactoryForTesting( 142 service_->SetFileSystemFactoryForTesting(
138 base::Bind(&FakeProvidedFileSystem::Create)); 143 base::Bind(&FakeProvidedFileSystem::Create));
139 extension_ = createFakeExtension(kExtensionId); 144 extension_ = createFakeExtension(kExtensionId);
140 } 145 }
141 146
142 content::TestBrowserThreadBundle thread_bundle_; 147 content::TestBrowserThreadBundle thread_bundle_;
143 scoped_ptr<TestingProfile> profile_; 148 scoped_ptr<TestingProfileManager> profile_manager_;
149 TestingProfile* profile_;
144 FakeUserManager* user_manager_; 150 FakeUserManager* user_manager_;
145 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; 151 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_;
146 scoped_ptr<extensions::ExtensionRegistry> extension_registry_; 152 scoped_ptr<extensions::ExtensionRegistry> extension_registry_;
147 scoped_ptr<Service> service_; 153 scoped_ptr<Service> service_;
148 scoped_refptr<extensions::Extension> extension_; 154 scoped_refptr<extensions::Extension> extension_;
149 }; 155 };
150 156
151 TEST_F(FileSystemProviderServiceTest, MountFileSystem) { 157 TEST_F(FileSystemProviderServiceTest, MountFileSystem) {
152 LoggingObserver observer; 158 LoggingObserver observer;
153 service_->AddObserver(&observer); 159 service_->AddObserver(&observer);
154 160
155 EXPECT_TRUE(service_->MountFileSystem( 161 EXPECT_TRUE(service_->MountFileSystem(
156 kExtensionId, kFileSystemId, kDisplayName, false /* writable */)); 162 kExtensionId, kFileSystemId, kDisplayName, false /* writable */));
157 163
158 ASSERT_EQ(1u, observer.mounts.size()); 164 ASSERT_EQ(1u, observer.mounts.size());
159 EXPECT_EQ(kExtensionId, observer.mounts[0].file_system_info().extension_id()); 165 EXPECT_EQ(kExtensionId, observer.mounts[0].file_system_info().extension_id());
160 EXPECT_EQ(kFileSystemId, 166 EXPECT_EQ(kFileSystemId,
161 observer.mounts[0].file_system_info().file_system_id()); 167 observer.mounts[0].file_system_info().file_system_id());
162 base::FilePath expected_mount_path = 168 base::FilePath expected_mount_path =
163 util::GetMountPath(profile_.get(), kExtensionId, kFileSystemId); 169 util::GetMountPath(profile_, kExtensionId, kFileSystemId);
164 EXPECT_EQ(expected_mount_path.AsUTF8Unsafe(), 170 EXPECT_EQ(expected_mount_path.AsUTF8Unsafe(),
165 observer.mounts[0].file_system_info().mount_path().AsUTF8Unsafe()); 171 observer.mounts[0].file_system_info().mount_path().AsUTF8Unsafe());
166 EXPECT_EQ(kDisplayName, observer.mounts[0].file_system_info().display_name()); 172 EXPECT_EQ(kDisplayName, observer.mounts[0].file_system_info().display_name());
167 EXPECT_FALSE(observer.mounts[0].file_system_info().writable()); 173 EXPECT_FALSE(observer.mounts[0].file_system_info().writable());
168 EXPECT_EQ(base::File::FILE_OK, observer.mounts[0].error()); 174 EXPECT_EQ(base::File::FILE_OK, observer.mounts[0].error());
169 ASSERT_EQ(0u, observer.unmounts.size()); 175 ASSERT_EQ(0u, observer.unmounts.size());
170 176
171 std::vector<ProvidedFileSystemInfo> file_system_info_list = 177 std::vector<ProvidedFileSystemInfo> file_system_info_list =
172 service_->GetProvidedFileSystemInfoList(); 178 service_->GetProvidedFileSystemInfoList();
173 ASSERT_EQ(1u, file_system_info_list.size()); 179 ASSERT_EQ(1u, file_system_info_list.size());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 TEST_F(FileSystemProviderServiceTest, UnmountFileSystem_OnExtensionUnload) { 274 TEST_F(FileSystemProviderServiceTest, UnmountFileSystem_OnExtensionUnload) {
269 LoggingObserver observer; 275 LoggingObserver observer;
270 service_->AddObserver(&observer); 276 service_->AddObserver(&observer);
271 277
272 EXPECT_TRUE(service_->MountFileSystem( 278 EXPECT_TRUE(service_->MountFileSystem(
273 kExtensionId, kFileSystemId, kDisplayName, false /* writable */)); 279 kExtensionId, kFileSystemId, kDisplayName, false /* writable */));
274 ASSERT_EQ(1u, observer.mounts.size()); 280 ASSERT_EQ(1u, observer.mounts.size());
275 281
276 // Directly call the observer's method. 282 // Directly call the observer's method.
277 service_->OnExtensionUnloaded( 283 service_->OnExtensionUnloaded(
278 profile_.get(), 284 profile_,
279 extension_.get(), 285 extension_.get(),
280 extensions::UnloadedExtensionInfo::REASON_DISABLE); 286 extensions::UnloadedExtensionInfo::REASON_DISABLE);
281 287
282 ASSERT_EQ(1u, observer.unmounts.size()); 288 ASSERT_EQ(1u, observer.unmounts.size());
283 EXPECT_EQ(base::File::FILE_OK, observer.unmounts[0].error()); 289 EXPECT_EQ(base::File::FILE_OK, observer.unmounts[0].error());
284 290
285 EXPECT_EQ(kExtensionId, 291 EXPECT_EQ(kExtensionId,
286 observer.unmounts[0].file_system_info().extension_id()); 292 observer.unmounts[0].file_system_info().extension_id());
287 EXPECT_EQ(kFileSystemId, 293 EXPECT_EQ(kFileSystemId,
288 observer.unmounts[0].file_system_info().file_system_id()); 294 observer.unmounts[0].file_system_info().file_system_id());
(...skipping 24 matching lines...) Expand all
313 319
314 std::vector<ProvidedFileSystemInfo> file_system_info_list = 320 std::vector<ProvidedFileSystemInfo> file_system_info_list =
315 service_->GetProvidedFileSystemInfoList(); 321 service_->GetProvidedFileSystemInfoList();
316 ASSERT_EQ(1u, file_system_info_list.size()); 322 ASSERT_EQ(1u, file_system_info_list.size());
317 323
318 service_->RemoveObserver(&observer); 324 service_->RemoveObserver(&observer);
319 } 325 }
320 326
321 TEST_F(FileSystemProviderServiceTest, RestoreFileSystem_OnExtensionLoad) { 327 TEST_F(FileSystemProviderServiceTest, RestoreFileSystem_OnExtensionLoad) {
322 // Create a fake entry in the preferences. 328 // Create a fake entry in the preferences.
323 RememberFakeFileSystem(profile_.get(), 329 RememberFakeFileSystem(
324 kExtensionId, 330 profile_, kExtensionId, kFileSystemId, kDisplayName, true /* writable */);
325 kFileSystemId,
326 kDisplayName,
327 true /* writable */);
328 331
329 // Create a new service instance in order to load remembered file systems 332 // Create a new service instance in order to load remembered file systems
330 // from preferences. 333 // from preferences.
331 scoped_ptr<Service> new_service( 334 scoped_ptr<Service> new_service(
332 new Service(profile_.get(), extension_registry_.get())); 335 new Service(profile_, extension_registry_.get()));
333 LoggingObserver observer; 336 LoggingObserver observer;
334 new_service->AddObserver(&observer); 337 new_service->AddObserver(&observer);
335 338
336 new_service->SetFileSystemFactoryForTesting( 339 new_service->SetFileSystemFactoryForTesting(
337 base::Bind(&FakeProvidedFileSystem::Create)); 340 base::Bind(&FakeProvidedFileSystem::Create));
338 341
339 EXPECT_EQ(0u, observer.mounts.size()); 342 EXPECT_EQ(0u, observer.mounts.size());
340 343
341 // Directly call the observer's method. 344 // Directly call the observer's method.
342 new_service->OnExtensionLoaded(profile_.get(), extension_.get()); 345 new_service->OnExtensionLoaded(profile_, extension_.get());
343 346
344 ASSERT_EQ(1u, observer.mounts.size()); 347 ASSERT_EQ(1u, observer.mounts.size());
345 EXPECT_EQ(base::File::FILE_OK, observer.mounts[0].error()); 348 EXPECT_EQ(base::File::FILE_OK, observer.mounts[0].error());
346 349
347 EXPECT_EQ(kExtensionId, observer.mounts[0].file_system_info().extension_id()); 350 EXPECT_EQ(kExtensionId, observer.mounts[0].file_system_info().extension_id());
348 EXPECT_EQ(kFileSystemId, 351 EXPECT_EQ(kFileSystemId,
349 observer.mounts[0].file_system_info().file_system_id()); 352 observer.mounts[0].file_system_info().file_system_id());
350 EXPECT_TRUE(observer.mounts[0].file_system_info().writable()); 353 EXPECT_TRUE(observer.mounts[0].file_system_info().writable());
351 354
352 std::vector<ProvidedFileSystemInfo> file_system_info_list = 355 std::vector<ProvidedFileSystemInfo> file_system_info_list =
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 const base::DictionaryValue* file_systems = NULL; 478 const base::DictionaryValue* file_systems = NULL;
476 EXPECT_FALSE(extensions->GetDictionaryWithoutPathExpansion(kExtensionId, 479 EXPECT_FALSE(extensions->GetDictionaryWithoutPathExpansion(kExtensionId,
477 &file_systems)); 480 &file_systems));
478 } 481 }
479 482
480 service_->RemoveObserver(&observer); 483 service_->RemoveObserver(&observer);
481 } 484 }
482 485
483 } // namespace file_system_provider 486 } // namespace file_system_provider
484 } // namespace chromeos 487 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698