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

Unified Diff: chrome/browser/extensions/api/image_writer_private/test_utils.h

Issue 336923002: Adds API test for imageWriterPrivate.writeFromFile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chrome OS fixes. Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/image_writer_private/test_utils.h
diff --git a/chrome/browser/extensions/api/image_writer_private/test_utils.h b/chrome/browser/extensions/api/image_writer_private/test_utils.h
index 80399f66d61ef8ea54d711a6ca661ae072971781..25a6941d477130616524e13e473609a1da9b8ed3 100644
--- a/chrome/browser/extensions/api/image_writer_private/test_utils.h
+++ b/chrome/browser/extensions/api/image_writer_private/test_utils.h
@@ -65,20 +65,6 @@ class FakeDiskMountManager : public chromeos::disks::MockDiskMountManager {
virtual void UnmountDeviceRecursively(
const std::string& device_path,
const UnmountDeviceRecursivelyCallbackType& callback) OVERRIDE;
- /*
- MOCK_METHOD1(AddObserver, void(chromeos::disks::DiskMountManager::Observer*));
- MOCK_METHOD1(RemoveObserver,
- void(chromeos::disks::DiskMountManager::Observer*));
- MOCK_CONST_METHOD0(disks, const DiskMap&());
- MOCK_CONST_METHOD1(FindDiskBySourcePath, const Disk*(const std::string&));
- MOCK_CONST_METHOD0(mount_points, const MountPointMap&());
- MOCK_METHOD0(RequestMountInfoRefresh, void());
- MOCK_METHOD4(MountPath, void(const std::string&, const std::string&, const
- std::string&, chromeos::MountType));
- MOCK_METHOD3(UnmountPath, void(const std::string&, chromeos::UnmountOptions,
- const UnmountPathCallback&));
- MOCK_METHOD1(FormatMountedDevice, void(const std::string&));
- */
private:
DiskMap disks_;
@@ -105,11 +91,19 @@ class FakeImageWriterClient : public ImageWriterUtilityClient {
virtual void Shutdown() OVERRIDE;
+ // Sets a callback for when a Write call is made.
+ void SetWriteCallback(const base::Closure& write_callback);
+ // Sets a callback for when a Verify call is made.
+ void SetVerifyCallback(const base::Closure& verify_callback);
+
+ // Triggers the progress callback.
void Progress(int64 progress);
+ // Triggers the success callback.
void Success();
+ // Triggers the error callback.
void Error(const std::string& message);
+ // Triggers the cancel callback.
void Cancel();
- static scoped_refptr<FakeImageWriterClient> Create();
private:
virtual ~FakeImageWriterClient();
@@ -118,23 +112,20 @@ class FakeImageWriterClient : public ImageWriterUtilityClient {
SuccessCallback success_callback_;
ErrorCallback error_callback_;
CancelCallback cancel_callback_;
-};
-
-// Base class for unit tests that manages creating image and device files.
-class ImageWriterUnitTestBase : public testing::Test {
- protected:
- ImageWriterUnitTestBase();
- virtual ~ImageWriterUnitTestBase();
- virtual void SetUp() OVERRIDE;
+ base::Closure write_callback_;
+ base::Closure verify_callback_;
+};
- virtual void TearDown() OVERRIDE;
+class ImageWriterTestUtils {
+ public:
+ ImageWriterTestUtils();
+ virtual ~ImageWriterTestUtils();
// Verifies that the data in image_path was written to the file at
// device_path. This is different from base::ContentsEqual because the device
// may be larger than the image.
- bool ImageWrittenToDevice(const base::FilePath& image_path,
- const base::FilePath& device_path);
+ bool ImageWrittenToDevice();
// Fills |file| with |length| bytes of |pattern|, overwriting any existing
// data.
@@ -142,10 +133,47 @@ class ImageWriterUnitTestBase : public testing::Test {
const int pattern,
const int length);
+ // Set up the test utils, creating temporary folders and such.
+ // Note that browser tests should use the alternate form and pass "true" as an
+ // argument.
+ virtual void SetUp();
+ // Set up the test utils, creating temporary folders and such. If
+ // |is_browser_test| is true then it will use alternate initialization
+ // appropriate for a browser test. This should be run in
+ // |SetUpInProcessBrowserTestFixture|.
+ virtual void SetUp(bool is_browser_test);
+
+ virtual void TearDown();
+
+ const base::FilePath& GetTempDir();
+ const base::FilePath& GetImagePath();
+ const base::FilePath& GetDevicePath();
+
+#if !defined(OS_CHROMEOS)
+ FakeImageWriterClient* GetUtilityClient();
+#endif
+
+ protected:
base::ScopedTempDir temp_dir_;
base::FilePath test_image_path_;
base::FilePath test_device_path_;
+#if !defined(OS_CHROMEOS)
+ scoped_refptr<FakeImageWriterClient> client_;
+#endif
+};
+
+// Base class for unit tests that manages creating image and device files.
+class ImageWriterUnitTestBase : public testing::Test {
+ protected:
+ ImageWriterUnitTestBase();
+ virtual ~ImageWriterUnitTestBase();
+
+ virtual void SetUp() OVERRIDE;
+ virtual void TearDown() OVERRIDE;
+
+ ImageWriterTestUtils test_utils_;
+
private:
content::TestBrowserThreadBundle thread_bundle_;
};

Powered by Google App Engine
This is Rietveld 408576698