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

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: string reference 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 // Check that HasEntry returns true for the article just added.
483 EXPECT_TRUE(service_->HasEntry(entry_id));
484
485 // Remove article and check that there is no longer an entry for the given
486 // entry id.
487 service_->RemoveEntry(entry_id);
488 base::RunLoop().RunUntilIdle();
489 EXPECT_EQ(0u, store_->GetEntries().size());
490 EXPECT_FALSE(service_->HasEntry(entry_id));
491 }
492
493 TEST_F(DomDistillerServiceTest, TestGetUrlForOnePageEntry) {
494 FakeDistiller* distiller = new FakeDistiller(false);
495 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl())
496 .WillOnce(Return(distiller));
497
498 GURL url("http://www.example.com/p1");
499
500 MockArticleAvailableCallback article_cb;
501 EXPECT_CALL(article_cb, DistillationCompleted(true));
502
503 std::string entry_id = service_->AddToList(
504 url,
505 service_->CreateDefaultDistillerPage(gfx::Size()).Pass(),
506 ArticleCallback(&article_cb));
507
508 ASSERT_FALSE(distiller->GetArticleCallback().is_null());
509 EXPECT_EQ(url, distiller->GetUrl());
510
511 scoped_ptr<DistilledArticleProto> proto = CreateArticleWithURL(url.spec());
512 RunDistillerCallback(distiller, proto.Pass());
513
514 // Check if retrieved URL is same as given URL.
515 GURL retrieved_url(service_->GetUrlForEntry(entry_id));
516 EXPECT_EQ(url, retrieved_url);
517
518 // Remove article and check that there is no longer an entry for the given
519 // entry id.
520 service_->RemoveEntry(entry_id);
521 base::RunLoop().RunUntilIdle();
522 EXPECT_EQ(0u, store_->GetEntries().size());
523 EXPECT_EQ("", service_->GetUrlForEntry(entry_id));
524 }
525
526 TEST_F(DomDistillerServiceTest, TestGetUrlForMultiPageEntry) {
527 FakeDistiller* distiller = new FakeDistiller(false);
528 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl())
529 .WillOnce(Return(distiller));
530
531 const int kPageCount = 8;
532
533 std::string base_url("http://www.example.com/p");
534 GURL pages_url[kPageCount];
535 for (int page_num = 0; page_num < kPageCount; ++page_num) {
536 pages_url[page_num] = GURL(base_url + base::IntToString(page_num));
537 }
538
539 MockArticleAvailableCallback article_cb;
540 EXPECT_CALL(article_cb, DistillationCompleted(true));
541
542 std::string entry_id = service_->AddToList(
543 pages_url[0],
544 service_->CreateDefaultDistillerPage(gfx::Size()).Pass(),
545 ArticleCallback(&article_cb));
546
547 ArticleEntry entry;
548 ASSERT_FALSE(distiller->GetArticleCallback().is_null());
549 EXPECT_EQ(pages_url[0], distiller->GetUrl());
550
551 // Create the article with pages to pass to the distiller.
552 scoped_ptr<DistilledArticleProto> proto =
553 CreateArticleWithURL(pages_url[0].spec());
554 for (int page_num = 1; page_num < kPageCount; ++page_num) {
555 DistilledPageProto* distilled_page = proto->add_pages();
556 distilled_page->set_url(pages_url[page_num].spec());
557 }
558
559 RunDistillerCallback(distiller, proto.Pass());
560 EXPECT_TRUE(store_->GetEntryByUrl(pages_url[0], &entry));
561
562 // Check if retrieved URL is same as given URL for the first page.
563 GURL retrieved_url(service_->GetUrlForEntry(entry_id));
564 EXPECT_EQ(pages_url[0], retrieved_url);
565
566 // Remove the article and check that no URL can be retrieved for the entry.
567 service_->RemoveEntry(entry_id);
568 base::RunLoop().RunUntilIdle();
569 EXPECT_EQ(0u, store_->GetEntries().size());
570 EXPECT_EQ("", service_->GetUrlForEntry(entry_id));
571 }
572
461 } // namespace test 573 } // namespace test
462 } // namespace dom_distiller 574 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « components/dom_distiller/core/dom_distiller_service_android.cc ('k') | components/dom_distiller/core/url_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698