| OLD | NEW |
| 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 "base/run_loop.h" | 5 #include "base/run_loop.h" |
| 6 #include "chrome/browser/extensions/api/image_writer_private/destroy_partitions_
operation.h" | 6 #include "chrome/browser/extensions/api/image_writer_private/destroy_partitions_
operation.h" |
| 7 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" | 7 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" |
| 8 #include "chrome/browser/extensions/api/image_writer_private/test_utils.h" | 8 #include "chrome/browser/extensions/api/image_writer_private/test_utils.h" |
| 9 | 9 |
| 10 namespace extensions { | 10 namespace extensions { |
| 11 namespace image_writer { | 11 namespace image_writer { |
| 12 | 12 |
| 13 using testing::_; | 13 using testing::_; |
| 14 using testing::AnyNumber; | 14 using testing::AnyNumber; |
| 15 using testing::AtLeast; | |
| 16 | 15 |
| 17 namespace { | 16 namespace { |
| 18 | 17 |
| 19 class ImageWriterDestroyPartitionsOperationTest | 18 class ImageWriterDestroyPartitionsOperationTest |
| 20 : public ImageWriterUnitTestBase { | 19 : public ImageWriterUnitTestBase { |
| 21 }; | 20 }; |
| 22 | 21 |
| 23 // Tests that the DestroyPartitionsOperation can successfully zero the first | 22 // Tests that the DestroyPartitionsOperation can successfully zero the first |
| 24 // kPartitionTableSize bytes of an image. | 23 // kPartitionTableSize bytes of an image. |
| 25 TEST_F(ImageWriterDestroyPartitionsOperationTest, DestroyPartitionsEndToEnd) { | 24 TEST_F(ImageWriterDestroyPartitionsOperationTest, DestroyPartitions) { |
| 26 MockOperationManager manager; | 25 MockOperationManager manager; |
| 27 base::RunLoop loop; | 26 base::RunLoop loop; |
| 28 | 27 |
| 29 scoped_refptr<DestroyPartitionsOperation> operation( | 28 scoped_refptr<DestroyPartitionsOperation> operation( |
| 30 new DestroyPartitionsOperation(manager.AsWeakPtr(), | 29 new DestroyPartitionsOperation(manager.AsWeakPtr(), |
| 31 kDummyExtensionId, | 30 kDummyExtensionId, |
| 32 test_device_path_.AsUTF8Unsafe())); | 31 test_device_path_.AsUTF8Unsafe())); |
| 33 | 32 |
| 34 #if defined(OS_LINUX) || defined(OS_CHROMEOS) | 33 #if defined(OS_LINUX) || defined(OS_CHROMEOS) |
| 34 EXPECT_CALL(manager, OnProgress(kDummyExtensionId, _, _)).Times(0); |
| 35 EXPECT_CALL(manager, OnProgress(kDummyExtensionId, | 35 EXPECT_CALL(manager, OnProgress(kDummyExtensionId, |
| 36 image_writer_api::STAGE_WRITE, | 36 image_writer_api::STAGE_WRITE, |
| 37 _)).Times(AnyNumber()); | 37 _)).Times(AnyNumber()); |
| 38 EXPECT_CALL(manager, | |
| 39 OnProgress(kDummyExtensionId, image_writer_api::STAGE_WRITE, 0)) | |
| 40 .Times(AtLeast(1)); | |
| 41 EXPECT_CALL(manager, | |
| 42 OnProgress(kDummyExtensionId, image_writer_api::STAGE_WRITE, 100)) | |
| 43 .Times(AtLeast(1)); | |
| 44 EXPECT_CALL(manager, OnComplete(kDummyExtensionId)).Times(1); | 38 EXPECT_CALL(manager, OnComplete(kDummyExtensionId)).Times(1); |
| 45 EXPECT_CALL(manager, OnError(kDummyExtensionId, _, _, _)).Times(0); | 39 EXPECT_CALL(manager, OnError(kDummyExtensionId, _, _, _)).Times(0); |
| 46 #else | 40 #else |
| 47 EXPECT_CALL(manager, OnProgress(kDummyExtensionId, _, _)).Times(0); | 41 EXPECT_CALL(manager, OnProgress(kDummyExtensionId, _, _)).Times(0); |
| 48 EXPECT_CALL(manager, OnComplete(kDummyExtensionId)).Times(0); | 42 EXPECT_CALL(manager, OnComplete(kDummyExtensionId)).Times(0); |
| 49 EXPECT_CALL(manager, OnError(kDummyExtensionId, | 43 EXPECT_CALL(manager, OnError(kDummyExtensionId, |
| 50 _, | 44 _, |
| 51 _, | 45 _, |
| 52 error::kUnsupportedOperation)).Times(1); | 46 error::kUnsupportedOperation)).Times(1); |
| 53 #endif | 47 #endif |
| 54 | 48 |
| 55 operation->Start(); | 49 operation->Start(); |
| 56 | 50 |
| 57 loop.RunUntilIdle(); | 51 loop.RunUntilIdle(); |
| 58 | 52 |
| 59 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 53 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 60 scoped_ptr<char[]> image_data(new char[kPartitionTableSize]); | 54 scoped_ptr<char[]> image_data(new char[kPartitionTableSize]); |
| 61 scoped_ptr<char[]> zeroes(new char[kPartitionTableSize]); | 55 scoped_ptr<char[]> zeroes(new char[kPartitionTableSize]); |
| 62 memset(zeroes.get(), 0, kPartitionTableSize); | 56 memset(zeroes.get(), 0, kPartitionTableSize); |
| 63 ASSERT_EQ(kPartitionTableSize, base::ReadFile(test_device_path_, | 57 ASSERT_EQ(kPartitionTableSize, base::ReadFile(test_device_path_, |
| 64 image_data.get(), | 58 image_data.get(), |
| 65 kPartitionTableSize)); | 59 kPartitionTableSize)); |
| 66 EXPECT_EQ(0, memcmp(image_data.get(), zeroes.get(), kPartitionTableSize)); | 60 EXPECT_EQ(0, memcmp(image_data.get(), zeroes.get(), kPartitionTableSize)); |
| 67 #endif | 61 #endif |
| 68 } | 62 } |
| 69 | 63 |
| 70 } // namespace | 64 } // namespace |
| 71 } // namespace image_writer | 65 } // namespace image_writer |
| 72 } // namespace extensions | 66 } // namespace extensions |
| OLD | NEW |