diff options
Diffstat (limited to 'sync/engine/syncer_unittest.cc')
-rw-r--r-- | sync/engine/syncer_unittest.cc | 79 |
1 files changed, 74 insertions, 5 deletions
diff --git a/sync/engine/syncer_unittest.cc b/sync/engine/syncer_unittest.cc index 304dd5a..1bdc13a 100644 --- a/sync/engine/syncer_unittest.cc +++ b/sync/engine/syncer_unittest.cc @@ -105,7 +105,6 @@ using syncable::SPECIFICS; using syncable::SYNCING; using syncable::UNITTEST; -using sessions::ScopedSetSessionWriteTransaction; using sessions::StatusController; using sessions::SyncSessionContext; using sessions::SyncSession; @@ -409,18 +408,16 @@ class SyncerTest : public testing::Test, const vector<syncable::Id>& expected_id_order) { for (size_t limit = expected_id_order.size() + 2; limit > 0; --limit) { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans); ModelSafeRoutingInfo routes; GetModelSafeRoutingInfo(&routes); sessions::OrderedCommitSet output_set(routes); - GetCommitIdsCommand command(limit, &output_set); + GetCommitIdsCommand command(&wtrans, limit, &output_set); std::set<int64> ready_unsynced_set; command.FilterUnreadyEntries(&wtrans, ModelTypeSet(), ModelTypeSet(), false, unsynced_handle_view, &ready_unsynced_set); - command.BuildCommitIds(session_->write_transaction(), routes, - ready_unsynced_set); + command.BuildCommitIds(&wtrans, routes, ready_unsynced_set); size_t truncated_size = std::min(limit, expected_id_order.size()); ASSERT_EQ(truncated_size, output_set.Size()); for (size_t i = 0; i < truncated_size; ++i) { @@ -4924,4 +4921,76 @@ TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { ExpectLocalOrderIsByServerId(); } +enum { + TEST_PARAM_BOOKMARK_ENABLE_BIT, + TEST_PARAM_AUTOFILL_ENABLE_BIT, + TEST_PARAM_BIT_COUNT +}; + +class MixedResult : + public SyncerTest, + public ::testing::WithParamInterface<int> { + protected: + bool ShouldFailBookmarkCommit() { + return (GetParam() & (1 << TEST_PARAM_BOOKMARK_ENABLE_BIT)) == 0; + } + bool ShouldFailAutofillCommit() { + return (GetParam() & (1 << TEST_PARAM_AUTOFILL_ENABLE_BIT)) == 0; + } +}; + +INSTANTIATE_TEST_CASE_P(ExtensionsActivity, + MixedResult, + testing::Range(0, 1 << TEST_PARAM_BIT_COUNT)); + +TEST_P(MixedResult, ExtensionsActivity) { + { + WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); + + MutableEntry pref(&wtrans, CREATE, PREFERENCES, wtrans.root_id(), "pref"); + ASSERT_TRUE(pref.good()); + pref.Put(syncable::IS_UNSYNCED, true); + + MutableEntry bookmark( + &wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "bookmark"); + ASSERT_TRUE(bookmark.good()); + bookmark.Put(syncable::IS_UNSYNCED, true); + + if (ShouldFailBookmarkCommit()) { + mock_server_->SetTransientErrorId(bookmark.Get(ID)); + } + + if (ShouldFailAutofillCommit()) { + mock_server_->SetTransientErrorId(pref.Get(ID)); + } + } + + + // Put some extenions activity records into the monitor. + { + ExtensionsActivityMonitor::Records records; + records["ABC"].extension_id = "ABC"; + records["ABC"].bookmark_write_count = 2049U; + records["xyz"].extension_id = "xyz"; + records["xyz"].bookmark_write_count = 4U; + context_->extensions_monitor()->PutRecords(records); + } + + SyncShareNudge(); + + ExtensionsActivityMonitor::Records final_monitor_records; + context_->extensions_monitor()->GetAndClearRecords(&final_monitor_records); + if (ShouldFailBookmarkCommit()) { + ASSERT_EQ(2U, final_monitor_records.size()) + << "Should restore records after unsuccessful bookmark commit."; + EXPECT_EQ("ABC", final_monitor_records["ABC"].extension_id); + EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); + EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); + EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); + } else { + EXPECT_TRUE(final_monitor_records.empty()) + << "Should not restore records after successful bookmark commit."; + } +} + } // namespace syncer |