Chromium Code Reviews| Index: sync/engine/syncer_util_unittest.cc |
| diff --git a/sync/engine/syncer_util_unittest.cc b/sync/engine/syncer_util_unittest.cc |
| index eec72eaad313746ed07dff7830a6755c61ee35ae..80551c05b4d93f3dcd441567636c3ccbe340d18b 100644 |
| --- a/sync/engine/syncer_util_unittest.cc |
| +++ b/sync/engine/syncer_util_unittest.cc |
| @@ -6,13 +6,34 @@ |
| #include "base/rand_util.h" |
| #include "sync/internal_api/public/base/unique_position.h" |
| +#include "sync/internal_api/public/test/test_entry_factory.h" |
| #include "sync/protocol/sync.pb.h" |
| +#include "sync/syncable/mutable_entry.h" |
| +#include "sync/syncable/syncable_write_transaction.h" |
| +#include "sync/test/engine/test_directory_setter_upper.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace syncer { |
| class GetUpdatePositionTest : public ::testing::Test { |
| public: |
| + virtual void SetUp() { |
| + dir_maker_.SetUp(); |
| + entry_factory_.reset(new TestEntryFactory(directory())); |
| + } |
| + |
| + virtual void TearDown() { |
| + dir_maker_.TearDown(); |
| + } |
| + |
| + syncable::Directory* directory() { |
| + return dir_maker_.directory(); |
| + } |
| + |
| + TestEntryFactory* entry_factory() { |
| + return entry_factory_.get(); |
| + } |
| + |
| GetUpdatePositionTest() { |
| InitUpdate(); |
| @@ -49,6 +70,9 @@ class GetUpdatePositionTest : public ::testing::Test { |
| sync_pb::SyncEntity update; |
| UniquePosition test_position; |
| + base::MessageLoop message_loop_; |
| + TestDirectorySetterUpper dir_maker_; |
| + scoped_ptr<TestEntryFactory> entry_factory_; |
| }; |
| // Generate a suffix from originator client GUID and client-assigned ID. These |
| @@ -124,4 +148,59 @@ TEST_F(GetUpdatePositionTest, FromNothing) { |
| EXPECT_TRUE(pos.IsValid()); |
| } |
| +namespace { |
| + |
| +sync_pb::EntitySpecifics DefaultBookmarkSpecifics() { |
| + sync_pb::EntitySpecifics result; |
| + AddDefaultFieldValue(BOOKMARKS, &result); |
| + return result; |
| +} |
| + |
| +} // namespace |
| + |
| +// Checks that whole cycle of unique_position updating from |
|
reat
2014/09/04 05:06:29
I've added some comments what this tests check
|
| +// server works fine and does not browser crash. |
| +TEST_F(GetUpdatePositionTest, UpdateServerFieldsFromUpdateTest) { |
| + InitSuffixIngredients(); // Initialize update with valid data |
|
Nicolas Zea
2014/09/04 18:44:37
nit: Comments should have proper punctuation. Add
reat
2014/09/05 04:42:55
Fixed
|
| + |
| + std::string root_server_id = syncable::GetNullId().GetServerId(); |
| + int64 handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( |
| + "I", DefaultBookmarkSpecifics(), root_server_id); |
| + |
| + syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory()); |
| + syncable::MutableEntry target(&trans, syncable::GET_BY_HANDLE, handle); |
| + |
| + // Before update, target has invalid bookmark tag and unique position |
| + EXPECT_FALSE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag())); |
| + EXPECT_FALSE(target.GetServerUniquePosition().IsValid()); |
| + UpdateServerFieldsFromUpdate(&target, update, "name"); |
| + |
| + // After update, target has valid bookmark tag and unique position |
| + EXPECT_TRUE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag())); |
| + EXPECT_TRUE(target.GetServerUniquePosition().IsValid()); |
| +} |
| + |
| +// Checks that whole cycle of unique_position updating does not |
| +// browser crash even data from server is invalid. |
| +// It looks like server bug, but browser should not crash and work further. |
| +TEST_F(GetUpdatePositionTest, UpdateServerFieldsFromInvalidUpdateTest) { |
| + // Do not initialize data in update, update is invalid |
| + |
| + std::string root_server_id = syncable::GetNullId().GetServerId(); |
| + int64 handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( |
| + "I", DefaultBookmarkSpecifics(), root_server_id); |
| + |
| + syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory()); |
| + syncable::MutableEntry target(&trans, syncable::GET_BY_HANDLE, handle); |
| + |
| + // Before update, target has invalid bookmark tag and unique position |
| + EXPECT_FALSE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag())); |
| + EXPECT_FALSE(target.GetServerUniquePosition().IsValid()); |
| + UpdateServerFieldsFromUpdate(&target, update, "name"); |
| + |
| + // After update, target has valid bookmark tag and unique position |
| + EXPECT_TRUE(UniquePosition::IsValidSuffix(target.GetUniqueBookmarkTag())); |
| + EXPECT_TRUE(target.GetServerUniquePosition().IsValid()); |
| +} |
| + |
| } // namespace syncer |