Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / invalidation / invalidator_storage_unittest.cc
blobd37588b4b592fd6360765922025e9c791aa3e2d0
1 // Copyright (c) 2012 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/impl/invalidator_storage.h"
7 #include "base/prefs/pref_service.h"
8 #include "base/strings/string_util.h"
9 #include "chrome/test/base/testing_pref_service_syncable.h"
10 #include "components/invalidation/impl/unacked_invalidation_set_test_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace invalidation {
15 class InvalidatorStorageTest : public testing::Test {
16 public:
17 InvalidatorStorageTest() {}
19 void SetUp() override {
20 InvalidatorStorage::RegisterProfilePrefs(pref_service_.registry());
23 protected:
24 TestingPrefServiceSyncable pref_service_;
27 // Clearing the storage should erase all version map entries, bootstrap data,
28 // and the client ID.
29 TEST_F(InvalidatorStorageTest, Clear) {
30 InvalidatorStorage storage(&pref_service_);
31 EXPECT_TRUE(storage.GetBootstrapData().empty());
32 EXPECT_TRUE(storage.GetInvalidatorClientId().empty());
34 storage.ClearAndSetNewClientId("fake_id");
35 EXPECT_EQ("fake_id", storage.GetInvalidatorClientId());
37 storage.SetBootstrapData("test");
38 EXPECT_EQ("test", storage.GetBootstrapData());
40 storage.Clear();
42 EXPECT_TRUE(storage.GetBootstrapData().empty());
43 EXPECT_TRUE(storage.GetInvalidatorClientId().empty());
46 TEST_F(InvalidatorStorageTest, SetGetNotifierClientId) {
47 InvalidatorStorage storage(&pref_service_);
48 const std::string client_id("fK6eDzAIuKqx9A4+93bljg==");
50 storage.ClearAndSetNewClientId(client_id);
51 EXPECT_EQ(client_id, storage.GetInvalidatorClientId());
54 TEST_F(InvalidatorStorageTest, SetGetBootstrapData) {
55 InvalidatorStorage storage(&pref_service_);
56 const std::string mess("n\0tK\0\0l\344", 8);
57 ASSERT_FALSE(base::IsStringUTF8(mess));
59 storage.SetBootstrapData(mess);
60 EXPECT_EQ(mess, storage.GetBootstrapData());
63 TEST_F(InvalidatorStorageTest, SaveGetInvalidations_Empty) {
64 InvalidatorStorage storage(&pref_service_);
65 syncer::UnackedInvalidationsMap empty_map;
66 ASSERT_TRUE(empty_map.empty());
68 storage.SetSavedInvalidations(empty_map);
69 syncer::UnackedInvalidationsMap restored_map =
70 storage.GetSavedInvalidations();
71 EXPECT_TRUE(restored_map.empty());
74 TEST_F(InvalidatorStorageTest, SaveGetInvalidations) {
75 InvalidatorStorage storage(&pref_service_);
77 ObjectId id1(10, "object1");
78 syncer::UnackedInvalidationSet storage1(id1);
79 syncer::Invalidation unknown_version_inv =
80 syncer::Invalidation::InitUnknownVersion(id1);
81 syncer::Invalidation known_version_inv =
82 syncer::Invalidation::Init(id1, 314, "payload");
83 storage1.Add(unknown_version_inv);
84 storage1.Add(known_version_inv);
86 ObjectId id2(10, "object2");
87 syncer::UnackedInvalidationSet storage2(id2);
88 syncer::Invalidation obj2_inv =
89 syncer::Invalidation::Init(id2, 1234, "payl\0ad\xff");
90 storage2.Add(obj2_inv);
92 syncer::UnackedInvalidationsMap map;
93 map.insert(std::make_pair(storage1.object_id(), storage1));
94 map.insert(std::make_pair(storage2.object_id(), storage2));
96 storage.SetSavedInvalidations(map);
97 syncer::UnackedInvalidationsMap restored_map =
98 storage.GetSavedInvalidations();
100 EXPECT_THAT(map, syncer::test_util::Eq(restored_map));
103 } // namespace invalidation