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 namespace { | |
13 | 12 |
14 using testing::_; | 13 using testing::_; |
15 using testing::AnyNumber; | 14 using testing::AnyNumber; |
16 using testing::AtLeast; | 15 using testing::AtLeast; |
17 | 16 |
| 17 namespace { |
| 18 |
18 class ImageWriterDestroyPartitionsOperationTest | 19 class ImageWriterDestroyPartitionsOperationTest |
19 : public ImageWriterUnitTestBase {}; | 20 : public ImageWriterUnitTestBase { |
| 21 }; |
20 | 22 |
21 TEST_F(ImageWriterDestroyPartitionsOperationTest, EndToEnd) { | 23 // Tests that the DestroyPartitionsOperation can successfully zero the first |
| 24 // kPartitionTableSize bytes of an image. |
| 25 TEST_F(ImageWriterDestroyPartitionsOperationTest, DestroyPartitionsEndToEnd) { |
22 MockOperationManager manager; | 26 MockOperationManager manager; |
23 scoped_refptr<FakeImageWriterClient> client = FakeImageWriterClient::Create(); | 27 base::RunLoop loop; |
24 | 28 |
25 scoped_refptr<DestroyPartitionsOperation> operation( | 29 scoped_refptr<DestroyPartitionsOperation> operation( |
26 new DestroyPartitionsOperation(manager.AsWeakPtr(), | 30 new DestroyPartitionsOperation(manager.AsWeakPtr(), |
27 kDummyExtensionId, | 31 kDummyExtensionId, |
28 test_device_path_.AsUTF8Unsafe())); | 32 test_device_path_.AsUTF8Unsafe())); |
29 | 33 |
30 #if !defined(OS_CHROMEOS) | 34 #if defined(OS_LINUX) || defined(OS_CHROMEOS) |
31 operation->SetUtilityClientForTesting(client); | |
32 #endif | |
33 | |
34 EXPECT_CALL( | |
35 manager, | |
36 OnProgress(kDummyExtensionId, image_writer_api::STAGE_VERIFYWRITE, _)) | |
37 .Times(AnyNumber()); | |
38 EXPECT_CALL(manager, OnProgress(kDummyExtensionId, | 35 EXPECT_CALL(manager, OnProgress(kDummyExtensionId, |
39 image_writer_api::STAGE_WRITE, | 36 image_writer_api::STAGE_WRITE, |
40 _)).Times(AnyNumber()); | 37 _)).Times(AnyNumber()); |
41 EXPECT_CALL(manager, | 38 EXPECT_CALL(manager, |
42 OnProgress(kDummyExtensionId, image_writer_api::STAGE_WRITE, 0)) | 39 OnProgress(kDummyExtensionId, image_writer_api::STAGE_WRITE, 0)) |
43 .Times(AtLeast(1)); | 40 .Times(AtLeast(1)); |
44 EXPECT_CALL(manager, | 41 EXPECT_CALL(manager, |
45 OnProgress(kDummyExtensionId, image_writer_api::STAGE_WRITE, 100)) | 42 OnProgress(kDummyExtensionId, image_writer_api::STAGE_WRITE, 100)) |
46 .Times(AtLeast(1)); | 43 .Times(AtLeast(1)); |
47 EXPECT_CALL(manager, OnComplete(kDummyExtensionId)).Times(1); | 44 EXPECT_CALL(manager, OnComplete(kDummyExtensionId)).Times(1); |
48 EXPECT_CALL(manager, OnError(kDummyExtensionId, _, _, _)).Times(0); | 45 EXPECT_CALL(manager, OnError(kDummyExtensionId, _, _, _)).Times(0); |
| 46 #else |
| 47 EXPECT_CALL(manager, OnProgress(kDummyExtensionId, _, _)).Times(0); |
| 48 EXPECT_CALL(manager, OnComplete(kDummyExtensionId)).Times(0); |
| 49 EXPECT_CALL(manager, OnError(kDummyExtensionId, |
| 50 _, |
| 51 _, |
| 52 error::kUnsupportedOperation)).Times(1); |
| 53 #endif |
49 | 54 |
50 operation->Start(); | 55 operation->Start(); |
51 | 56 |
52 base::RunLoop().RunUntilIdle(); | 57 loop.RunUntilIdle(); |
53 | 58 |
54 #if !defined(OS_CHROMEOS) | 59 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
55 client->Progress(0); | 60 scoped_ptr<char[]> image_data(new char[kPartitionTableSize]); |
56 client->Progress(50); | 61 scoped_ptr<char[]> zeroes(new char[kPartitionTableSize]); |
57 client->Progress(100); | 62 memset(zeroes.get(), 0, kPartitionTableSize); |
58 client->Success(); | 63 ASSERT_EQ(kPartitionTableSize, base::ReadFile(test_device_path_, |
59 | 64 image_data.get(), |
60 base::RunLoop().RunUntilIdle(); | 65 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 |