Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / components / invalidation / object_id_invalidation_map_unittest.cc
blob34b2e88a702cbce8f319d6040ab78a66971134a9
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 "components/invalidation/object_id_invalidation_map.h"
7 #include "google/cacheinvalidation/types.pb.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace syncer {
13 namespace {
15 class ObjectIdInvalidationMapTest : public testing::Test {
16 public:
17 ObjectIdInvalidationMapTest()
18 : kIdOne(ipc::invalidation::ObjectSource::TEST, "one"),
19 kIdTwo(ipc::invalidation::ObjectSource::TEST, "two"),
20 kInv1(Invalidation::Init(kIdOne, 10, "ten")) {
21 set1.insert(kIdOne);
22 set2.insert(kIdTwo);
23 all_set.insert(kIdOne);
24 all_set.insert(kIdTwo);
26 one_invalidation.Insert(kInv1);
27 invalidate_all = ObjectIdInvalidationMap::InvalidateAll(all_set);
30 protected:
31 const invalidation::ObjectId kIdOne;
32 const invalidation::ObjectId kIdTwo;
33 const Invalidation kInv1;
35 ObjectIdSet set1;
36 ObjectIdSet set2;
37 ObjectIdSet all_set;
38 ObjectIdInvalidationMap empty;
39 ObjectIdInvalidationMap one_invalidation;
40 ObjectIdInvalidationMap invalidate_all;
43 TEST_F(ObjectIdInvalidationMapTest, Empty) {
44 EXPECT_TRUE(empty.Empty());
45 EXPECT_FALSE(one_invalidation.Empty());
46 EXPECT_FALSE(invalidate_all.Empty());
49 TEST_F(ObjectIdInvalidationMapTest, Equality) {
50 ObjectIdInvalidationMap empty2;
51 EXPECT_TRUE(empty == empty2);
53 ObjectIdInvalidationMap one_invalidation2;
54 one_invalidation2.Insert(kInv1);
55 EXPECT_TRUE(one_invalidation == one_invalidation2);
57 EXPECT_FALSE(empty == invalidate_all);
60 TEST_F(ObjectIdInvalidationMapTest, GetObjectIds) {
61 EXPECT_EQ(ObjectIdSet(), empty.GetObjectIds());
62 EXPECT_EQ(set1, one_invalidation.GetObjectIds());
63 EXPECT_EQ(all_set, invalidate_all.GetObjectIds());
66 TEST_F(ObjectIdInvalidationMapTest, GetSubsetWithObjectIds) {
67 EXPECT_TRUE(empty.GetSubsetWithObjectIds(set1).Empty());
69 EXPECT_TRUE(one_invalidation.GetSubsetWithObjectIds(set1) ==
70 one_invalidation);
71 EXPECT_TRUE(one_invalidation.GetSubsetWithObjectIds(all_set) ==
72 one_invalidation);
73 EXPECT_TRUE(one_invalidation.GetSubsetWithObjectIds(set2).Empty());
75 EXPECT_TRUE(invalidate_all.GetSubsetWithObjectIds(ObjectIdSet()).Empty());
78 TEST_F(ObjectIdInvalidationMapTest, SerializeEmpty) {
79 scoped_ptr<base::ListValue> value = empty.ToValue();
80 ASSERT_TRUE(value.get());
81 ObjectIdInvalidationMap deserialized;
82 deserialized.ResetFromValue(*value.get());
83 EXPECT_TRUE(empty == deserialized);
86 TEST_F(ObjectIdInvalidationMapTest, SerializeOneInvalidation) {
87 scoped_ptr<base::ListValue> value = one_invalidation.ToValue();
88 ASSERT_TRUE(value.get());
89 ObjectIdInvalidationMap deserialized;
90 deserialized.ResetFromValue(*value.get());
91 EXPECT_TRUE(one_invalidation == deserialized);
94 TEST_F(ObjectIdInvalidationMapTest, SerializeInvalidateAll) {
95 scoped_ptr<base::ListValue> value = invalidate_all.ToValue();
96 ASSERT_TRUE(value.get());
97 ObjectIdInvalidationMap deserialized;
98 deserialized.ResetFromValue(*value.get());
99 EXPECT_TRUE(invalidate_all == deserialized);
102 } // namespace
104 } // namespace syncer