| 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/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "components/dom_distiller/core/article_distillation_update.h" | 17 #include "components/dom_distiller/core/article_distillation_update.h" |
| 18 #include "components/dom_distiller/core/distiller.h" | 18 #include "components/dom_distiller/core/distiller.h" |
| 19 #include "components/dom_distiller/core/distiller_page.h" | 19 #include "components/dom_distiller/core/distiller_page.h" |
| 20 #include "components/dom_distiller/core/fake_distiller_page.h" | 20 #include "components/dom_distiller/core/fake_distiller_page.h" |
| 21 #include "components/dom_distiller/core/proto/distilled_article.pb.h" | 21 #include "components/dom_distiller/core/proto/distilled_article.pb.h" |
| 22 #include "components/dom_distiller/core/proto/distilled_page.pb.h" | 22 #include "components/dom_distiller/core/proto/distilled_page.pb.h" |
| 23 #include "net/url_request/url_request_context_getter.h" | 23 #include "net/url_request/url_request_context_getter.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "third_party/dom_distiller_js/dom_distiller.pb.h" |
| 27 #include "third_party/dom_distiller_js/dom_distiller_json_converter.h" |
| 26 | 28 |
| 27 using std::vector; | 29 using std::vector; |
| 28 using std::string; | 30 using std::string; |
| 29 using ::testing::Invoke; | 31 using ::testing::Invoke; |
| 30 using ::testing::Return; | 32 using ::testing::Return; |
| 31 using ::testing::_; | 33 using ::testing::_; |
| 32 | 34 |
| 33 namespace { | 35 namespace { |
| 34 const char kTitle[] = "Title"; | 36 const char kTitle[] = "Title"; |
| 35 const char kContent[] = "Content"; | 37 const char kContent[] = "Content"; |
| 36 const char kURL[] = "http://a.com/"; | 38 const char kURL[] = "http://a.com/"; |
| 37 const size_t kTotalImages = 2; | 39 const size_t kTotalImages = 2; |
| 38 const char* kImageURLs[kTotalImages] = {"http://a.com/img1.jpg", | 40 const char* kImageURLs[kTotalImages] = {"http://a.com/img1.jpg", |
| 39 "http://a.com/img2.jpg"}; | 41 "http://a.com/img2.jpg"}; |
| 40 const char* kImageData[kTotalImages] = {"abcde", "12345"}; | 42 const char* kImageData[kTotalImages] = {"abcde", "12345"}; |
| 41 | 43 |
| 42 const string GetImageName(int page_num, int image_num) { | 44 const string GetImageName(int page_num, int image_num) { |
| 43 return base::IntToString(page_num) + "_" + base::IntToString(image_num); | 45 return base::IntToString(page_num) + "_" + base::IntToString(image_num); |
| 44 } | 46 } |
| 45 | 47 |
| 46 scoped_ptr<base::ListValue> CreateDistilledValueReturnedFromJS( | 48 scoped_ptr<base::Value> CreateDistilledValueReturnedFromJS( |
| 47 const string& title, | 49 const string& title, |
| 48 const string& content, | 50 const string& content, |
| 49 const vector<int>& image_indices, | 51 const vector<int>& image_indices, |
| 50 const string& next_page_url, | 52 const string& next_page_url, |
| 51 const string& prev_page_url = "") { | 53 const string& prev_page_url = "") { |
| 52 scoped_ptr<base::ListValue> list(new base::ListValue()); | 54 dom_distiller::proto::DomDistillerResult result; |
| 55 result.set_title(title); |
| 56 result.mutable_distilled_content()->set_html(content); |
| 57 result.mutable_pagination_info()->set_next_page(next_page_url); |
| 58 result.mutable_pagination_info()->set_prev_page(prev_page_url); |
| 53 | 59 |
| 54 list->AppendString(title); | |
| 55 list->AppendString(content); | |
| 56 list->AppendString(next_page_url); | |
| 57 list->AppendString(prev_page_url); | |
| 58 for (size_t i = 0; i < image_indices.size(); ++i) { | 60 for (size_t i = 0; i < image_indices.size(); ++i) { |
| 59 list->AppendString(kImageURLs[image_indices[i]]); | 61 result.add_image_urls(kImageURLs[image_indices[i]]); |
| 60 } | 62 } |
| 61 return list.Pass(); | 63 |
| 64 return dom_distiller::proto::json::DomDistillerResult::WriteToValue(result); |
| 62 } | 65 } |
| 63 | 66 |
| 64 // Return the sequence in which Distiller will distill pages. | 67 // Return the sequence in which Distiller will distill pages. |
| 65 // Note: ignores any delays due to fetching images etc. | 68 // Note: ignores any delays due to fetching images etc. |
| 66 vector<int> GetPagesInSequence(int start_page_num, int num_pages) { | 69 vector<int> GetPagesInSequence(int start_page_num, int num_pages) { |
| 67 // Distiller prefers distilling past pages first. E.g. when distillation | 70 // Distiller prefers distilling past pages first. E.g. when distillation |
| 68 // starts on page 2 then pages are distilled in the order: 2, 1, 0, 3, 4. | 71 // starts on page 2 then pages are distilled in the order: 2, 1, 0, 3, 4. |
| 69 vector<int> page_nums; | 72 vector<int> page_nums; |
| 70 for (int page = start_page_num; page >= 0; --page) | 73 for (int page = start_page_num; page >= 0; --page) |
| 71 page_nums.push_back(page); | 74 page_nums.push_back(page); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 for (size_t page_num = 0; page_num < pages_size; ++page_num) { | 140 for (size_t page_num = 0; page_num < pages_size; ++page_num) { |
| 138 result->page_urls.push_back(url_prefix + base::IntToString(page_num)); | 141 result->page_urls.push_back(url_prefix + base::IntToString(page_num)); |
| 139 result->content.push_back("Content for page:" + | 142 result->content.push_back("Content for page:" + |
| 140 base::IntToString(page_num)); | 143 base::IntToString(page_num)); |
| 141 result->image_ids.push_back(vector<int>()); | 144 result->image_ids.push_back(vector<int>()); |
| 142 string next_page_url = (page_num + 1 < pages_size) | 145 string next_page_url = (page_num + 1 < pages_size) |
| 143 ? url_prefix + base::IntToString(page_num + 1) | 146 ? url_prefix + base::IntToString(page_num + 1) |
| 144 : ""; | 147 : ""; |
| 145 string prev_page_url = | 148 string prev_page_url = |
| 146 (page_num > 0) ? result->page_urls[page_num - 1] : ""; | 149 (page_num > 0) ? result->page_urls[page_num - 1] : ""; |
| 147 scoped_ptr<base::ListValue> distilled_value = | 150 scoped_ptr<base::Value> distilled_value = |
| 148 CreateDistilledValueReturnedFromJS(kTitle, | 151 CreateDistilledValueReturnedFromJS(kTitle, |
| 149 result->content[page_num], | 152 result->content[page_num], |
| 150 result->image_ids[page_num], | 153 result->image_ids[page_num], |
| 151 next_page_url, | 154 next_page_url, |
| 152 prev_page_url); | 155 prev_page_url); |
| 153 result->distilled_values.push_back(distilled_value.release()); | 156 result->distilled_values.push_back(distilled_value.release()); |
| 154 } | 157 } |
| 155 return result.Pass(); | 158 return result.Pass(); |
| 156 } | 159 } |
| 157 | 160 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 public: | 233 public: |
| 231 MockDistillerURLFetcherFactory() : DistillerURLFetcherFactory(NULL) {} | 234 MockDistillerURLFetcherFactory() : DistillerURLFetcherFactory(NULL) {} |
| 232 virtual ~MockDistillerURLFetcherFactory() {} | 235 virtual ~MockDistillerURLFetcherFactory() {} |
| 233 | 236 |
| 234 MOCK_CONST_METHOD0(CreateDistillerURLFetcher, DistillerURLFetcher*()); | 237 MOCK_CONST_METHOD0(CreateDistillerURLFetcher, DistillerURLFetcher*()); |
| 235 }; | 238 }; |
| 236 | 239 |
| 237 class DistillerTest : public testing::Test { | 240 class DistillerTest : public testing::Test { |
| 238 public: | 241 public: |
| 239 virtual ~DistillerTest() {} | 242 virtual ~DistillerTest() {} |
| 243 |
| 240 void OnDistillArticleDone(scoped_ptr<DistilledArticleProto> proto) { | 244 void OnDistillArticleDone(scoped_ptr<DistilledArticleProto> proto) { |
| 241 article_proto_ = proto.Pass(); | 245 article_proto_ = proto.Pass(); |
| 242 } | 246 } |
| 243 | 247 |
| 244 void OnDistillArticleUpdate(const ArticleDistillationUpdate& article_update) { | 248 void OnDistillArticleUpdate(const ArticleDistillationUpdate& article_update) { |
| 245 in_sequence_updates_.push_back(article_update); | 249 in_sequence_updates_.push_back(article_update); |
| 246 } | 250 } |
| 247 | 251 |
| 248 void DistillPage(const std::string& url, | 252 void DistillPage(const std::string& url, |
| 249 scoped_ptr<DistillerPage> distiller_page) { | 253 scoped_ptr<DistillerPage> distiller_page) { |
| 250 distiller_->DistillPage(GURL(url), | 254 distiller_->DistillPage(GURL(url), |
| 251 distiller_page.Pass(), | 255 distiller_page.Pass(), |
| 252 base::Bind(&DistillerTest::OnDistillArticleDone, | 256 base::Bind(&DistillerTest::OnDistillArticleDone, |
| 253 base::Unretained(this)), | 257 base::Unretained(this)), |
| 254 base::Bind(&DistillerTest::OnDistillArticleUpdate, | 258 base::Bind(&DistillerTest::OnDistillArticleUpdate, |
| 255 base::Unretained(this))); | 259 base::Unretained(this))); |
| 256 } | 260 } |
| 257 | 261 |
| 258 protected: | 262 protected: |
| 259 scoped_ptr<DistillerImpl> distiller_; | 263 scoped_ptr<DistillerImpl> distiller_; |
| 260 scoped_ptr<DistilledArticleProto> article_proto_; | 264 scoped_ptr<DistilledArticleProto> article_proto_; |
| 261 std::vector<ArticleDistillationUpdate> in_sequence_updates_; | 265 std::vector<ArticleDistillationUpdate> in_sequence_updates_; |
| 262 MockDistillerPageFactory page_factory_; | 266 MockDistillerPageFactory page_factory_; |
| 263 TestDistillerURLFetcherFactory url_fetcher_factory_; | 267 TestDistillerURLFetcherFactory url_fetcher_factory_; |
| 264 }; | 268 }; |
| 265 | 269 |
| 266 ACTION_P3(DistillerPageOnDistillationDone, distiller_page, url, list) { | 270 ACTION_P3(DistillerPageOnDistillationDone, distiller_page, url, result) { |
| 267 distiller_page->OnDistillationDone(url, list); | 271 distiller_page->OnDistillationDone(url, result); |
| 268 } | 272 } |
| 269 | 273 |
| 270 scoped_ptr<DistillerPage> CreateMockDistillerPage(const base::Value* list, | 274 scoped_ptr<DistillerPage> CreateMockDistillerPage(const base::Value* result, |
| 271 const GURL& url) { | 275 const GURL& url) { |
| 272 MockDistillerPage* distiller_page = new MockDistillerPage(); | 276 MockDistillerPage* distiller_page = new MockDistillerPage(); |
| 273 EXPECT_CALL(*distiller_page, DistillPageImpl(url, _)) | 277 EXPECT_CALL(*distiller_page, DistillPageImpl(url, _)) |
| 274 .WillOnce(DistillerPageOnDistillationDone(distiller_page, url, list)); | 278 .WillOnce(DistillerPageOnDistillationDone(distiller_page, url, result)); |
| 275 return scoped_ptr<DistillerPage>(distiller_page).Pass(); | 279 return scoped_ptr<DistillerPage>(distiller_page).Pass(); |
| 276 } | 280 } |
| 277 | 281 |
| 278 scoped_ptr<DistillerPage> CreateMockDistillerPageWithPendingJSCallback( | 282 scoped_ptr<DistillerPage> CreateMockDistillerPageWithPendingJSCallback( |
| 279 MockDistillerPage** distiller_page_ptr, | 283 MockDistillerPage** distiller_page_ptr, |
| 280 const GURL& url) { | 284 const GURL& url) { |
| 281 MockDistillerPage* distiller_page = new MockDistillerPage(); | 285 MockDistillerPage* distiller_page = new MockDistillerPage(); |
| 282 *distiller_page_ptr = distiller_page; | 286 *distiller_page_ptr = distiller_page; |
| 283 EXPECT_CALL(*distiller_page, DistillPageImpl(url, _)); | 287 EXPECT_CALL(*distiller_page, DistillPageImpl(url, _)); |
| 284 return scoped_ptr<DistillerPage>(distiller_page).Pass(); | 288 return scoped_ptr<DistillerPage>(distiller_page).Pass(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 298 EXPECT_CALL(*distiller_page, DistillPageImpl(url, _)) | 302 EXPECT_CALL(*distiller_page, DistillPageImpl(url, _)) |
| 299 .WillOnce(DistillerPageOnDistillationDone( | 303 .WillOnce(DistillerPageOnDistillationDone( |
| 300 distiller_page, url, distiller_data->distilled_values[page])); | 304 distiller_page, url, distiller_data->distilled_values[page])); |
| 301 } | 305 } |
| 302 } | 306 } |
| 303 return scoped_ptr<DistillerPage>(distiller_page).Pass(); | 307 return scoped_ptr<DistillerPage>(distiller_page).Pass(); |
| 304 } | 308 } |
| 305 | 309 |
| 306 TEST_F(DistillerTest, DistillPage) { | 310 TEST_F(DistillerTest, DistillPage) { |
| 307 base::MessageLoopForUI loop; | 311 base::MessageLoopForUI loop; |
| 308 scoped_ptr<base::ListValue> list = | 312 scoped_ptr<base::Value> result = |
| 309 CreateDistilledValueReturnedFromJS(kTitle, kContent, vector<int>(), ""); | 313 CreateDistilledValueReturnedFromJS(kTitle, kContent, vector<int>(), ""); |
| 310 distiller_.reset(new DistillerImpl(url_fetcher_factory_)); | 314 distiller_.reset(new DistillerImpl(url_fetcher_factory_)); |
| 311 DistillPage(kURL, CreateMockDistillerPage(list.get(), GURL(kURL)).Pass()); | 315 DistillPage(kURL, CreateMockDistillerPage(result.get(), GURL(kURL)).Pass()); |
| 312 base::MessageLoop::current()->RunUntilIdle(); | 316 base::MessageLoop::current()->RunUntilIdle(); |
| 313 EXPECT_EQ(kTitle, article_proto_->title()); | 317 EXPECT_EQ(kTitle, article_proto_->title()); |
| 314 EXPECT_EQ(article_proto_->pages_size(), 1); | 318 EXPECT_EQ(article_proto_->pages_size(), 1); |
| 315 const DistilledPageProto& first_page = article_proto_->pages(0); | 319 const DistilledPageProto& first_page = article_proto_->pages(0); |
| 316 EXPECT_EQ(kContent, first_page.html()); | 320 EXPECT_EQ(kContent, first_page.html()); |
| 317 EXPECT_EQ(kURL, first_page.url()); | 321 EXPECT_EQ(kURL, first_page.url()); |
| 318 } | 322 } |
| 319 | 323 |
| 320 TEST_F(DistillerTest, DistillPageWithImages) { | 324 TEST_F(DistillerTest, DistillPageWithImages) { |
| 321 base::MessageLoopForUI loop; | 325 base::MessageLoopForUI loop; |
| 322 vector<int> image_indices; | 326 vector<int> image_indices; |
| 323 image_indices.push_back(0); | 327 image_indices.push_back(0); |
| 324 image_indices.push_back(1); | 328 image_indices.push_back(1); |
| 325 scoped_ptr<base::ListValue> list = | 329 scoped_ptr<base::Value> result = |
| 326 CreateDistilledValueReturnedFromJS(kTitle, kContent, image_indices, ""); | 330 CreateDistilledValueReturnedFromJS(kTitle, kContent, image_indices, ""); |
| 327 distiller_.reset(new DistillerImpl(url_fetcher_factory_)); | 331 distiller_.reset(new DistillerImpl(url_fetcher_factory_)); |
| 328 DistillPage(kURL, CreateMockDistillerPage(list.get(), GURL(kURL)).Pass()); | 332 DistillPage(kURL, CreateMockDistillerPage(result.get(), GURL(kURL)).Pass()); |
| 329 base::MessageLoop::current()->RunUntilIdle(); | 333 base::MessageLoop::current()->RunUntilIdle(); |
| 330 EXPECT_EQ(kTitle, article_proto_->title()); | 334 EXPECT_EQ(kTitle, article_proto_->title()); |
| 331 EXPECT_EQ(article_proto_->pages_size(), 1); | 335 EXPECT_EQ(article_proto_->pages_size(), 1); |
| 332 const DistilledPageProto& first_page = article_proto_->pages(0); | 336 const DistilledPageProto& first_page = article_proto_->pages(0); |
| 333 EXPECT_EQ(kContent, first_page.html()); | 337 EXPECT_EQ(kContent, first_page.html()); |
| 334 EXPECT_EQ(kURL, first_page.url()); | 338 EXPECT_EQ(kURL, first_page.url()); |
| 335 EXPECT_EQ(2, first_page.image_size()); | 339 EXPECT_EQ(2, first_page.image_size()); |
| 336 EXPECT_EQ(kImageData[0], first_page.image(0).data()); | 340 EXPECT_EQ(kImageData[0], first_page.image(0).data()); |
| 337 EXPECT_EQ(GetImageName(1, 0), first_page.image(0).name()); | 341 EXPECT_EQ(GetImageName(1, 0), first_page.image(0).name()); |
| 338 EXPECT_EQ(kImageData[1], first_page.image(1).data()); | 342 EXPECT_EQ(kImageData[1], first_page.image(1).data()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 364 CreateMockDistillerPages(distiller_data.get(), kNumPages, 0).Pass()); | 368 CreateMockDistillerPages(distiller_data.get(), kNumPages, 0).Pass()); |
| 365 base::MessageLoop::current()->RunUntilIdle(); | 369 base::MessageLoop::current()->RunUntilIdle(); |
| 366 VerifyArticleProtoMatchesMultipageData( | 370 VerifyArticleProtoMatchesMultipageData( |
| 367 article_proto_.get(), distiller_data.get(), kNumPages); | 371 article_proto_.get(), distiller_data.get(), kNumPages); |
| 368 } | 372 } |
| 369 | 373 |
| 370 TEST_F(DistillerTest, DistillLinkLoop) { | 374 TEST_F(DistillerTest, DistillLinkLoop) { |
| 371 base::MessageLoopForUI loop; | 375 base::MessageLoopForUI loop; |
| 372 // Create a loop, the next page is same as the current page. This could | 376 // Create a loop, the next page is same as the current page. This could |
| 373 // happen if javascript misparses a next page link. | 377 // happen if javascript misparses a next page link. |
| 374 scoped_ptr<base::ListValue> list = | 378 scoped_ptr<base::Value> result = |
| 375 CreateDistilledValueReturnedFromJS(kTitle, kContent, vector<int>(), kURL); | 379 CreateDistilledValueReturnedFromJS(kTitle, kContent, vector<int>(), kURL); |
| 376 distiller_.reset(new DistillerImpl(url_fetcher_factory_)); | 380 distiller_.reset(new DistillerImpl(url_fetcher_factory_)); |
| 377 DistillPage(kURL, CreateMockDistillerPage(list.get(), GURL(kURL)).Pass()); | 381 DistillPage(kURL, CreateMockDistillerPage(result.get(), GURL(kURL)).Pass()); |
| 378 base::MessageLoop::current()->RunUntilIdle(); | 382 base::MessageLoop::current()->RunUntilIdle(); |
| 379 EXPECT_EQ(kTitle, article_proto_->title()); | 383 EXPECT_EQ(kTitle, article_proto_->title()); |
| 380 EXPECT_EQ(article_proto_->pages_size(), 1); | 384 EXPECT_EQ(article_proto_->pages_size(), 1); |
| 381 } | 385 } |
| 382 | 386 |
| 383 TEST_F(DistillerTest, CheckMaxPageLimitExtraPage) { | 387 TEST_F(DistillerTest, CheckMaxPageLimitExtraPage) { |
| 384 base::MessageLoopForUI loop; | 388 base::MessageLoopForUI loop; |
| 385 const size_t kMaxPagesInArticle = 10; | 389 const size_t kMaxPagesInArticle = 10; |
| 386 scoped_ptr<MultipageDistillerData> distiller_data = | 390 scoped_ptr<MultipageDistillerData> distiller_data = |
| 387 CreateMultipageDistillerDataWithoutImages(kMaxPagesInArticle); | 391 CreateMultipageDistillerDataWithoutImages(kMaxPagesInArticle); |
| 388 | 392 |
| 389 // Note: Next page url of the last page of article is set. So distiller will | 393 // Note: Next page url of the last page of article is set. So distiller will |
| 390 // try to do kMaxPagesInArticle + 1 calls if the max article limit does not | 394 // try to do kMaxPagesInArticle + 1 calls if the max article limit does not |
| 391 // work. | 395 // work. |
| 392 scoped_ptr<base::ListValue> last_page_data = | 396 scoped_ptr<base::Value> last_page_data = |
| 393 CreateDistilledValueReturnedFromJS( | 397 CreateDistilledValueReturnedFromJS( |
| 394 kTitle, | 398 kTitle, |
| 395 distiller_data->content[kMaxPagesInArticle - 1], | 399 distiller_data->content[kMaxPagesInArticle - 1], |
| 396 vector<int>(), | 400 vector<int>(), |
| 397 "", | 401 "", |
| 398 distiller_data->page_urls[kMaxPagesInArticle - 2]); | 402 distiller_data->page_urls[kMaxPagesInArticle - 2]); |
| 399 | 403 |
| 400 distiller_data->distilled_values.pop_back(); | 404 distiller_data->distilled_values.pop_back(); |
| 401 distiller_data->distilled_values.push_back(last_page_data.release()); | 405 distiller_data->distilled_values.push_back(last_page_data.release()); |
| 402 | 406 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 // Delete the article. | 555 // Delete the article. |
| 552 article_proto_.reset(); | 556 article_proto_.reset(); |
| 553 VerifyIncrementalUpdatesMatch( | 557 VerifyIncrementalUpdatesMatch( |
| 554 distiller_data.get(), kNumPages, in_sequence_updates_, start_page_num); | 558 distiller_data.get(), kNumPages, in_sequence_updates_, start_page_num); |
| 555 } | 559 } |
| 556 | 560 |
| 557 TEST_F(DistillerTest, CancelWithDelayedImageFetchCallback) { | 561 TEST_F(DistillerTest, CancelWithDelayedImageFetchCallback) { |
| 558 base::MessageLoopForUI loop; | 562 base::MessageLoopForUI loop; |
| 559 vector<int> image_indices; | 563 vector<int> image_indices; |
| 560 image_indices.push_back(0); | 564 image_indices.push_back(0); |
| 561 scoped_ptr<base::ListValue> distilled_value = | 565 scoped_ptr<base::Value> distilled_value = |
| 562 CreateDistilledValueReturnedFromJS(kTitle, kContent, image_indices, ""); | 566 CreateDistilledValueReturnedFromJS(kTitle, kContent, image_indices, ""); |
| 563 TestDistillerURLFetcher* delayed_fetcher = new TestDistillerURLFetcher(true); | 567 TestDistillerURLFetcher* delayed_fetcher = new TestDistillerURLFetcher(true); |
| 564 MockDistillerURLFetcherFactory url_fetcher_factory; | 568 MockDistillerURLFetcherFactory url_fetcher_factory; |
| 565 EXPECT_CALL(url_fetcher_factory, CreateDistillerURLFetcher()) | 569 EXPECT_CALL(url_fetcher_factory, CreateDistillerURLFetcher()) |
| 566 .WillOnce(Return(delayed_fetcher)); | 570 .WillOnce(Return(delayed_fetcher)); |
| 567 distiller_.reset(new DistillerImpl(url_fetcher_factory)); | 571 distiller_.reset(new DistillerImpl(url_fetcher_factory)); |
| 568 DistillPage( | 572 DistillPage( |
| 569 kURL, CreateMockDistillerPage(distilled_value.get(), GURL(kURL)).Pass()); | 573 kURL, CreateMockDistillerPage(distilled_value.get(), GURL(kURL)).Pass()); |
| 570 base::MessageLoop::current()->RunUntilIdle(); | 574 base::MessageLoop::current()->RunUntilIdle(); |
| 571 | 575 |
| 572 // Post callback from the url fetcher and then delete the distiller. | 576 // Post callback from the url fetcher and then delete the distiller. |
| 573 delayed_fetcher->PostCallbackTask(); | 577 delayed_fetcher->PostCallbackTask(); |
| 574 distiller_.reset(); | 578 distiller_.reset(); |
| 575 | 579 |
| 576 base::MessageLoop::current()->RunUntilIdle(); | 580 base::MessageLoop::current()->RunUntilIdle(); |
| 577 } | 581 } |
| 578 | 582 |
| 579 TEST_F(DistillerTest, CancelWithDelayedJSCallback) { | 583 TEST_F(DistillerTest, CancelWithDelayedJSCallback) { |
| 580 base::MessageLoopForUI loop; | 584 base::MessageLoopForUI loop; |
| 581 scoped_ptr<base::ListValue> distilled_value = | 585 scoped_ptr<base::Value> distilled_value = |
| 582 CreateDistilledValueReturnedFromJS(kTitle, kContent, vector<int>(), ""); | 586 CreateDistilledValueReturnedFromJS(kTitle, kContent, vector<int>(), ""); |
| 583 MockDistillerPage* distiller_page = NULL; | 587 MockDistillerPage* distiller_page = NULL; |
| 584 distiller_.reset(new DistillerImpl(url_fetcher_factory_)); | 588 distiller_.reset(new DistillerImpl(url_fetcher_factory_)); |
| 585 DistillPage(kURL, | 589 DistillPage(kURL, |
| 586 CreateMockDistillerPageWithPendingJSCallback(&distiller_page, | 590 CreateMockDistillerPageWithPendingJSCallback(&distiller_page, |
| 587 GURL(kURL))); | 591 GURL(kURL))); |
| 588 base::MessageLoop::current()->RunUntilIdle(); | 592 base::MessageLoop::current()->RunUntilIdle(); |
| 589 | 593 |
| 590 ASSERT_TRUE(distiller_page); | 594 ASSERT_TRUE(distiller_page); |
| 591 // Post the task to execute javascript and then delete the distiller. | 595 // Post the task to execute javascript and then delete the distiller. |
| 592 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get()); | 596 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get()); |
| 593 distiller_.reset(); | 597 distiller_.reset(); |
| 594 | 598 |
| 595 base::MessageLoop::current()->RunUntilIdle(); | 599 base::MessageLoop::current()->RunUntilIdle(); |
| 596 } | 600 } |
| 597 | 601 |
| 598 } // namespace dom_distiller | 602 } // namespace dom_distiller |
| OLD | NEW |