1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/sync/engine_impl/loopback_server/persistent_bookmark_entity.h"
6
7 #include "base/guid.h"
8 #include "components/sync/protocol/sync.pb.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace syncer {
12
13 namespace {
14
TEST(PersistentBookmarkEntityTest,CreateNew)15 TEST(PersistentBookmarkEntityTest, CreateNew) {
16 sync_pb::SyncEntity entity;
17 entity.set_id_string(base::GenerateGUID());
18
19 entity.mutable_specifics()->mutable_preference();
20 EXPECT_FALSE(
21 PersistentBookmarkEntity::CreateNew(entity, "parent_id", "client_guid"));
22
23 entity.clear_specifics();
24 entity.mutable_specifics()->mutable_bookmark();
25 EXPECT_TRUE(
26 PersistentBookmarkEntity::CreateNew(entity, "parent_id", "client_guid"));
27 }
28
TEST(PersistentBookmarkEntityTest,CreateUpdatedVersion)29 TEST(PersistentBookmarkEntityTest, CreateUpdatedVersion) {
30 sync_pb::SyncEntity client_entity;
31 client_entity.mutable_specifics()->mutable_bookmark();
32 auto server_entity =
33 PersistentBookmarkEntity::CreateFromEntity(client_entity);
34 ASSERT_TRUE(server_entity);
35
36 // Fails with since there's no version
37 ASSERT_FALSE(PersistentBookmarkEntity::CreateUpdatedVersion(
38 client_entity, *server_entity, "parent_id", "updating_guid"));
39
40 // And now succeeds that we have a version.
41 client_entity.set_version(1);
42 ASSERT_TRUE(PersistentBookmarkEntity::CreateUpdatedVersion(
43 client_entity, *server_entity, "parent_id", "updating_guid"));
44
45 // But fails when not actually a bookmark.
46 client_entity.clear_specifics();
47 client_entity.mutable_specifics()->mutable_preference();
48 ASSERT_FALSE(PersistentBookmarkEntity::CreateUpdatedVersion(
49 client_entity, *server_entity, "parent_id", "updating_guid"));
50 }
51
TEST(PersistentBookmarkEntityTest,CreateFromEntity)52 TEST(PersistentBookmarkEntityTest, CreateFromEntity) {
53 sync_pb::SyncEntity entity;
54 entity.mutable_specifics()->mutable_preference();
55 EXPECT_FALSE(PersistentBookmarkEntity::CreateFromEntity(entity));
56
57 entity.clear_specifics();
58 entity.mutable_specifics()->mutable_bookmark();
59 EXPECT_TRUE(PersistentBookmarkEntity::CreateFromEntity(entity));
60 }
61
62 } // namespace
63
64 } // namespace syncer
65