Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: components/dom_distiller/core/dom_distiller_service_unittest.cc

Issue 442503002: Retrieve article original URL from entryID (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/dom_distiller_service.h" 5 #include "components/dom_distiller/core/dom_distiller_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 // Should be able to query article using any of the pages url. 451 // Should be able to query article using any of the pages url.
452 for (int page_num = 0; page_num < kPageCount; ++page_num) { 452 for (int page_num = 0; page_num < kPageCount; ++page_num) {
453 EXPECT_TRUE(store_->GetEntryByUrl(pages_url[page_num], &entry)); 453 EXPECT_TRUE(store_->GetEntryByUrl(pages_url[page_num], &entry));
454 } 454 }
455 455
456 service_->RemoveEntry(entry_id); 456 service_->RemoveEntry(entry_id);
457 base::RunLoop().RunUntilIdle(); 457 base::RunLoop().RunUntilIdle();
458 EXPECT_EQ(0u, store_->GetEntries().size()); 458 EXPECT_EQ(0u, store_->GetEntries().size());
459 } 459 }
460 460
461 TEST_F(DomDistillerServiceTest, TestHasEntry) {
462 FakeDistiller* distiller = new FakeDistiller(false);
463 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl())
464 .WillOnce(Return(distiller));
465
466 GURL url("http://www.example.com/p1");
467
468 MockArticleAvailableCallback article_cb;
469 EXPECT_CALL(article_cb, DistillationCompleted(true));
470
471 std::string entry_id = service_->AddToList(
472 url,
473 service_->CreateDefaultDistillerPage(gfx::Size()).Pass(),
474 ArticleCallback(&article_cb));
475
476 ASSERT_FALSE(distiller->GetArticleCallback().is_null());
477 EXPECT_EQ(url, distiller->GetUrl());
478
479 scoped_ptr<DistilledArticleProto> proto = CreateArticleWithURL(url.spec());
480 RunDistillerCallback(distiller, proto.Pass());
481
482 EXPECT_TRUE(service_->HasEntry(entry_id));
483
484 service_->RemoveEntry(entry_id);
485 base::RunLoop().RunUntilIdle();
486 EXPECT_EQ(0u, store_->GetEntries().size());
487 EXPECT_FALSE(service_->HasEntry(entry_id));
488 }
489
490 TEST_F(DomDistillerServiceTest, TestGetUrlForOnePageEntry) {
491 FakeDistiller* distiller = new FakeDistiller(false);
492 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl())
493 .WillOnce(Return(distiller));
494
495 GURL url("http://www.example.com/p1");
496
497 MockArticleAvailableCallback article_cb;
498 EXPECT_CALL(article_cb, DistillationCompleted(true));
499
500 std::string entry_id = service_->AddToList(
501 url,
502 service_->CreateDefaultDistillerPage(gfx::Size()).Pass(),
503 ArticleCallback(&article_cb));
504
505 ASSERT_FALSE(distiller->GetArticleCallback().is_null());
506 EXPECT_EQ(url, distiller->GetUrl());
507
508 scoped_ptr<DistilledArticleProto> proto = CreateArticleWithURL(url.spec());
509 RunDistillerCallback(distiller, proto.Pass());
510
511 // Check if retrieved URL is same as given URL.
512 GURL formattedURL(service_->GetUrlForEntry(entry_id));
nyquist 2014/08/13 20:09:11 Nit: This URL isn't really formatted in any specia
sunangel 2014/08/13 21:49:33 Done.
513 EXPECT_EQ(url, formattedURL);
514
515 service_->RemoveEntry(entry_id);
516 base::RunLoop().RunUntilIdle();
517 EXPECT_EQ(0u, store_->GetEntries().size());
518 EXPECT_EQ("", service_->GetUrlForEntry(entry_id));
519 }
520
521 TEST_F(DomDistillerServiceTest, TestGetUrlForMultiPageEntry) {
522 FakeDistiller* distiller = new FakeDistiller(false);
523 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl())
524 .WillOnce(Return(distiller));
525
526 const int kPageCount = 8;
527
528 std::string base_url("http://www.example.com/p");
529 GURL pages_url[kPageCount];
530 for (int page_num = 0; page_num < kPageCount; ++page_num) {
531 pages_url[page_num] = GURL(base_url + base::IntToString(page_num));
532 }
533
534 MockArticleAvailableCallback article_cb;
535 EXPECT_CALL(article_cb, DistillationCompleted(true));
536
537 std::string entry_id = service_->AddToList(
538 pages_url[0],
539 service_->CreateDefaultDistillerPage(gfx::Size()).Pass(),
540 ArticleCallback(&article_cb));
541
542 ArticleEntry entry;
543 ASSERT_FALSE(distiller->GetArticleCallback().is_null());
544 EXPECT_EQ(pages_url[0], distiller->GetUrl());
545
546 // Create the article with pages to pass to the distiller.
547 scoped_ptr<DistilledArticleProto> proto =
548 CreateArticleWithURL(pages_url[0].spec());
549 for (int page_num = 1; page_num < kPageCount; ++page_num) {
550 DistilledPageProto* distilled_page = proto->add_pages();
551 distilled_page->set_url(pages_url[page_num].spec());
552 }
553
554 RunDistillerCallback(distiller, proto.Pass());
555 EXPECT_TRUE(store_->GetEntryByUrl(pages_url[0], &entry));
556
557 GURL formattedURL(service_->GetUrlForEntry(entry_id));
558 EXPECT_EQ(pages_url[0], formattedURL);
559
560 service_->RemoveEntry(entry_id);
561 base::RunLoop().RunUntilIdle();
562 EXPECT_EQ(0u, store_->GetEntries().size());
563 EXPECT_EQ("", service_->GetUrlForEntry(entry_id));
564 }
565
461 } // namespace test 566 } // namespace test
462 } // namespace dom_distiller 567 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698