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
3// found in the LICENSE file.
4
5#include "base/run_loop.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"
8#include "chrome/browser/extensions/api/image_writer_private/test_utils.h"
9#include "chrome/test/base/testing_profile.h"
10
11namespace extensions {
12namespace image_writer {
13namespace {
14
15using testing::_;
16using testing::AnyNumber;
17using testing::AtLeast;
18
19class ImageWriterDestroyPartitionsOperationTest
20    : public ImageWriterUnitTestBase {};
21
22TEST_F(ImageWriterDestroyPartitionsOperationTest, EndToEnd) {
23  TestingProfile profile;
24  MockOperationManager manager(&profile);
25
26  scoped_refptr<DestroyPartitionsOperation> operation(
27      new DestroyPartitionsOperation(
28          manager.AsWeakPtr(),
29          kDummyExtensionId,
30          test_utils_.GetDevicePath().AsUTF8Unsafe()));
31
32  EXPECT_CALL(
33      manager,
34      OnProgress(kDummyExtensionId, image_writer_api::STAGE_VERIFYWRITE, _))
35      .Times(AnyNumber());
36  EXPECT_CALL(manager, OnProgress(kDummyExtensionId,
37                                  image_writer_api::STAGE_WRITE,
38                                  _)).Times(AnyNumber());
39  EXPECT_CALL(manager,
40              OnProgress(kDummyExtensionId, image_writer_api::STAGE_WRITE, 0))
41      .Times(AtLeast(1));
42  EXPECT_CALL(manager,
43              OnProgress(kDummyExtensionId, image_writer_api::STAGE_WRITE, 100))
44      .Times(AtLeast(1));
45  EXPECT_CALL(manager, OnComplete(kDummyExtensionId)).Times(1);
46  EXPECT_CALL(manager, OnError(kDummyExtensionId, _, _, _)).Times(0);
47
48  operation->Start();
49
50  base::RunLoop().RunUntilIdle();
51
52#if !defined(OS_CHROMEOS)
53  test_utils_.GetUtilityClient()->Progress(0);
54  test_utils_.GetUtilityClient()->Progress(50);
55  test_utils_.GetUtilityClient()->Progress(100);
56  test_utils_.GetUtilityClient()->Success();
57
58  base::RunLoop().RunUntilIdle();
59#endif
60}
61
62} // namespace
63} // namespace image_writer
64} // namespace extensions
65