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 #include "components/dom_distiller/core/fake_distiller.h" | 5 #include "components/dom_distiller/core/fake_distiller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace dom_distiller { | 11 namespace dom_distiller { |
12 namespace test { | 12 namespace test { |
13 | 13 |
14 MockDistillerFactory::MockDistillerFactory() {} | 14 MockDistillerFactory::MockDistillerFactory() {} |
15 MockDistillerFactory::~MockDistillerFactory() {} | 15 MockDistillerFactory::~MockDistillerFactory() {} |
16 | 16 |
17 FakeDistiller::FakeDistiller(bool execute_callback) : | 17 FakeDistiller::FakeDistiller(bool execute_callback) |
18 execute_callback_(execute_callback) { | 18 : execute_callback_(execute_callback) { |
19 EXPECT_CALL(*this, Die()).Times(testing::AnyNumber()); | 19 EXPECT_CALL(*this, Die()).Times(testing::AnyNumber()); |
20 } | 20 } |
21 | 21 |
22 FakeDistiller::~FakeDistiller() { Die(); } | 22 FakeDistiller::~FakeDistiller() { Die(); } |
23 | 23 |
24 void FakeDistiller::RunDistillerCallback(scoped_ptr<DistilledPageProto> proto) { | 24 void FakeDistiller::DistillPage(const GURL& url, |
| 25 const DistillerCallback& callback) { |
| 26 url_ = url; |
| 27 callback_ = callback; |
| 28 if (execute_callback_) { |
| 29 scoped_ptr<DistilledArticleProto> proto(new DistilledArticleProto); |
| 30 proto->add_pages()->set_url(url_.spec()); |
| 31 RunDistillerCallback(proto.Pass()); |
| 32 } |
| 33 } |
| 34 |
| 35 void FakeDistiller::RunDistillerCallback( |
| 36 scoped_ptr<DistilledArticleProto> proto) { |
25 base::MessageLoop::current()->PostTask( | 37 base::MessageLoop::current()->PostTask( |
26 FROM_HERE, | 38 FROM_HERE, |
27 base::Bind(&FakeDistiller::RunDistillerCallbackInternal, | 39 base::Bind(&FakeDistiller::RunDistillerCallbackInternal, |
28 base::Unretained(this), | 40 base::Unretained(this), |
29 base::Passed(&proto))); | 41 base::Passed(&proto))); |
30 } | 42 } |
31 | 43 |
32 void FakeDistiller::RunDistillerCallbackInternal( | 44 void FakeDistiller::RunDistillerCallbackInternal( |
33 scoped_ptr<DistilledPageProto> proto) { | 45 scoped_ptr<DistilledArticleProto> proto) { |
34 EXPECT_FALSE(callback_.is_null()); | 46 EXPECT_FALSE(callback_.is_null()); |
35 callback_.Run(proto.Pass()); | 47 callback_.Run(proto.Pass()); |
36 callback_.Reset(); | 48 callback_.Reset(); |
37 } | 49 } |
38 | 50 |
39 } // namespace test | 51 } // namespace test |
40 } // namespace dom_distiller | 52 } // namespace dom_distiller |
OLD | NEW |