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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/fileapi/file_stream_reader_unittest.cc

Issue 1165913002: [Cleanup] Used scoped pointers in KeyedServiceFactory's SetTestingFactory functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Finish renaming profile -> context Created 5 years, 6 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/fileapi/file_stream_reade r.h" 5 #include "chrome/browser/chromeos/file_system_provider/fileapi/file_stream_reade r.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"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 const base::FilePath& file_path) { 64 const base::FilePath& file_path) {
65 const std::string origin = std::string("chrome-extension://") + kExtensionId; 65 const std::string origin = std::string("chrome-extension://") + kExtensionId;
66 const storage::ExternalMountPoints* const mount_points = 66 const storage::ExternalMountPoints* const mount_points =
67 storage::ExternalMountPoints::GetSystemInstance(); 67 storage::ExternalMountPoints::GetSystemInstance();
68 return mount_points->CreateCrackedFileSystemURL( 68 return mount_points->CreateCrackedFileSystemURL(
69 GURL(origin), 69 GURL(origin),
70 storage::kFileSystemTypeExternal, 70 storage::kFileSystemTypeExternal,
71 base::FilePath::FromUTF8Unsafe(mount_point_name).Append(file_path)); 71 base::FilePath::FromUTF8Unsafe(mount_point_name).Append(file_path));
72 } 72 }
73 73
74 // Creates a Service instance. Used to be able to destroy the service in
75 // TearDown().
76 KeyedService* CreateService(content::BrowserContext* context) {
77 return new Service(Profile::FromBrowserContext(context),
78 extensions::ExtensionRegistry::Get(context));
79 }
80
81 } // namespace 74 } // namespace
82 75
83 class FileSystemProviderFileStreamReader : public testing::Test { 76 class FileSystemProviderFileStreamReader : public testing::Test {
84 protected: 77 protected:
85 FileSystemProviderFileStreamReader() : profile_(NULL), fake_file_(NULL) {} 78 FileSystemProviderFileStreamReader() : profile_(NULL), fake_file_(NULL) {}
86 ~FileSystemProviderFileStreamReader() override {} 79 ~FileSystemProviderFileStreamReader() override {}
87 80
88 void SetUp() override { 81 void SetUp() override {
89 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); 82 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
90 profile_manager_.reset( 83 profile_manager_.reset(
91 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 84 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
92 ASSERT_TRUE(profile_manager_->SetUp()); 85 ASSERT_TRUE(profile_manager_->SetUp());
93 profile_ = profile_manager_->CreateTestingProfile("testing-profile"); 86 profile_ = profile_manager_->CreateTestingProfile("testing-profile");
94 87
95 ServiceFactory::GetInstance()->SetTestingFactory(profile_, &CreateService);
96 Service* service = Service::Get(profile_); // Owned by its factory. 88 Service* service = Service::Get(profile_); // Owned by its factory.
97 service->SetFileSystemFactoryForTesting( 89 service->SetFileSystemFactoryForTesting(
98 base::Bind(&FakeProvidedFileSystem::Create)); 90 base::Bind(&FakeProvidedFileSystem::Create));
99 91
100 const base::File::Error result = service->MountFileSystem( 92 const base::File::Error result = service->MountFileSystem(
101 kExtensionId, MountOptions(kFileSystemId, "Testing File System")); 93 kExtensionId, MountOptions(kFileSystemId, "Testing File System"));
102 ASSERT_EQ(base::File::FILE_OK, result); 94 ASSERT_EQ(base::File::FILE_OK, result);
103 FakeProvidedFileSystem* provided_file_system = 95 FakeProvidedFileSystem* provided_file_system =
104 static_cast<FakeProvidedFileSystem*>( 96 static_cast<FakeProvidedFileSystem*>(
105 service->GetProvidedFileSystem(kExtensionId, kFileSystemId)); 97 service->GetProvidedFileSystem(kExtensionId, kFileSystemId));
106 ASSERT_TRUE(provided_file_system); 98 ASSERT_TRUE(provided_file_system);
107 fake_file_ = provided_file_system->GetEntry(base::FilePath(kFakeFilePath)); 99 fake_file_ = provided_file_system->GetEntry(base::FilePath(kFakeFilePath));
108 ASSERT_TRUE(fake_file_); 100 ASSERT_TRUE(fake_file_);
109 const ProvidedFileSystemInfo& file_system_info = 101 const ProvidedFileSystemInfo& file_system_info =
110 service->GetProvidedFileSystem(kExtensionId, kFileSystemId) 102 service->GetProvidedFileSystem(kExtensionId, kFileSystemId)
111 ->GetFileSystemInfo(); 103 ->GetFileSystemInfo();
112 const std::string mount_point_name = 104 const std::string mount_point_name =
113 file_system_info.mount_path().BaseName().AsUTF8Unsafe(); 105 file_system_info.mount_path().BaseName().AsUTF8Unsafe();
114 106
115 file_url_ = CreateFileSystemURL(mount_point_name, 107 file_url_ = CreateFileSystemURL(mount_point_name,
116 base::FilePath(kFakeFilePath + 1)); 108 base::FilePath(kFakeFilePath + 1));
117 ASSERT_TRUE(file_url_.is_valid()); 109 ASSERT_TRUE(file_url_.is_valid());
118 wrong_file_url_ = CreateFileSystemURL( 110 wrong_file_url_ = CreateFileSystemURL(
119 mount_point_name, base::FilePath(FILE_PATH_LITERAL("im-not-here.txt"))); 111 mount_point_name, base::FilePath(FILE_PATH_LITERAL("im-not-here.txt")));
120 ASSERT_TRUE(wrong_file_url_.is_valid()); 112 ASSERT_TRUE(wrong_file_url_.is_valid());
121 } 113 }
122 114
123 void TearDown() override {
124 // Setting the testing factory to NULL will destroy the created service
125 // associated with the testing profile.
126 ServiceFactory::GetInstance()->SetTestingFactory(profile_, NULL);
127 }
128
129 content::TestBrowserThreadBundle thread_bundle_; 115 content::TestBrowserThreadBundle thread_bundle_;
130 base::ScopedTempDir data_dir_; 116 base::ScopedTempDir data_dir_;
131 scoped_ptr<TestingProfileManager> profile_manager_; 117 scoped_ptr<TestingProfileManager> profile_manager_;
132 TestingProfile* profile_; // Owned by TestingProfileManager. 118 TestingProfile* profile_; // Owned by TestingProfileManager.
133 const FakeEntry* fake_file_; // Owned by FakePRovidedFileSystem. 119 const FakeEntry* fake_file_; // Owned by FakePRovidedFileSystem.
134 storage::FileSystemURL file_url_; 120 storage::FileSystemURL file_url_;
135 storage::FileSystemURL wrong_file_url_; 121 storage::FileSystemURL wrong_file_url_;
136 }; 122 };
137 123
138 TEST_F(FileSystemProviderFileStreamReader, Read_AllAtOnce) { 124 TEST_F(FileSystemProviderFileStreamReader, Read_AllAtOnce) {
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 EXPECT_EQ(net::ERR_IO_PENDING, result); 348 EXPECT_EQ(net::ERR_IO_PENDING, result);
363 base::RunLoop().RunUntilIdle(); 349 base::RunLoop().RunUntilIdle();
364 350
365 ASSERT_EQ(1u, logger.results().size()); 351 ASSERT_EQ(1u, logger.results().size());
366 EXPECT_LT(0, logger.results()[0]); 352 EXPECT_LT(0, logger.results()[0]);
367 EXPECT_EQ(fake_file_->metadata->size, logger.results()[0]); 353 EXPECT_EQ(fake_file_->metadata->size, logger.results()[0]);
368 } 354 }
369 355
370 } // namespace file_system_provider 356 } // namespace file_system_provider
371 } // namespace chromeos 357 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698