1 // Copyright 2013 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.
5 #ifndef COMPONENTS_DOM_DISTILLER_CORE_FAKE_DISTILLER_H_
6 #define COMPONENTS_DOM_DISTILLER_CORE_FAKE_DISTILLER_H_
8 #include "base/callback.h"
9 #include "components/dom_distiller/core/article_distillation_update.h"
10 #include "components/dom_distiller/core/article_entry.h"
11 #include "components/dom_distiller/core/distiller.h"
12 #include "testing/gmock/include/gmock/gmock.h"
17 namespace dom_distiller
{
20 class MockDistillerFactory
: public DistillerFactory
{
22 MockDistillerFactory();
23 virtual ~MockDistillerFactory();
24 MOCK_METHOD0(CreateDistillerImpl
, Distiller
*());
25 scoped_ptr
<Distiller
> CreateDistillerForUrl(const GURL
& unused
) override
{
26 return scoped_ptr
<Distiller
>(CreateDistillerImpl());
30 class FakeDistiller
: public Distiller
{
32 // If execute_callback is true, when DistillPage is called, a task will
33 // immediately be posted to execute the callback with a simple
34 // DistilledArticleProto.
35 explicit FakeDistiller(bool execute_callback
);
36 // TODO(yfriedman): Drop execute_callback from this and give the option of
37 // "auto-distilling" or calling the provided closure.
38 explicit FakeDistiller(bool execute_callback
,
39 const base::Closure
& distillation_initiated_callback
);
40 ~FakeDistiller() override
;
41 MOCK_METHOD0(Die
, void());
43 void DistillPage(const GURL
& url
,
44 scoped_ptr
<DistillerPage
> distiller_page
,
45 const DistillationFinishedCallback
& article_callback
,
46 const DistillationUpdateCallback
& page_callback
) override
;
48 void RunDistillerCallback(scoped_ptr
<DistilledArticleProto
> proto
);
49 void RunDistillerUpdateCallback(const ArticleDistillationUpdate
& update
);
51 GURL
GetUrl() { return url_
; }
53 DistillationFinishedCallback
GetArticleCallback() {
54 return article_callback_
;
58 void PostDistillerCallback(scoped_ptr
<DistilledArticleProto
> proto
);
59 void RunDistillerCallbackInternal(scoped_ptr
<DistilledArticleProto
> proto
);
61 bool execute_callback_
;
63 DistillationFinishedCallback article_callback_
;
64 DistillationUpdateCallback page_callback_
;
65 bool destruction_allowed_
;
66 // Used to notify when distillation is complete.
67 base::Closure distillation_initiated_callback_
;
71 } // namespace dom_distiller
73 #endif // COMPONENTS_DOM_DISTILLER_CORE_FAKE_DISTILLER_H_