OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extensions/api/image_writer_private/test_utils.h" | 5 #include "chrome/browser/extensions/api/image_writer_private/test_utils.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), | 158 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), |
159 &test_image_path_)); | 159 &test_image_path_)); |
160 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), | 160 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), |
161 &test_device_path_)); | 161 &test_device_path_)); |
162 | 162 |
163 ASSERT_TRUE(FillFile(test_image_path_, kImagePattern, kTestFileSize)); | 163 ASSERT_TRUE(FillFile(test_image_path_, kImagePattern, kTestFileSize)); |
164 ASSERT_TRUE(FillFile(test_device_path_, kDevicePattern, kTestFileSize)); | 164 ASSERT_TRUE(FillFile(test_device_path_, kDevicePattern, kTestFileSize)); |
165 | 165 |
166 #if defined(OS_CHROMEOS) | 166 #if defined(OS_CHROMEOS) |
167 if (!chromeos::DBusThreadManager::IsInitialized()) { | 167 if (!chromeos::DBusThreadManager::IsInitialized()) { |
168 scoped_ptr<chromeos::DBusThreadManagerSetter> dbus_setter = | 168 std::unique_ptr<chromeos::DBusThreadManagerSetter> dbus_setter = |
169 chromeos::DBusThreadManager::GetSetterForTesting(); | 169 chromeos::DBusThreadManager::GetSetterForTesting(); |
170 scoped_ptr<chromeos::ImageBurnerClient> | 170 std::unique_ptr<chromeos::ImageBurnerClient> image_burner_fake( |
171 image_burner_fake(new ImageWriterFakeImageBurnerClient()); | 171 new ImageWriterFakeImageBurnerClient()); |
172 dbus_setter->SetImageBurnerClient(std::move(image_burner_fake)); | 172 dbus_setter->SetImageBurnerClient(std::move(image_burner_fake)); |
173 } | 173 } |
174 | 174 |
175 FakeDiskMountManager* disk_manager = new FakeDiskMountManager(); | 175 FakeDiskMountManager* disk_manager = new FakeDiskMountManager(); |
176 chromeos::disks::DiskMountManager::InitializeForTesting(disk_manager); | 176 chromeos::disks::DiskMountManager::InitializeForTesting(disk_manager); |
177 | 177 |
178 // Adds a disk entry for test_device_path_ with the same device and file path. | 178 // Adds a disk entry for test_device_path_ with the same device and file path. |
179 disk_manager->CreateDiskEntryForMountDevice( | 179 disk_manager->CreateDiskEntryForMountDevice( |
180 chromeos::disks::DiskMountManager::MountPointInfo( | 180 chromeos::disks::DiskMountManager::MountPointInfo( |
181 test_device_path_.value(), | 181 test_device_path_.value(), |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 return test_device_path_; | 223 return test_device_path_; |
224 } | 224 } |
225 | 225 |
226 #if !defined(OS_CHROMEOS) | 226 #if !defined(OS_CHROMEOS) |
227 FakeImageWriterClient* ImageWriterTestUtils::GetUtilityClient() { | 227 FakeImageWriterClient* ImageWriterTestUtils::GetUtilityClient() { |
228 return client_.get(); | 228 return client_.get(); |
229 } | 229 } |
230 #endif | 230 #endif |
231 | 231 |
232 bool ImageWriterTestUtils::ImageWrittenToDevice() { | 232 bool ImageWriterTestUtils::ImageWrittenToDevice() { |
233 scoped_ptr<char[]> image_buffer(new char[kTestFileSize]); | 233 std::unique_ptr<char[]> image_buffer(new char[kTestFileSize]); |
234 scoped_ptr<char[]> device_buffer(new char[kTestFileSize]); | 234 std::unique_ptr<char[]> device_buffer(new char[kTestFileSize]); |
235 | 235 |
236 int image_bytes_read = | 236 int image_bytes_read = |
237 ReadFile(test_image_path_, image_buffer.get(), kTestFileSize); | 237 ReadFile(test_image_path_, image_buffer.get(), kTestFileSize); |
238 | 238 |
239 if (image_bytes_read < 0) | 239 if (image_bytes_read < 0) |
240 return false; | 240 return false; |
241 | 241 |
242 int device_bytes_read = | 242 int device_bytes_read = |
243 ReadFile(test_device_path_, device_buffer.get(), kTestFileSize); | 243 ReadFile(test_device_path_, device_buffer.get(), kTestFileSize); |
244 | 244 |
245 if (image_bytes_read != device_bytes_read) | 245 if (image_bytes_read != device_bytes_read) |
246 return false; | 246 return false; |
247 | 247 |
248 return memcmp(image_buffer.get(), device_buffer.get(), image_bytes_read) == 0; | 248 return memcmp(image_buffer.get(), device_buffer.get(), image_bytes_read) == 0; |
249 } | 249 } |
250 | 250 |
251 bool ImageWriterTestUtils::FillFile(const base::FilePath& file, | 251 bool ImageWriterTestUtils::FillFile(const base::FilePath& file, |
252 const int pattern, | 252 const int pattern, |
253 const int length) { | 253 const int length) { |
254 scoped_ptr<char[]> buffer(new char[length]); | 254 std::unique_ptr<char[]> buffer(new char[length]); |
255 memset(buffer.get(), pattern, length); | 255 memset(buffer.get(), pattern, length); |
256 | 256 |
257 return base::WriteFile(file, buffer.get(), length) == length; | 257 return base::WriteFile(file, buffer.get(), length) == length; |
258 } | 258 } |
259 | 259 |
260 ImageWriterUnitTestBase::ImageWriterUnitTestBase() | 260 ImageWriterUnitTestBase::ImageWriterUnitTestBase() |
261 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { | 261 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
262 } | 262 } |
263 ImageWriterUnitTestBase::~ImageWriterUnitTestBase() { | 263 ImageWriterUnitTestBase::~ImageWriterUnitTestBase() { |
264 } | 264 } |
265 | 265 |
266 void ImageWriterUnitTestBase::SetUp() { | 266 void ImageWriterUnitTestBase::SetUp() { |
267 testing::Test::SetUp(); | 267 testing::Test::SetUp(); |
268 test_utils_.SetUp(); | 268 test_utils_.SetUp(); |
269 } | 269 } |
270 | 270 |
271 void ImageWriterUnitTestBase::TearDown() { | 271 void ImageWriterUnitTestBase::TearDown() { |
272 testing::Test::TearDown(); | 272 testing::Test::TearDown(); |
273 test_utils_.TearDown(); | 273 test_utils_.TearDown(); |
274 } | 274 } |
275 | 275 |
276 } // namespace image_writer | 276 } // namespace image_writer |
277 } // namespace extensions | 277 } // namespace extensions |
OLD | NEW |