Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Unified Diff: chrome/browser/prefs/pref_hash_store_impl_unittest.cc

Issue 324493002: Move preference MACs to the protected preference stores. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to CR comments. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/prefs/pref_hash_store_impl_unittest.cc
diff --git a/chrome/browser/prefs/pref_hash_store_impl_unittest.cc b/chrome/browser/prefs/pref_hash_store_impl_unittest.cc
index 5a53ef5b10a4425dc0e7499656a7a938562ca568..cf821449d76172a6ab16a99f644ddfa166ebd8ab 100644
--- a/chrome/browser/prefs/pref_hash_store_impl_unittest.cc
+++ b/chrome/browser/prefs/pref_hash_store_impl_unittest.cc
@@ -31,7 +31,6 @@ class MockHashStoreContents : public HashStoreContents {
scoped_ptr<base::DictionaryValue> contents;
std::string super_mac;
- scoped_ptr<int> version;
bool commit_performed;
};
@@ -43,21 +42,10 @@ class MockHashStoreContents : public HashStoreContents {
virtual void Reset() OVERRIDE {
data_->contents.reset();
data_->super_mac = "";
- data_->version.reset();
}
virtual bool IsInitialized() const OVERRIDE { return data_->contents; }
- virtual bool GetVersion(int* version) const OVERRIDE {
- if (data_->version)
- *version = *data_->version;
- return data_->version;
- }
-
- virtual void SetVersion(int version) OVERRIDE {
- data_->version.reset(new int(version));
- }
-
virtual const base::DictionaryValue* GetContents() const OVERRIDE {
return data_->contents.get();
}
@@ -115,8 +103,8 @@ TEST_F(PrefHashStoreImplTest, AtomicHashStoreAndCheck) {
{
// 32 NULL bytes is the seed that was used to generate the legacy hash.
- PrefHashStoreImpl pref_hash_store(
- std::string(32, 0), "device_id", CreateHashStoreContents());
+ PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true);
+ pref_hash_store.SetHashStoreContents(CreateHashStoreContents());
scoped_ptr<PrefHashStoreTransaction> transaction(
pref_hash_store.BeginTransaction());
@@ -164,8 +152,8 @@ TEST_F(PrefHashStoreImplTest, AtomicHashStoreAndCheck) {
{
// |pref_hash_store2| should trust its initial hashes dictionary and thus
// trust new unknown values.
- PrefHashStoreImpl pref_hash_store2(
- std::string(32, 0), "device_id", CreateHashStoreContents());
+ PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true);
+ pref_hash_store2.SetHashStoreContents(CreateHashStoreContents());
scoped_ptr<PrefHashStoreTransaction> transaction(
pref_hash_store2.BeginTransaction());
EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE,
@@ -188,8 +176,8 @@ TEST_F(PrefHashStoreImplTest, AtomicHashStoreAndCheck) {
{
// |pref_hash_store3| should no longer trust its initial hashes dictionary
// and thus shouldn't trust non-NULL unknown values.
- PrefHashStoreImpl pref_hash_store3(
- std::string(32, 0), "device_id", CreateHashStoreContents());
+ PrefHashStoreImpl pref_hash_store3(std::string(32, 0), "device_id", true);
+ pref_hash_store3.SetHashStoreContents(CreateHashStoreContents());
scoped_ptr<PrefHashStoreTransaction> transaction(
pref_hash_store3.BeginTransaction());
EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE,
@@ -223,8 +211,8 @@ TEST_F(PrefHashStoreImplTest, SplitHashStoreAndCheck) {
std::vector<std::string> invalid_keys;
{
- PrefHashStoreImpl pref_hash_store(
- std::string(32, 0), "device_id", CreateHashStoreContents());
+ PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true);
+ pref_hash_store.SetHashStoreContents(CreateHashStoreContents());
scoped_ptr<PrefHashStoreTransaction> transaction(
pref_hash_store.BeginTransaction());
@@ -299,8 +287,8 @@ TEST_F(PrefHashStoreImplTest, SplitHashStoreAndCheck) {
{
// |pref_hash_store2| should trust its initial hashes dictionary and thus
// trust new unknown values.
- PrefHashStoreImpl pref_hash_store2(
- std::string(32, 0), "device_id", CreateHashStoreContents());
+ PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true);
+ pref_hash_store2.SetHashStoreContents(CreateHashStoreContents());
scoped_ptr<PrefHashStoreTransaction> transaction(
pref_hash_store2.BeginTransaction());
EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE,
@@ -320,8 +308,8 @@ TEST_F(PrefHashStoreImplTest, SplitHashStoreAndCheck) {
{
// |pref_hash_store3| should no longer trust its initial hashes dictionary
// and thus shouldn't trust unknown values.
- PrefHashStoreImpl pref_hash_store3(
- std::string(32, 0), "device_id", CreateHashStoreContents());
+ PrefHashStoreImpl pref_hash_store3(std::string(32, 0), "device_id", true);
+ pref_hash_store3.SetHashStoreContents(CreateHashStoreContents());
scoped_ptr<PrefHashStoreTransaction> transaction(
pref_hash_store3.BeginTransaction());
EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE,
@@ -342,8 +330,8 @@ TEST_F(PrefHashStoreImplTest, EmptyAndNULLSplitDict) {
std::vector<std::string> invalid_keys;
{
- PrefHashStoreImpl pref_hash_store(
- std::string(32, 0), "device_id", CreateHashStoreContents());
+ PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true);
+ pref_hash_store.SetHashStoreContents(CreateHashStoreContents());
scoped_ptr<PrefHashStoreTransaction> transaction(
pref_hash_store.BeginTransaction());
@@ -379,8 +367,8 @@ TEST_F(PrefHashStoreImplTest, EmptyAndNULLSplitDict) {
// the hashes for path1 by setting its value to NULL (this is a regression
// test ensuring that the internal action of clearing some hashes does
// update the stored hash of hashes).
- PrefHashStoreImpl pref_hash_store2(
- std::string(32, 0), "device_id", CreateHashStoreContents());
+ PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true);
+ pref_hash_store2.SetHashStoreContents(CreateHashStoreContents());
scoped_ptr<PrefHashStoreTransaction> transaction(
pref_hash_store2.BeginTransaction());
@@ -410,8 +398,8 @@ TEST_F(PrefHashStoreImplTest, TrustedUnknownSplitValueFromExistingAtomic) {
dict.Set("c", new base::StringValue("baz"));
{
- PrefHashStoreImpl pref_hash_store(
- std::string(32, 0), "device_id", CreateHashStoreContents());
+ PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true);
+ pref_hash_store.SetHashStoreContents(CreateHashStoreContents());
scoped_ptr<PrefHashStoreTransaction> transaction(
pref_hash_store.BeginTransaction());
@@ -422,8 +410,8 @@ TEST_F(PrefHashStoreImplTest, TrustedUnknownSplitValueFromExistingAtomic) {
{
// Load a new |pref_hash_store2| in which the hashes dictionary is trusted.
- PrefHashStoreImpl pref_hash_store2(
- std::string(32, 0), "device_id", CreateHashStoreContents());
+ PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true);
+ pref_hash_store2.SetHashStoreContents(CreateHashStoreContents());
scoped_ptr<PrefHashStoreTransaction> transaction(
pref_hash_store2.BeginTransaction());
std::vector<std::string> invalid_keys;
@@ -432,80 +420,3 @@ TEST_F(PrefHashStoreImplTest, TrustedUnknownSplitValueFromExistingAtomic) {
EXPECT_TRUE(invalid_keys.empty());
}
}
-
-TEST_F(PrefHashStoreImplTest, GetCurrentVersion) {
- COMPILE_ASSERT(PrefHashStoreImpl::VERSION_LATEST == 2,
- new_versions_should_be_tested_here);
- {
- PrefHashStoreImpl pref_hash_store(
- std::string(32, 0), "device_id", CreateHashStoreContents());
-
- // VERSION_UNINITIALIZED when no hashes are stored.
- EXPECT_EQ(PrefHashStoreImpl::VERSION_UNINITIALIZED,
- pref_hash_store.GetCurrentVersion());
-
- scoped_ptr<PrefHashStoreTransaction> transaction(
- pref_hash_store.BeginTransaction());
- base::StringValue string_value("foo");
- transaction->StoreHash("path1", &string_value);
-
- // Test that |pref_hash_store| flushes its content to disk when it
- // initializes its version.
- transaction.reset();
- pref_hash_store.CommitPendingWrite();
- EXPECT_TRUE(hash_store_data_.GetCommitPerformedAndReset());
- }
- {
- PrefHashStoreImpl pref_hash_store(
- std::string(32, 0), "device_id", CreateHashStoreContents());
-
- // VERSION_LATEST after storing a hash.
- EXPECT_EQ(PrefHashStoreImpl::VERSION_LATEST,
- pref_hash_store.GetCurrentVersion());
-
- // Test that |pref_hash_store| doesn't flush its contents to disk when it
- // didn't change.
- pref_hash_store.CommitPendingWrite();
- EXPECT_FALSE(hash_store_data_.GetCommitPerformedAndReset());
- }
-
- // Manually clear the version number.
- hash_store_data_.version.reset();
-
- {
- PrefHashStoreImpl pref_hash_store(
- std::string(32, 0), "device_id", CreateHashStoreContents());
-
- // VERSION_PRE_MIGRATION when no version is stored.
- EXPECT_EQ(PrefHashStoreImpl::VERSION_PRE_MIGRATION,
- pref_hash_store.GetCurrentVersion());
-
- scoped_ptr<PrefHashStoreTransaction> transaction(
- pref_hash_store.BeginTransaction());
-
- // Test that |pref_hash_store| flushes its content to disk when it
- // re-initializes its version.
- transaction.reset();
- pref_hash_store.CommitPendingWrite();
- EXPECT_TRUE(hash_store_data_.GetCommitPerformedAndReset());
- }
- {
- PrefHashStoreImpl pref_hash_store(
- std::string(32, 0), "device_id", CreateHashStoreContents());
-
- // Back to VERSION_LATEST after performing a transaction from
- // VERSION_PRE_MIGRATION (the presence of an existing hash should be
- // sufficient, no need for the transaction itself to perform any work).
- EXPECT_EQ(PrefHashStoreImpl::VERSION_LATEST,
- pref_hash_store.GetCurrentVersion());
-
- // Test that |pref_hash_store| doesn't flush its contents to disk when it
- // didn't change (i.e., its version was already up-to-date and the only
- // transaction performed was empty).
- scoped_ptr<PrefHashStoreTransaction> transaction(
- pref_hash_store.BeginTransaction());
- transaction.reset();
- pref_hash_store.CommitPendingWrite();
- EXPECT_FALSE(hash_store_data_.GetCommitPerformedAndReset());
- }
-}

Powered by Google App Engine
This is Rietveld 408576698