Index: chrome/browser/extensions/api/image_writer_private/operation_unittest.cc |
diff --git a/chrome/browser/extensions/api/image_writer_private/operation_unittest.cc b/chrome/browser/extensions/api/image_writer_private/operation_unittest.cc |
index 1c65efb9091906ac223d0b0020fc2ad6ee7c1ac3..8012209eb9c91fddc28228d174c8d35c4a2f8cfb 100644 |
--- a/chrome/browser/extensions/api/image_writer_private/operation_unittest.cc |
+++ b/chrome/browser/extensions/api/image_writer_private/operation_unittest.cc |
@@ -77,9 +77,20 @@ class ImageWriterOperationTest : public ImageWriterUnitTestBase { |
zip_file_ = temp_dir_.path().AppendASCII("test_image.zip"); |
ASSERT_TRUE(zip::Zip(image_dir, zip_file_, true)); |
+ |
+ // Operation setup. |
+ operation_ = new OperationForTest(manager_.AsWeakPtr(), |
+ kDummyExtensionId, |
+ test_device_path_.AsUTF8Unsafe()); |
+ client_ = FakeImageWriterClient::Create(); |
+ operation_->SetImagePath(test_image_path_); |
} |
virtual void TearDown() OVERRIDE { |
+ // Ensure all callbacks have been destroyed and cleanup occurs. |
+ client_->Shutdown(); |
+ operation_->Cancel(); |
+ |
ImageWriterUnitTestBase::TearDown(); |
} |
@@ -87,36 +98,31 @@ class ImageWriterOperationTest : public ImageWriterUnitTestBase { |
base::FilePath zip_file_; |
MockOperationManager manager_; |
+ scoped_refptr<FakeImageWriterClient> client_; |
+ scoped_refptr<OperationForTest> operation_; |
}; |
} // namespace |
+// Unizpping a non-zip should do nothing. |
TEST_F(ImageWriterOperationTest, UnzipNonZipFile) { |
- scoped_refptr<OperationForTest> operation( |
- new OperationForTest(manager_.AsWeakPtr(), |
- kDummyExtensionId, |
- test_device_path_.AsUTF8Unsafe())); |
- |
EXPECT_CALL(manager_, OnProgress(kDummyExtensionId, _, _)).Times(0); |
- operation->SetImagePath(test_image_path_); |
+ EXPECT_CALL(manager_, OnError(kDummyExtensionId, _, _, _)).Times(0); |
+ EXPECT_CALL(manager_, OnProgress(kDummyExtensionId, _, _)).Times(0); |
+ EXPECT_CALL(manager_, OnComplete(kDummyExtensionId)).Times(0); |
- operation->Start(); |
+ operation_->Start(); |
content::BrowserThread::PostTask( |
content::BrowserThread::FILE, |
FROM_HERE, |
base::Bind( |
- &OperationForTest::Unzip, operation, base::Bind(&base::DoNothing))); |
+ &OperationForTest::Unzip, operation_, base::Bind(&base::DoNothing))); |
base::RunLoop().RunUntilIdle(); |
} |
TEST_F(ImageWriterOperationTest, UnzipZipFile) { |
- scoped_refptr<OperationForTest> operation( |
- new OperationForTest(manager_.AsWeakPtr(), |
- kDummyExtensionId, |
- test_device_path_.AsUTF8Unsafe())); |
- |
EXPECT_CALL(manager_, OnError(kDummyExtensionId, _, _, _)).Times(0); |
EXPECT_CALL(manager_, |
OnProgress(kDummyExtensionId, image_writer_api::STAGE_UNZIP, _)) |
@@ -128,27 +134,25 @@ TEST_F(ImageWriterOperationTest, UnzipZipFile) { |
OnProgress(kDummyExtensionId, image_writer_api::STAGE_UNZIP, 100)) |
.Times(AtLeast(1)); |
- operation->SetImagePath(zip_file_); |
+ operation_->SetImagePath(zip_file_); |
- operation->Start(); |
+ operation_->Start(); |
content::BrowserThread::PostTask( |
content::BrowserThread::FILE, |
FROM_HERE, |
base::Bind( |
- &OperationForTest::Unzip, operation, base::Bind(&base::DoNothing))); |
+ &OperationForTest::Unzip, operation_, base::Bind(&base::DoNothing))); |
base::RunLoop().RunUntilIdle(); |
- EXPECT_TRUE(base::ContentsEqual(image_path_, operation->GetImagePath())); |
+ EXPECT_TRUE(base::ContentsEqual(image_path_, operation_->GetImagePath())); |
} |
#if defined(OS_LINUX) |
TEST_F(ImageWriterOperationTest, WriteImageToDevice) { |
- |
- scoped_refptr<OperationForTest> operation( |
- new OperationForTest(manager_.AsWeakPtr(), |
- kDummyExtensionId, |
- test_device_path_.AsUTF8Unsafe())); |
+#if !defined(OS_CHROMEOS) |
+ operation_->SetUtilityClientForTesting(client_); |
+#endif |
EXPECT_CALL(manager_, OnError(kDummyExtensionId, _, _, _)).Times(0); |
EXPECT_CALL(manager_, |
@@ -161,34 +165,32 @@ TEST_F(ImageWriterOperationTest, WriteImageToDevice) { |
OnProgress(kDummyExtensionId, image_writer_api::STAGE_WRITE, 100)) |
.Times(AtLeast(1)); |
- operation->SetImagePath(test_image_path_); |
- |
- operation->Start(); |
+ operation_->Start(); |
content::BrowserThread::PostTask( |
content::BrowserThread::FILE, |
FROM_HERE, |
base::Bind( |
- &OperationForTest::Write, operation, base::Bind(&base::DoNothing))); |
+ &OperationForTest::Write, operation_, base::Bind(&base::DoNothing))); |
base::RunLoop().RunUntilIdle(); |
#if !defined(OS_CHROMEOS) |
- // Chrome OS tests don't actually write to the disk because that's handled by |
- // the DBUS process. |
- EXPECT_TRUE(base::ContentsEqual(test_image_path_, test_device_path_)); |
+ client_->Progress(0); |
+ client_->Progress(kTestFileSize / 2); |
+ client_->Progress(kTestFileSize); |
+ client_->Success(); |
+ |
+ base::RunLoop().RunUntilIdle(); |
#endif |
} |
#endif |
-#if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
+#if !defined(OS_CHROMEOS) |
// Chrome OS doesn't support verification in the ImageBurner, so these two tests |
// are skipped. |
TEST_F(ImageWriterOperationTest, VerifyFileSuccess) { |
- scoped_refptr<OperationForTest> operation( |
- new OperationForTest(manager_.AsWeakPtr(), |
- kDummyExtensionId, |
- test_device_path_.AsUTF8Unsafe())); |
+ operation_->SetUtilityClientForTesting(client_); |
EXPECT_CALL(manager_, OnError(kDummyExtensionId, _, _, _)).Times(0); |
EXPECT_CALL( |
@@ -205,60 +207,64 @@ TEST_F(ImageWriterOperationTest, VerifyFileSuccess) { |
.Times(AtLeast(1)); |
FillFile(test_device_path_, kImagePattern, kTestFileSize); |
- operation->SetImagePath(test_image_path_); |
- operation->Start(); |
+ operation_->Start(); |
content::BrowserThread::PostTask(content::BrowserThread::FILE, |
FROM_HERE, |
base::Bind(&OperationForTest::VerifyWrite, |
- operation, |
+ operation_, |
base::Bind(&base::DoNothing))); |
base::RunLoop().RunUntilIdle(); |
+ |
+ client_->Progress(0); |
+ client_->Progress(kTestFileSize / 2); |
+ client_->Progress(kTestFileSize); |
+ client_->Success(); |
+ |
+ base::RunLoop().RunUntilIdle(); |
} |
TEST_F(ImageWriterOperationTest, VerifyFileFailure) { |
- scoped_refptr<OperationForTest> operation( |
- new OperationForTest(manager_.AsWeakPtr(), |
- kDummyExtensionId, |
- test_device_path_.AsUTF8Unsafe())); |
+ operation_->SetUtilityClientForTesting(client_); |
EXPECT_CALL( |
manager_, |
- OnError(kDummyExtensionId, image_writer_api::STAGE_VERIFYWRITE, _, _)) |
- .Times(1); |
- EXPECT_CALL( |
- manager_, |
OnProgress(kDummyExtensionId, image_writer_api::STAGE_VERIFYWRITE, _)) |
.Times(AnyNumber()); |
EXPECT_CALL( |
manager_, |
OnProgress(kDummyExtensionId, image_writer_api::STAGE_VERIFYWRITE, 100)) |
.Times(0); |
+ EXPECT_CALL(manager_, OnComplete(kDummyExtensionId)).Times(0); |
+ EXPECT_CALL( |
+ manager_, |
+ OnError(kDummyExtensionId, image_writer_api::STAGE_VERIFYWRITE, _, _)) |
+ .Times(1); |
FillFile(test_device_path_, kDevicePattern, kTestFileSize); |
- operation->SetImagePath(test_image_path_); |
- operation->Start(); |
+ operation_->Start(); |
content::BrowserThread::PostTask(content::BrowserThread::FILE, |
FROM_HERE, |
base::Bind(&OperationForTest::VerifyWrite, |
- operation, |
+ operation_, |
base::Bind(&base::DoNothing))); |
base::RunLoop().RunUntilIdle(); |
+ |
+ client_->Progress(0); |
+ client_->Progress(kTestFileSize / 2); |
+ client_->Error(error::kVerificationFailed); |
+ |
+ base::RunLoop().RunUntilIdle(); |
} |
#endif |
-// Tests that on creation the operation has the expected state. |
+// Tests that on creation the operation_ has the expected state. |
TEST_F(ImageWriterOperationTest, Creation) { |
- scoped_refptr<Operation> op( |
- new OperationForTest(manager_.AsWeakPtr(), |
- kDummyExtensionId, |
- test_device_path_.AsUTF8Unsafe())); |
- |
- EXPECT_EQ(0, op->GetProgress()); |
- EXPECT_EQ(image_writer_api::STAGE_UNKNOWN, op->GetStage()); |
+ EXPECT_EQ(0, operation_->GetProgress()); |
+ EXPECT_EQ(image_writer_api::STAGE_UNKNOWN, operation_->GetStage()); |
} |
} // namespace image_writer |