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

Unified Diff: components/reading_list/ios/reading_list_store_unittest.cc

Issue 2764533002: Reading List iOS: Use external clock in ReadingListEntry. (Closed)
Patch Set: fix microseconds Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: components/reading_list/ios/reading_list_store_unittest.cc
diff --git a/components/reading_list/ios/reading_list_store_unittest.mm b/components/reading_list/ios/reading_list_store_unittest.cc
similarity index 91%
rename from components/reading_list/ios/reading_list_store_unittest.mm
rename to components/reading_list/ios/reading_list_store_unittest.cc
index 9ba369d41bdf680368cea50793c66dbc7e1408cc..38495dfa52a2a9f2f150a79baeee969ea0db9fce 100644
--- a/components/reading_list/ios/reading_list_store_unittest.mm
+++ b/components/reading_list/ios/reading_list_store_unittest.cc
@@ -11,12 +11,14 @@
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
-#import "base/test/ios/wait_util.h"
+#include "base/test/simple_test_clock.h"
#include "components/reading_list/ios/reading_list_model_impl.h"
#include "components/sync/model/fake_model_type_change_processor.h"
#include "components/sync/model/model_type_store_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace {
+
// Tests that the transition from |entryA| to |entryB| is possible (|possible|
// is true) or not.
void ExpectAB(const sync_pb::ReadingListSpecifics& entryA,
@@ -24,9 +26,11 @@ void ExpectAB(const sync_pb::ReadingListSpecifics& entryA,
bool possible) {
EXPECT_EQ(ReadingListStore::CompareEntriesForSync(entryA, entryB), possible);
std::unique_ptr<ReadingListEntry> a =
- ReadingListEntry::FromReadingListSpecifics(entryA);
+ ReadingListEntry::FromReadingListSpecifics(entryA,
+ base::Time::FromTimeT(10));
std::unique_ptr<ReadingListEntry> b =
- ReadingListEntry::FromReadingListSpecifics(entryB);
+ ReadingListEntry::FromReadingListSpecifics(entryB,
+ base::Time::FromTimeT(10));
a->MergeWithEntry(*b);
std::unique_ptr<sync_pb::ReadingListSpecifics> mergedEntry =
a->AsReadingListSpecifics();
@@ -40,6 +44,12 @@ void ExpectAB(const sync_pb::ReadingListSpecifics& entryA,
EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryB, *mergedEntry));
}
}
gambard 2017/03/21 13:08:07 Add new line.
Olivier 2017/03/21 14:01:10 Done.
+base::Time AdvanceAndGetTime(base::SimpleTestClock* clock) {
+ clock->Advance(base::TimeDelta::FromMilliseconds(10));
+ return clock->Now();
+}
+
+} // namespace
class FakeModelTypeChangeProcessorObserver {
public:
@@ -85,8 +95,11 @@ class ReadingListStoreTest : public testing::Test,
base::Passed(&store_)),
base::Bind(&ReadingListStoreTest::CreateModelTypeChangeProcessor,
base::Unretained(this)));
- model_ = base::MakeUnique<ReadingListModelImpl>(nullptr, nullptr);
- reading_list_store_->SetReadingListModel(model_.get(), this);
+ auto clock = base::MakeUnique<base::SimpleTestClock>();
+ clock_ = clock.get();
+ model_ = base::MakeUnique<ReadingListModelImpl>(nullptr, nullptr,
+ std::move(clock));
+ reading_list_store_->SetReadingListModel(model_.get(), this, clock_);
base::RunLoop().RunUntilIdle();
gambard 2017/03/21 13:08:07 What is this used for?
}
@@ -163,6 +176,7 @@ class ReadingListStoreTest : public testing::Test,
std::unique_ptr<syncer::ModelTypeStore> store_;
std::unique_ptr<ReadingListModelImpl> model_;
+ base::SimpleTestClock* clock_;
std::unique_ptr<ReadingListStore> reading_list_store_;
int put_called_;
int delete_called_;
@@ -181,8 +195,10 @@ TEST_F(ReadingListStoreTest, CheckEmpties) {
}
TEST_F(ReadingListStoreTest, SaveOneRead) {
- ReadingListEntry entry(GURL("http://read.example.com/"), "read title");
- entry.SetRead(true);
+ ReadingListEntry entry(GURL("http://read.example.com/"), "read title",
+ AdvanceAndGetTime(clock_));
+ entry.SetRead(true, AdvanceAndGetTime(clock_));
+ AdvanceAndGetTime(clock_);
reading_list_store_->SaveEntry(entry);
AssertCounts(1, 0, 0, 0, 0);
syncer::EntityData* data = put_multimap_["http://read.example.com/"].get();
@@ -194,7 +210,8 @@ TEST_F(ReadingListStoreTest, SaveOneRead) {
}
TEST_F(ReadingListStoreTest, SaveOneUnread) {
- ReadingListEntry entry(GURL("http://unread.example.com/"), "unread title");
+ ReadingListEntry entry(GURL("http://unread.example.com/"), "unread title",
+ AdvanceAndGetTime(clock_));
reading_list_store_->SaveEntry(entry);
AssertCounts(1, 0, 0, 0, 0);
syncer::EntityData* data = put_multimap_["http://unread.example.com/"].get();
@@ -207,8 +224,9 @@ TEST_F(ReadingListStoreTest, SaveOneUnread) {
TEST_F(ReadingListStoreTest, SyncMergeOneEntry) {
syncer::EntityDataMap remote_input;
- ReadingListEntry entry(GURL("http://read.example.com/"), "read title");
- entry.SetRead(true);
+ ReadingListEntry entry(GURL("http://read.example.com/"), "read title",
+ AdvanceAndGetTime(clock_));
+ entry.SetRead(true, AdvanceAndGetTime(clock_));
std::unique_ptr<sync_pb::ReadingListSpecifics> specifics =
entry.AsReadingListSpecifics();
@@ -230,8 +248,9 @@ TEST_F(ReadingListStoreTest, SyncMergeOneEntry) {
TEST_F(ReadingListStoreTest, ApplySyncChangesOneAdd) {
syncer::EntityDataMap remote_input;
- ReadingListEntry entry(GURL("http://read.example.com/"), "read title");
- entry.SetRead(true);
+ ReadingListEntry entry(GURL("http://read.example.com/"), "read title",
+ AdvanceAndGetTime(clock_));
+ entry.SetRead(true, AdvanceAndGetTime(clock_));
std::unique_ptr<sync_pb::ReadingListSpecifics> specifics =
entry.AsReadingListSpecifics();
syncer::EntityData data;
@@ -252,14 +271,13 @@ TEST_F(ReadingListStoreTest, ApplySyncChangesOneAdd) {
TEST_F(ReadingListStoreTest, ApplySyncChangesOneMerge) {
syncer::EntityDataMap remote_input;
+ AdvanceAndGetTime(clock_);
model_->AddEntry(GURL("http://unread.example.com/"), "unread title",
reading_list::ADDED_VIA_CURRENT_APP);
- base::test::ios::SpinRunLoopWithMinDelay(
- base::TimeDelta::FromMilliseconds(10));
- ReadingListEntry new_entry(GURL("http://unread.example.com/"),
- "unread title");
- new_entry.SetRead(true);
+ ReadingListEntry new_entry(GURL("http://unread.example.com/"), "unread title",
+ AdvanceAndGetTime(clock_));
+ new_entry.SetRead(true, AdvanceAndGetTime(clock_));
std::unique_ptr<sync_pb::ReadingListSpecifics> specifics =
new_entry.AsReadingListSpecifics();
syncer::EntityData data;
@@ -280,12 +298,11 @@ TEST_F(ReadingListStoreTest, ApplySyncChangesOneMerge) {
TEST_F(ReadingListStoreTest, ApplySyncChangesOneIgnored) {
// Read entry but with unread URL as it must update the other one.
ReadingListEntry old_entry(GURL("http://unread.example.com/"),
- "old unread title");
- old_entry.SetRead(true);
+ "old unread title", AdvanceAndGetTime(clock_));
+ old_entry.SetRead(true, AdvanceAndGetTime(clock_));
- base::test::ios::SpinRunLoopWithMinDelay(
- base::TimeDelta::FromMilliseconds(10));
syncer::EntityDataMap remote_input;
+ AdvanceAndGetTime(clock_);
model_->AddEntry(GURL("http://unread.example.com/"), "new unread title",
reading_list::ADDED_VIA_CURRENT_APP);
AssertCounts(0, 0, 0, 0, 0);

Powered by Google App Engine
This is Rietveld 408576698