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