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

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

Powered by Google App Engine
This is Rietveld 408576698