| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef COMPONENTS_DOM_DISTILLER_CORE_FAKE_DISTILLER_H_ | 5 #ifndef COMPONENTS_DOM_DISTILLER_CORE_FAKE_DISTILLER_H_ |
| 6 #define COMPONENTS_DOM_DISTILLER_CORE_FAKE_DISTILLER_H_ | 6 #define COMPONENTS_DOM_DISTILLER_CORE_FAKE_DISTILLER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" |
| 8 #include "components/dom_distiller/core/article_distillation_update.h" | 9 #include "components/dom_distiller/core/article_distillation_update.h" |
| 9 #include "components/dom_distiller/core/article_entry.h" | 10 #include "components/dom_distiller/core/article_entry.h" |
| 10 #include "components/dom_distiller/core/distiller.h" | 11 #include "components/dom_distiller/core/distiller.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 13 | 14 |
| 14 class GURL; | 15 class GURL; |
| 15 | 16 |
| 16 namespace dom_distiller { | 17 namespace dom_distiller { |
| 17 namespace test { | 18 namespace test { |
| 18 | 19 |
| 19 class MockDistillerFactory : public DistillerFactory { | 20 class MockDistillerFactory : public DistillerFactory { |
| 20 public: | 21 public: |
| 21 MockDistillerFactory(); | 22 MockDistillerFactory(); |
| 22 virtual ~MockDistillerFactory(); | 23 virtual ~MockDistillerFactory(); |
| 23 MOCK_METHOD0(CreateDistillerImpl, Distiller*()); | 24 MOCK_METHOD0(CreateDistillerImpl, Distiller*()); |
| 24 virtual scoped_ptr<Distiller> CreateDistiller() OVERRIDE { | 25 virtual scoped_ptr<Distiller> CreateDistiller() OVERRIDE { |
| 25 return scoped_ptr<Distiller>(CreateDistillerImpl()); | 26 return scoped_ptr<Distiller>(CreateDistillerImpl()); |
| 26 } | 27 } |
| 27 }; | 28 }; |
| 28 | 29 |
| 29 class FakeDistiller : public Distiller { | 30 class FakeDistiller : public Distiller { |
| 30 public: | 31 public: |
| 31 // If execute_callback is true, when DistillPage is called, a task will | 32 // If execute_callback is true, when DistillPage is called, a task will |
| 32 // immediately be posted to execute the callback with a simple | 33 // immediately be posted to execute the callback with a simple |
| 33 // DistilledArticleProto. | 34 // DistilledArticleProto. |
| 34 explicit FakeDistiller(bool execute_callback); | 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); |
| 35 virtual ~FakeDistiller(); | 40 virtual ~FakeDistiller(); |
| 36 MOCK_METHOD0(Die, void()); | 41 MOCK_METHOD0(Die, void()); |
| 37 | 42 |
| 38 virtual void DistillPage( | 43 virtual void DistillPage( |
| 39 const GURL& url, | 44 const GURL& url, |
| 40 scoped_ptr<DistillerPage> distiller_page, | 45 scoped_ptr<DistillerPage> distiller_page, |
| 41 const DistillationFinishedCallback& article_callback, | 46 const DistillationFinishedCallback& article_callback, |
| 42 const DistillationUpdateCallback& page_callback) OVERRIDE; | 47 const DistillationUpdateCallback& page_callback) OVERRIDE; |
| 43 | 48 |
| 44 void RunDistillerCallback(scoped_ptr<DistilledArticleProto> proto); | 49 void RunDistillerCallback(scoped_ptr<DistilledArticleProto> proto); |
| 50 void RunDistillerUpdateCallback(const ArticleDistillationUpdate& update); |
| 45 | 51 |
| 46 GURL GetUrl() { return url_; } | 52 GURL GetUrl() { return url_; } |
| 47 | 53 |
| 48 DistillationFinishedCallback GetArticleCallback() { | 54 DistillationFinishedCallback GetArticleCallback() { |
| 49 return article_callback_; | 55 return article_callback_; |
| 50 } | 56 } |
| 51 | 57 |
| 52 private: | 58 private: |
| 53 void PostDistillerCallback(scoped_ptr<DistilledArticleProto> proto); | 59 void PostDistillerCallback(scoped_ptr<DistilledArticleProto> proto); |
| 54 void RunDistillerCallbackInternal(scoped_ptr<DistilledArticleProto> proto); | 60 void RunDistillerCallbackInternal(scoped_ptr<DistilledArticleProto> proto); |
| 55 | 61 |
| 56 bool execute_callback_; | 62 bool execute_callback_; |
| 57 GURL url_; | 63 GURL url_; |
| 58 DistillationFinishedCallback article_callback_; | 64 DistillationFinishedCallback article_callback_; |
| 59 DistillationUpdateCallback page_callback_; | 65 DistillationUpdateCallback page_callback_; |
| 60 | |
| 61 bool destruction_allowed_; | 66 bool destruction_allowed_; |
| 67 // Used to notify when distillation is complete. |
| 68 base::Closure distillation_initiated_callback_; |
| 62 }; | 69 }; |
| 63 | 70 |
| 64 } // namespace test | 71 } // namespace test |
| 65 } // namespace dom_distiller | 72 } // namespace dom_distiller |
| 66 | 73 |
| 67 #endif // COMPONENTS_DOM_DISTILLER_CORE_FAKE_DISTILLER_H_ | 74 #endif // COMPONENTS_DOM_DISTILLER_CORE_FAKE_DISTILLER_H_ |
| OLD | NEW |