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