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 <algorithm> | 5 #include <algorithm> |
6 #include <map> | 6 #include <map> |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/path_service.h" | |
16 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
17 #include "base/values.h" | 16 #include "base/values.h" |
18 #include "components/dom_distiller/core/article_distillation_update.h" | 17 #include "components/dom_distiller/core/article_distillation_update.h" |
19 #include "components/dom_distiller/core/distiller.h" | 18 #include "components/dom_distiller/core/distiller.h" |
20 #include "components/dom_distiller/core/distiller_page.h" | 19 #include "components/dom_distiller/core/distiller_page.h" |
21 #include "components/dom_distiller/core/fake_distiller_page.h" | 20 #include "components/dom_distiller/core/fake_distiller_page.h" |
22 #include "components/dom_distiller/core/proto/distilled_article.pb.h" | 21 #include "components/dom_distiller/core/proto/distilled_article.pb.h" |
23 #include "components/dom_distiller/core/proto/distilled_page.pb.h" | 22 #include "components/dom_distiller/core/proto/distilled_page.pb.h" |
24 #include "net/url_request/url_request_context_getter.h" | 23 #include "net/url_request/url_request_context_getter.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "third_party/dom_distiller_js/dom_distiller.pb.h" | 26 #include "third_party/dom_distiller_js/dom_distiller.pb.h" |
28 #include "third_party/dom_distiller_js/dom_distiller_json_converter.h" | 27 #include "third_party/dom_distiller_js/dom_distiller_json_converter.h" |
29 #include "ui/base/resource/resource_bundle.h" | |
30 | 28 |
31 using std::vector; | 29 using std::vector; |
32 using std::string; | 30 using std::string; |
33 using ::testing::Invoke; | 31 using ::testing::Invoke; |
34 using ::testing::Return; | 32 using ::testing::Return; |
35 using ::testing::_; | 33 using ::testing::_; |
36 | 34 |
37 using dom_distiller::proto::DomDistillerOptions; | 35 using dom_distiller::proto::DomDistillerOptions; |
38 using dom_distiller::proto::DomDistillerResult; | 36 using dom_distiller::proto::DomDistillerResult; |
39 | 37 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 const vector<int>& image_ids_for_page = distiller_data->image_ids[page_num]; | 178 const vector<int>& image_ids_for_page = distiller_data->image_ids[page_num]; |
181 for (size_t img_num = 0; img_num < image_ids_for_page.size(); ++img_num) { | 179 for (size_t img_num = 0; img_num < image_ids_for_page.size(); ++img_num) { |
182 EXPECT_EQ(kImageData[image_ids_for_page[img_num]], | 180 EXPECT_EQ(kImageData[image_ids_for_page[img_num]], |
183 page.image(img_num).data()); | 181 page.image(img_num).data()); |
184 EXPECT_EQ(GetImageName(page_num + 1, img_num), | 182 EXPECT_EQ(GetImageName(page_num + 1, img_num), |
185 page.image(img_num).name()); | 183 page.image(img_num).name()); |
186 } | 184 } |
187 } | 185 } |
188 } | 186 } |
189 | 187 |
190 void AddComponentsResources() { | |
191 base::FilePath pak_file; | |
192 base::FilePath pak_dir; | |
193 PathService::Get(base::DIR_MODULE, &pak_dir); | |
194 pak_file = pak_dir.Append(FILE_PATH_LITERAL("components_resources.pak")); | |
195 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( | |
196 pak_file, ui::SCALE_FACTOR_NONE); | |
197 } | |
198 | |
199 } // namespace | 188 } // namespace |
200 | 189 |
201 namespace dom_distiller { | 190 namespace dom_distiller { |
202 | 191 |
203 using test::MockDistillerPage; | 192 using test::MockDistillerPage; |
204 using test::MockDistillerPageFactory; | 193 using test::MockDistillerPageFactory; |
205 | 194 |
206 class TestDistillerURLFetcher : public DistillerURLFetcher { | 195 class TestDistillerURLFetcher : public DistillerURLFetcher { |
207 public: | 196 public: |
208 explicit TestDistillerURLFetcher(bool delay_fetch) | 197 explicit TestDistillerURLFetcher(bool delay_fetch) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 MockDistillerURLFetcherFactory() : DistillerURLFetcherFactory(NULL) {} | 239 MockDistillerURLFetcherFactory() : DistillerURLFetcherFactory(NULL) {} |
251 virtual ~MockDistillerURLFetcherFactory() {} | 240 virtual ~MockDistillerURLFetcherFactory() {} |
252 | 241 |
253 MOCK_CONST_METHOD0(CreateDistillerURLFetcher, DistillerURLFetcher*()); | 242 MOCK_CONST_METHOD0(CreateDistillerURLFetcher, DistillerURLFetcher*()); |
254 }; | 243 }; |
255 | 244 |
256 class DistillerTest : public testing::Test { | 245 class DistillerTest : public testing::Test { |
257 public: | 246 public: |
258 virtual ~DistillerTest() {} | 247 virtual ~DistillerTest() {} |
259 | 248 |
260 virtual void SetUp() OVERRIDE { | |
261 AddComponentsResources(); | |
262 } | |
263 | |
264 void OnDistillArticleDone(scoped_ptr<DistilledArticleProto> proto) { | 249 void OnDistillArticleDone(scoped_ptr<DistilledArticleProto> proto) { |
265 article_proto_ = proto.Pass(); | 250 article_proto_ = proto.Pass(); |
266 } | 251 } |
267 | 252 |
268 void OnDistillArticleUpdate(const ArticleDistillationUpdate& article_update) { | 253 void OnDistillArticleUpdate(const ArticleDistillationUpdate& article_update) { |
269 in_sequence_updates_.push_back(article_update); | 254 in_sequence_updates_.push_back(article_update); |
270 } | 255 } |
271 | 256 |
272 void DistillPage(const std::string& url, | 257 void DistillPage(const std::string& url, |
273 scoped_ptr<DistillerPage> distiller_page) { | 258 scoped_ptr<DistillerPage> distiller_page) { |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 | 626 |
642 ASSERT_TRUE(distiller_page); | 627 ASSERT_TRUE(distiller_page); |
643 // Post the task to execute javascript and then delete the distiller. | 628 // Post the task to execute javascript and then delete the distiller. |
644 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get()); | 629 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get()); |
645 distiller_.reset(); | 630 distiller_.reset(); |
646 | 631 |
647 base::MessageLoop::current()->RunUntilIdle(); | 632 base::MessageLoop::current()->RunUntilIdle(); |
648 } | 633 } |
649 | 634 |
650 } // namespace dom_distiller | 635 } // namespace dom_distiller |
OLD | NEW |