Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / components / dom_distiller / core / fake_distiller.h
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.
4
5 #ifndef COMPONENTS_DOM_DISTILLER_CORE_FAKE_DISTILLER_H_
6 #define COMPONENTS_DOM_DISTILLER_CORE_FAKE_DISTILLER_H_
7
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"
13 #include "url/gurl.h"
14
15 class GURL;
16
17 namespace dom_distiller {
18 namespace test {
19
20 class MockDistillerFactory : public DistillerFactory {
21  public:
22   MockDistillerFactory();
23   virtual ~MockDistillerFactory();
24   MOCK_METHOD0(CreateDistillerImpl, Distiller*());
25   virtual scoped_ptr<Distiller> CreateDistillerForUrl(
26       const GURL& unused) override {
27     return scoped_ptr<Distiller>(CreateDistillerImpl());
28   }
29 };
30
31 class FakeDistiller : public Distiller {
32  public:
33   // If execute_callback is true, when DistillPage is called, a task will
34   // immediately be posted to execute the callback with a simple
35   // DistilledArticleProto.
36   explicit FakeDistiller(bool execute_callback);
37   // TODO(yfriedman): Drop execute_callback from this and give the option of
38   // "auto-distilling" or calling the provided closure.
39   explicit FakeDistiller(bool execute_callback,
40                          const base::Closure& distillation_initiated_callback);
41   virtual ~FakeDistiller();
42   MOCK_METHOD0(Die, void());
43
44   virtual void DistillPage(
45       const GURL& url,
46       scoped_ptr<DistillerPage> distiller_page,
47       const DistillationFinishedCallback& article_callback,
48       const DistillationUpdateCallback& page_callback) override;
49
50   void RunDistillerCallback(scoped_ptr<DistilledArticleProto> proto);
51   void RunDistillerUpdateCallback(const ArticleDistillationUpdate& update);
52
53   GURL GetUrl() { return url_; }
54
55   DistillationFinishedCallback GetArticleCallback() {
56     return article_callback_;
57   }
58
59  private:
60   void PostDistillerCallback(scoped_ptr<DistilledArticleProto> proto);
61   void RunDistillerCallbackInternal(scoped_ptr<DistilledArticleProto> proto);
62
63   bool execute_callback_;
64   GURL url_;
65   DistillationFinishedCallback article_callback_;
66   DistillationUpdateCallback page_callback_;
67   bool destruction_allowed_;
68   // Used to notify when distillation is complete.
69   base::Closure distillation_initiated_callback_;
70 };
71
72 }  // namespace test
73 }  // namespace dom_distiller
74
75 #endif  // COMPONENTS_DOM_DISTILLER_CORE_FAKE_DISTILLER_H_