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

Side by Side Diff: components/reading_list/reading_list_model_unittest.cc

Issue 2514333003: Componentize Reading List (Closed)
Patch Set: fix Created 4 years 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/ptr_util.h" 6 #include "base/memory/ptr_util.h"
7 #import "base/test/ios/wait_util.h" 7 #import "base/test/ios/wait_util.h"
8 #include "ios/chrome/browser/reading_list/reading_list_model_impl.h" 8 #include "components/reading_list/reading_list_model_impl.h"
9 #include "ios/chrome/browser/reading_list/reading_list_model_storage.h" 9 #include "components/reading_list/reading_list_model_storage.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace { 12 namespace {
13 13
14 const GURL callback_url("http://example.com"); 14 const GURL callback_url("http://example.com");
15 const std::string callback_title("test title"); 15 const std::string callback_title("test title");
16 16
17 class TestReadingListStorageObserver { 17 class TestReadingListStorageObserver {
18 public: 18 public:
19 virtual void ReadingListDidSaveEntry() = 0; 19 virtual void ReadingListDidSaveEntry() = 0;
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 const ReadingListEntry* local_entry = 287 const ReadingListEntry* local_entry =
288 model_->GetEntryFromURL(GURL("http://example.com"), nullptr); 288 model_->GetEntryFromURL(GURL("http://example.com"), nullptr);
289 int64_t local_update_time = local_entry->UpdateTime(); 289 int64_t local_update_time = local_entry->UpdateTime();
290 290
291 base::test::ios::SpinRunLoopWithMinDelay( 291 base::test::ios::SpinRunLoopWithMinDelay(
292 base::TimeDelta::FromMilliseconds(10)); 292 base::TimeDelta::FromMilliseconds(10));
293 auto sync_entry = 293 auto sync_entry =
294 base::MakeUnique<ReadingListEntry>(GURL("http://example.com"), "sample"); 294 base::MakeUnique<ReadingListEntry>(GURL("http://example.com"), "sample");
295 ASSERT_GT(sync_entry->UpdateTime(), local_update_time); 295 ASSERT_GT(sync_entry->UpdateTime(), local_update_time);
296 int64_t sync_update_time = sync_entry->UpdateTime(); 296 int64_t sync_update_time = sync_entry->UpdateTime();
297 EXPECT_FALSE(sync_entry->DistilledURL().is_valid()); 297 EXPECT_TRUE(sync_entry->DistilledPath().empty());
298 298
299 EXPECT_EQ(model_->unread_size(), 1u); 299 EXPECT_EQ(model_->unread_size(), 1u);
300 EXPECT_EQ(model_->read_size(), 0u); 300 EXPECT_EQ(model_->read_size(), 0u);
301 301
302 ReadingListEntry* merged_entry = 302 ReadingListEntry* merged_entry =
303 model_->SyncMergeEntry(std::move(sync_entry), true); 303 model_->SyncMergeEntry(std::move(sync_entry), true);
304 EXPECT_EQ(model_->unread_size(), 0u); 304 EXPECT_EQ(model_->unread_size(), 0u);
305 EXPECT_EQ(model_->read_size(), 1u); 305 EXPECT_EQ(model_->read_size(), 1u);
306 EXPECT_EQ(merged_entry->DistilledPath(), 306 EXPECT_EQ(merged_entry->DistilledPath(),
307 base::FilePath("distilled/page.html")); 307 base::FilePath("distilled/page.html"));
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 TEST_F(ReadingListModelTest, UpdateReadDistilledPath) { 528 TEST_F(ReadingListModelTest, UpdateReadDistilledPath) {
529 const GURL gurl("http://example.com"); 529 const GURL gurl("http://example.com");
530 model_->AddEntry(gurl, "sample"); 530 model_->AddEntry(gurl, "sample");
531 model_->MarkReadByURL(gurl); 531 model_->MarkReadByURL(gurl);
532 const ReadingListEntry& entry = model_->GetReadEntryAtIndex(0); 532 const ReadingListEntry& entry = model_->GetReadEntryAtIndex(0);
533 ClearCounts(); 533 ClearCounts();
534 534
535 model_->SetEntryDistilledPath(gurl, base::FilePath("distilled/page.html")); 535 model_->SetEntryDistilledPath(gurl, base::FilePath("distilled/page.html"));
536 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1); 536 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1);
537 EXPECT_EQ(ReadingListEntry::PROCESSED, entry.DistilledState()); 537 EXPECT_EQ(ReadingListEntry::PROCESSED, entry.DistilledState());
538 EXPECT_EQ(GURL("chrome://offline/distilled/page.html"), entry.DistilledURL()); 538 EXPECT_EQ(base::FilePath("distilled/page.html"), entry.DistilledPath());
539 } 539 }
540 540
541 // Tests that the callback is called when the entry is unread. 541 // Tests that the callback is called when the entry is unread.
542 TEST_F(ReadingListModelTest, CallbackEntryURLUnread) { 542 TEST_F(ReadingListModelTest, CallbackEntryURLUnread) {
543 // Setup. 543 // Setup.
544 model_->AddEntry(callback_url, callback_title); 544 model_->AddEntry(callback_url, callback_title);
545 545
546 ASSERT_EQ(0UL, model_->read_size()); 546 ASSERT_EQ(0UL, model_->read_size());
547 ASSERT_EQ(1UL, model_->unread_size()); 547 ASSERT_EQ(1UL, model_->unread_size());
548 548
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 } 593 }
594 594
595 // Tests that ReadingListModel calls CallbackModelBeingDeleted when destroyed. 595 // Tests that ReadingListModel calls CallbackModelBeingDeleted when destroyed.
596 TEST_F(ReadingListModelTest, CallbackModelBeingDeleted) { 596 TEST_F(ReadingListModelTest, CallbackModelBeingDeleted) {
597 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 597 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
598 model_.reset(); 598 model_.reset();
599 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0); 599 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0);
600 } 600 }
601 601
602 } // namespace 602 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698