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

Side by Side Diff: chrome/browser/extensions/api/image_writer_private/test_utils.cc

Issue 282853003: Unmounts volumes before writing to a drive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds compile guard to Chrome OS includes in test_utils.h Created 6 years, 7 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
« no previous file with comments | « chrome/browser/extensions/api/image_writer_private/test_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #if defined(OS_CHROMEOS) 7 #if defined(OS_CHROMEOS)
8 #include "chromeos/dbus/dbus_thread_manager.h" 8 #include "chromeos/dbus/dbus_thread_manager.h"
9 #include "chromeos/dbus/fake_dbus_thread_manager.h" 9 #include "chromeos/dbus/fake_dbus_thread_manager.h"
10 #include "chromeos/dbus/fake_image_burner_client.h" 10 #include "chromeos/dbus/fake_image_burner_client.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 }; 48 };
49 49
50 } // namespace 50 } // namespace
51 #endif 51 #endif
52 52
53 MockOperationManager::MockOperationManager() : OperationManager(NULL) {} 53 MockOperationManager::MockOperationManager() : OperationManager(NULL) {}
54 MockOperationManager::MockOperationManager(content::BrowserContext* context) 54 MockOperationManager::MockOperationManager(content::BrowserContext* context)
55 : OperationManager(context) {} 55 : OperationManager(context) {}
56 MockOperationManager::~MockOperationManager() {} 56 MockOperationManager::~MockOperationManager() {}
57 57
58 #if defined(OS_CHROMEOS)
59 FakeDiskMountManager::FakeDiskMountManager() {}
60 FakeDiskMountManager::~FakeDiskMountManager() {}
61
62 void FakeDiskMountManager::UnmountDeviceRecursively(
63 const std::string& device_path,
64 const UnmountDeviceRecursivelyCallbackType& callback) {
65 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true));
66 }
67 #endif
68
58 FakeImageWriterClient::FakeImageWriterClient() {} 69 FakeImageWriterClient::FakeImageWriterClient() {}
59 FakeImageWriterClient::~FakeImageWriterClient() {} 70 FakeImageWriterClient::~FakeImageWriterClient() {}
60 71
61 void FakeImageWriterClient::Write(const ProgressCallback& progress_callback, 72 void FakeImageWriterClient::Write(const ProgressCallback& progress_callback,
62 const SuccessCallback& success_callback, 73 const SuccessCallback& success_callback,
63 const ErrorCallback& error_callback, 74 const ErrorCallback& error_callback,
64 const base::FilePath& source, 75 const base::FilePath& source,
65 const base::FilePath& target) { 76 const base::FilePath& target) {
66 progress_callback_ = progress_callback; 77 progress_callback_ = progress_callback;
67 success_callback_ = success_callback; 78 success_callback_ = success_callback;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 135
125 #if defined(OS_CHROMEOS) 136 #if defined(OS_CHROMEOS)
126 if (!chromeos::DBusThreadManager::IsInitialized()) { 137 if (!chromeos::DBusThreadManager::IsInitialized()) {
127 chromeos::FakeDBusThreadManager* fake_dbus_thread_manager = 138 chromeos::FakeDBusThreadManager* fake_dbus_thread_manager =
128 new chromeos::FakeDBusThreadManager; 139 new chromeos::FakeDBusThreadManager;
129 scoped_ptr<chromeos::ImageBurnerClient> 140 scoped_ptr<chromeos::ImageBurnerClient>
130 image_burner_fake(new ImageWriterFakeImageBurnerClient()); 141 image_burner_fake(new ImageWriterFakeImageBurnerClient());
131 fake_dbus_thread_manager->SetImageBurnerClient(image_burner_fake.Pass()); 142 fake_dbus_thread_manager->SetImageBurnerClient(image_burner_fake.Pass());
132 chromeos::DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager); 143 chromeos::DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager);
133 } 144 }
145 FakeDiskMountManager* disk_manager = new FakeDiskMountManager();
146 chromeos::disks::DiskMountManager::InitializeForTesting(disk_manager);
147
148 // Adds a disk entry for test_device_path_ with the same device and file path.
149 disk_manager->CreateDiskEntryForMountDevice(
150 chromeos::disks::DiskMountManager::MountPointInfo(
151 test_device_path_.value(),
152 "/dummy/mount",
153 chromeos::MOUNT_TYPE_DEVICE,
154 chromeos::disks::MOUNT_CONDITION_NONE),
155 "device_id",
156 "device_label",
157 "Vendor",
158 "Product",
159 chromeos::DEVICE_TYPE_USB,
160 kTestFileSize,
161 true,
162 true,
163 false);
164 disk_manager->SetupDefaultReplies();
134 #endif 165 #endif
135 } 166 }
136 167
137 void ImageWriterUnitTestBase::TearDown() { 168 void ImageWriterUnitTestBase::TearDown() {
138 #if defined(OS_CHROMEOS) 169 #if defined(OS_CHROMEOS)
139 chromeos::DBusThreadManager::Shutdown(); 170 chromeos::DBusThreadManager::Shutdown();
171 chromeos::disks::DiskMountManager::Shutdown();
140 #endif 172 #endif
141 } 173 }
142 174
143 bool ImageWriterUnitTestBase::ImageWrittenToDevice( 175 bool ImageWriterUnitTestBase::ImageWrittenToDevice(
144 const base::FilePath& image_path, 176 const base::FilePath& image_path,
145 const base::FilePath& device_path) { 177 const base::FilePath& device_path) {
146 scoped_ptr<char[]> image_buffer(new char[kTestFileSize]); 178 scoped_ptr<char[]> image_buffer(new char[kTestFileSize]);
147 scoped_ptr<char[]> device_buffer(new char[kTestFileSize]); 179 scoped_ptr<char[]> device_buffer(new char[kTestFileSize]);
148 180
149 int image_bytes_read = 181 int image_bytes_read =
(...skipping 15 matching lines...) Expand all
165 const int pattern, 197 const int pattern,
166 const int length) { 198 const int length) {
167 scoped_ptr<char[]> buffer(new char[length]); 199 scoped_ptr<char[]> buffer(new char[length]);
168 memset(buffer.get(), pattern, length); 200 memset(buffer.get(), pattern, length);
169 201
170 return base::WriteFile(file, buffer.get(), length) == length; 202 return base::WriteFile(file, buffer.get(), length) == length;
171 } 203 }
172 204
173 } // namespace image_writer 205 } // namespace image_writer
174 } // namespace extensions 206 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/image_writer_private/test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698