1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
// Copyright (c) 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/user_prefs/tracked/registry_hash_store_contents_win.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/test_reg_util_win.h"
#include "base/values.h"
#include "base/win/registry.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
constexpr base::char16 kRegistryPath[] = L"Foo\\TestStore";
constexpr base::char16 kStoreKey[] = L"test_store_key";
// Hex-encoded MACs are 64 characters long.
constexpr char kTestStringA[] =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
constexpr char kTestStringB[] =
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
constexpr char kAtomicPrefPath[] = "path1";
constexpr char kSplitPrefPath[] = "extension";
class RegistryHashStoreContentsWinTest : public testing::Test {
protected:
RegistryHashStoreContentsWinTest() {}
void SetUp() override {
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
contents.reset(new RegistryHashStoreContentsWin(kRegistryPath, kStoreKey));
}
std::unique_ptr<HashStoreContents> contents;
private:
registry_util::RegistryOverrideManager registry_override_manager_;
DISALLOW_COPY_AND_ASSIGN(RegistryHashStoreContentsWinTest);
};
} // namespace
TEST_F(RegistryHashStoreContentsWinTest, TestSetAndGetMac) {
std::string stored_mac;
EXPECT_FALSE(contents->GetMac(kAtomicPrefPath, &stored_mac));
contents->SetMac(kAtomicPrefPath, kTestStringA);
EXPECT_TRUE(contents->GetMac(kAtomicPrefPath, &stored_mac));
EXPECT_EQ(kTestStringA, stored_mac);
}
TEST_F(RegistryHashStoreContentsWinTest, TestSetAndGetSplitMacs) {
std::map<std::string, std::string> split_macs;
EXPECT_FALSE(contents->GetSplitMacs(kSplitPrefPath, &split_macs));
contents->SetSplitMac(kSplitPrefPath, "a", kTestStringA);
contents->SetSplitMac(kSplitPrefPath, "b", kTestStringB);
EXPECT_TRUE(contents->GetSplitMacs(kSplitPrefPath, &split_macs));
EXPECT_EQ(2U, split_macs.size());
EXPECT_EQ(kTestStringA, split_macs.at("a"));
EXPECT_EQ(kTestStringB, split_macs.at("b"));
}
TEST_F(RegistryHashStoreContentsWinTest, TestRemoveAtomicMac) {
contents->SetMac(kAtomicPrefPath, kTestStringA);
std::string stored_mac;
EXPECT_TRUE(contents->GetMac(kAtomicPrefPath, &stored_mac));
EXPECT_EQ(kTestStringA, stored_mac);
contents->RemoveEntry(kAtomicPrefPath);
EXPECT_FALSE(contents->GetMac(kAtomicPrefPath, &stored_mac));
}
TEST_F(RegistryHashStoreContentsWinTest, TestRemoveSplitMacs) {
contents->SetSplitMac(kSplitPrefPath, "a", kTestStringA);
contents->SetSplitMac(kSplitPrefPath, "b", kTestStringB);
std::map<std::string, std::string> split_macs;
EXPECT_TRUE(contents->GetSplitMacs(kSplitPrefPath, &split_macs));
EXPECT_EQ(2U, split_macs.size());
contents->RemoveEntry(kSplitPrefPath);
split_macs.clear();
EXPECT_FALSE(contents->GetSplitMacs(kSplitPrefPath, &split_macs));
EXPECT_EQ(0U, split_macs.size());
}
TEST_F(RegistryHashStoreContentsWinTest, TestReset) {
contents->SetMac(kAtomicPrefPath, kTestStringA);
contents->SetSplitMac(kSplitPrefPath, "a", kTestStringA);
std::string stored_mac;
EXPECT_TRUE(contents->GetMac(kAtomicPrefPath, &stored_mac));
EXPECT_EQ(kTestStringA, stored_mac);
std::map<std::string, std::string> split_macs;
EXPECT_TRUE(contents->GetSplitMacs(kSplitPrefPath, &split_macs));
EXPECT_EQ(1U, split_macs.size());
contents->Reset();
stored_mac.clear();
EXPECT_FALSE(contents->GetMac(kAtomicPrefPath, &stored_mac));
EXPECT_TRUE(stored_mac.empty());
split_macs.clear();
EXPECT_FALSE(contents->GetSplitMacs(kSplitPrefPath, &split_macs));
EXPECT_EQ(0U, split_macs.size());
}
|