cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / sync / syncable / entry_kernel_unittest.cc
blobba65207e11bde580dc49302ea99c417471f4ed4b
1 // Copyright 2014 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.
5 #include "sync/syncable/entry_kernel.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace syncer {
11 namespace syncable {
13 class EntryKernelTest : public testing::Test {};
15 TEST_F(EntryKernelTest, ToValue) {
16 EntryKernel kernel;
17 scoped_ptr<base::DictionaryValue> value(kernel.ToValue(NULL));
18 if (value) {
19 // Not much to check without repeating the ToValue() code.
20 EXPECT_TRUE(value->HasKey("isDirty"));
21 // The extra +2 is for "isDirty" and "modelType".
22 EXPECT_EQ(BIT_TEMPS_END - BEGIN_FIELDS + 2,
23 static_cast<int>(value->size()));
24 } else {
25 ADD_FAILURE();
29 bool ProtoFieldValuesEqual(const sync_pb::EntitySpecifics& v1,
30 const sync_pb::EntitySpecifics& v2) {
31 return v1.SerializeAsString() == v2.SerializeAsString();
34 bool ProtoFieldValuesAreSame(const sync_pb::EntitySpecifics& v1,
35 const sync_pb::EntitySpecifics& v2) {
36 return &v1 == &v2;
39 bool ProtoFieldValueIsDefault(const sync_pb::EntitySpecifics& v) {
40 return ProtoFieldValuesAreSame(v,
41 sync_pb::EntitySpecifics::default_instance());
44 // Tests default value, assignment, and sharing of proto fields.
45 TEST_F(EntryKernelTest, ProtoFieldTest) {
46 EntryKernel kernel;
48 // Check default values.
49 EXPECT_TRUE(ProtoFieldValueIsDefault(kernel.ref(SPECIFICS)));
50 EXPECT_TRUE(ProtoFieldValueIsDefault(kernel.ref(SERVER_SPECIFICS)));
51 EXPECT_TRUE(ProtoFieldValueIsDefault(kernel.ref(BASE_SERVER_SPECIFICS)));
53 sync_pb::EntitySpecifics specifics;
55 // Assign empty value and verify that the field still returns the
56 // default value.
57 kernel.put(SPECIFICS, specifics);
58 EXPECT_TRUE(ProtoFieldValueIsDefault(kernel.ref(SPECIFICS)));
59 EXPECT_TRUE(ProtoFieldValuesEqual(kernel.ref(SPECIFICS), specifics));
61 // Verifies that the kernel holds the copy of the value assigned to it.
62 specifics.mutable_bookmark()->set_url("http://demo/");
63 EXPECT_FALSE(ProtoFieldValuesEqual(kernel.ref(SPECIFICS), specifics));
65 // Put the new value and verify the equality.
66 kernel.put(SPECIFICS, specifics);
67 EXPECT_TRUE(ProtoFieldValuesEqual(kernel.ref(SPECIFICS), specifics));
68 EXPECT_FALSE(ProtoFieldValueIsDefault(kernel.ref(SPECIFICS)));
70 // Copy the value between the fields and verify that exactly the same
71 // underlying value is shared.
72 kernel.copy(SPECIFICS, SERVER_SPECIFICS);
73 EXPECT_TRUE(ProtoFieldValuesEqual(kernel.ref(SERVER_SPECIFICS), specifics));
74 EXPECT_TRUE(ProtoFieldValuesAreSame(kernel.ref(SPECIFICS),
75 kernel.ref(SERVER_SPECIFICS)));
77 // Put the new value into SPECIFICS and verify that that stops sharing even
78 // though the values are still equal.
79 kernel.put(SPECIFICS, specifics);
80 EXPECT_FALSE(ProtoFieldValuesAreSame(kernel.ref(SPECIFICS),
81 kernel.ref(SERVER_SPECIFICS)));
84 } // namespace syncable
86 } // namespace syncer