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

Unified Diff: trunk/src/chrome/browser/prefs/pref_hash_filter_unittest.cc

Issue 273243002: Revert 269415 "Introduce a new framework for back-and-forth trac..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 7 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: trunk/src/chrome/browser/prefs/pref_hash_filter_unittest.cc
===================================================================
--- trunk/src/chrome/browser/prefs/pref_hash_filter_unittest.cc (revision 269437)
+++ trunk/src/chrome/browser/prefs/pref_hash_filter_unittest.cc (working copy)
@@ -320,9 +320,7 @@
class PrefHashFilterTest
: public testing::TestWithParam<PrefHashFilter::EnforcementLevel> {
public:
- PrefHashFilterTest() : mock_pref_hash_store_(NULL),
- pref_store_contents_(new base::DictionaryValue),
- last_filter_on_load_modified_prefs_(false) {}
+ PrefHashFilterTest() : mock_pref_hash_store_(NULL) {}
virtual void SetUp() OVERRIDE {
// Construct a PrefHashFilter and MockPrefHashStore for the test.
@@ -345,41 +343,18 @@
}
bool RecordedReset() {
- return pref_store_contents_->Get(prefs::kPreferenceResetTime, NULL);
+ return pref_store_contents_.Get(prefs::kPreferenceResetTime, NULL);
}
- // Calls FilterOnLoad() on |pref_hash_Filter_|. |pref_store_contents_| is
- // handed off, but should be given back to us synchronously through
- // GetPrefsBack() as there is no FilterOnLoadInterceptor installed on
- // |pref_hash_filter_|.
- void DoFilterOnLoad(bool expect_prefs_modifications) {
- pref_hash_filter_->FilterOnLoad(
- base::Bind(&PrefHashFilterTest::GetPrefsBack, base::Unretained(this),
- expect_prefs_modifications),
- pref_store_contents_.Pass());
- }
-
MockPrefHashStore* mock_pref_hash_store_;
- scoped_ptr<base::DictionaryValue> pref_store_contents_;
- bool last_filter_on_load_modified_prefs_;
+ base::DictionaryValue pref_store_contents_;
scoped_ptr<PrefHashFilter> pref_hash_filter_;
- private:
- // Stores |prefs| back in |pref_store_contents| and ensure
- // |expected_schedule_write| matches the reported |schedule_write|.
- void GetPrefsBack(bool expected_schedule_write,
- scoped_ptr<base::DictionaryValue> prefs,
- bool schedule_write) {
- pref_store_contents_ = prefs.Pass();
- EXPECT_TRUE(pref_store_contents_);
- EXPECT_EQ(expected_schedule_write, schedule_write);
- }
-
DISALLOW_COPY_AND_ASSIGN(PrefHashFilterTest);
};
TEST_P(PrefHashFilterTest, EmptyAndUnchanged) {
- DoFilterOnLoad(false);
+ ASSERT_FALSE(pref_hash_filter_->FilterOnLoad(&pref_store_contents_));
// All paths checked.
ASSERT_EQ(arraysize(kTestTrackedPrefs),
mock_pref_hash_store_->checked_paths_count());
@@ -512,14 +487,14 @@
}
TEST_P(PrefHashFilterTest, EmptyAndUnknown) {
- ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL));
- ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL));
+ ASSERT_FALSE(pref_store_contents_.Get(kAtomicPref, NULL));
+ ASSERT_FALSE(pref_store_contents_.Get(kSplitPref, NULL));
// NULL values are always trusted by the PrefHashStore.
mock_pref_hash_store_->SetCheckResult(
kAtomicPref, PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE);
mock_pref_hash_store_->SetCheckResult(
kSplitPref, PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE);
- DoFilterOnLoad(false);
+ ASSERT_FALSE(pref_hash_filter_->FilterOnLoad(&pref_store_contents_));
ASSERT_EQ(arraysize(kTestTrackedPrefs),
mock_pref_hash_store_->checked_paths_count());
ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count());
@@ -542,22 +517,23 @@
TEST_P(PrefHashFilterTest, InitialValueUnknown) {
// Ownership of these values is transfered to |pref_store_contents_|.
base::StringValue* string_value = new base::StringValue("string value");
- pref_store_contents_->Set(kAtomicPref, string_value);
+ pref_store_contents_.Set(kAtomicPref, string_value);
base::DictionaryValue* dict_value = new base::DictionaryValue;
dict_value->SetString("a", "foo");
dict_value->SetInteger("b", 1234);
- pref_store_contents_->Set(kSplitPref, dict_value);
+ pref_store_contents_.Set(kSplitPref, dict_value);
- ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL));
- ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL));
+ ASSERT_TRUE(pref_store_contents_.Get(kAtomicPref, NULL));
+ ASSERT_TRUE(pref_store_contents_.Get(kSplitPref, NULL));
mock_pref_hash_store_->SetCheckResult(
kAtomicPref, PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE);
mock_pref_hash_store_->SetCheckResult(
kSplitPref, PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE);
// If we are enforcing, expect this to report changes.
- DoFilterOnLoad(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD);
+ ASSERT_EQ(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD,
+ pref_hash_filter_->FilterOnLoad(&pref_store_contents_));
ASSERT_EQ(arraysize(kTestTrackedPrefs),
mock_pref_hash_store_->checked_paths_count());
ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count());
@@ -574,10 +550,10 @@
if (GetParam() == PrefHashFilter::ENFORCE_ON_LOAD) {
// Ensure the prefs were cleared and the hashes for NULL were restored if
// the current enforcement level denies seeding.
- ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL));
+ ASSERT_FALSE(pref_store_contents_.Get(kAtomicPref, NULL));
ASSERT_EQ(NULL, stored_atomic_value.first);
- ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL));
+ ASSERT_FALSE(pref_store_contents_.Get(kSplitPref, NULL));
ASSERT_EQ(NULL, stored_split_value.first);
ASSERT_TRUE(RecordedReset());
@@ -585,12 +561,12 @@
// Otherwise the values should have remained intact and the hashes should
// have been updated to match them.
const base::Value* atomic_value_in_store;
- ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, &atomic_value_in_store));
+ ASSERT_TRUE(pref_store_contents_.Get(kAtomicPref, &atomic_value_in_store));
ASSERT_EQ(string_value, atomic_value_in_store);
ASSERT_EQ(string_value, stored_atomic_value.first);
const base::Value* split_value_in_store;
- ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store));
+ ASSERT_TRUE(pref_store_contents_.Get(kSplitPref, &split_value_in_store));
ASSERT_EQ(dict_value, split_value_in_store);
ASSERT_EQ(dict_value, stored_split_value.first);
@@ -602,21 +578,21 @@
TEST_P(PrefHashFilterTest, InitialValueTrustedUnknown) {
// Ownership of this value is transfered to |pref_store_contents_|.
base::Value* string_value = base::Value::CreateStringValue("test");
- pref_store_contents_->Set(kAtomicPref, string_value);
+ pref_store_contents_.Set(kAtomicPref, string_value);
base::DictionaryValue* dict_value = new base::DictionaryValue;
dict_value->SetString("a", "foo");
dict_value->SetInteger("b", 1234);
- pref_store_contents_->Set(kSplitPref, dict_value);
+ pref_store_contents_.Set(kSplitPref, dict_value);
- ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL));
- ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL));
+ ASSERT_TRUE(pref_store_contents_.Get(kAtomicPref, NULL));
+ ASSERT_TRUE(pref_store_contents_.Get(kSplitPref, NULL));
mock_pref_hash_store_->SetCheckResult(
kAtomicPref, PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE);
mock_pref_hash_store_->SetCheckResult(
kSplitPref, PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE);
- DoFilterOnLoad(false);
+ ASSERT_FALSE(pref_hash_filter_->FilterOnLoad(&pref_store_contents_));
ASSERT_EQ(arraysize(kTestTrackedPrefs),
mock_pref_hash_store_->checked_paths_count());
ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count());
@@ -624,7 +600,7 @@
// Seeding is always allowed for trusted unknown values.
const base::Value* atomic_value_in_store;
- ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, &atomic_value_in_store));
+ ASSERT_TRUE(pref_store_contents_.Get(kAtomicPref, &atomic_value_in_store));
ASSERT_EQ(string_value, atomic_value_in_store);
MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value =
mock_pref_hash_store_->stored_value(kAtomicPref);
@@ -633,7 +609,7 @@
stored_atomic_value.second);
const base::Value* split_value_in_store;
- ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store));
+ ASSERT_TRUE(pref_store_contents_.Get(kSplitPref, &split_value_in_store));
ASSERT_EQ(dict_value, split_value_in_store);
MockPrefHashStore::ValuePtrStrategyPair stored_split_value =
mock_pref_hash_store_->stored_value(kSplitPref);
@@ -646,17 +622,17 @@
TEST_P(PrefHashFilterTest, InitialValueChanged) {
// Ownership of this value is transfered to |pref_store_contents_|.
base::Value* int_value = base::Value::CreateIntegerValue(1234);
- pref_store_contents_->Set(kAtomicPref, int_value);
+ pref_store_contents_.Set(kAtomicPref, int_value);
base::DictionaryValue* dict_value = new base::DictionaryValue;
dict_value->SetString("a", "foo");
dict_value->SetInteger("b", 1234);
dict_value->SetInteger("c", 56);
dict_value->SetBoolean("d", false);
- pref_store_contents_->Set(kSplitPref, dict_value);
+ pref_store_contents_.Set(kSplitPref, dict_value);
- ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL));
- ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL));
+ ASSERT_TRUE(pref_store_contents_.Get(kAtomicPref, NULL));
+ ASSERT_TRUE(pref_store_contents_.Get(kSplitPref, NULL));
mock_pref_hash_store_->SetCheckResult(kAtomicPref,
PrefHashStoreTransaction::CHANGED);
@@ -668,7 +644,8 @@
mock_invalid_keys.push_back("c");
mock_pref_hash_store_->SetInvalidKeysResult(kSplitPref, mock_invalid_keys);
- DoFilterOnLoad(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD);
+ ASSERT_EQ(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD,
+ pref_hash_filter_->FilterOnLoad(&pref_store_contents_));
ASSERT_EQ(arraysize(kTestTrackedPrefs),
mock_pref_hash_store_->checked_paths_count());
ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count());
@@ -685,13 +662,13 @@
if (GetParam() == PrefHashFilter::ENFORCE_ON_LOAD) {
// Ensure the atomic pref was cleared and the hash for NULL was restored if
// the current enforcement level prevents changes.
- ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL));
+ ASSERT_FALSE(pref_store_contents_.Get(kAtomicPref, NULL));
ASSERT_EQ(NULL, stored_atomic_value.first);
// The split pref on the other hand should only have been stripped of its
// invalid keys.
const base::Value* split_value_in_store;
- ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store));
+ ASSERT_TRUE(pref_store_contents_.Get(kSplitPref, &split_value_in_store));
ASSERT_EQ(2U, dict_value->size());
ASSERT_FALSE(dict_value->HasKey("a"));
ASSERT_TRUE(dict_value->HasKey("b"));
@@ -704,12 +681,12 @@
// Otherwise the value should have remained intact and the hash should have
// been updated to match it.
const base::Value* atomic_value_in_store;
- ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, &atomic_value_in_store));
+ ASSERT_TRUE(pref_store_contents_.Get(kAtomicPref, &atomic_value_in_store));
ASSERT_EQ(int_value, atomic_value_in_store);
ASSERT_EQ(int_value, stored_atomic_value.first);
const base::Value* split_value_in_store;
- ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store));
+ ASSERT_TRUE(pref_store_contents_.Get(kSplitPref, &split_value_in_store));
ASSERT_EQ(dict_value, split_value_in_store);
ASSERT_EQ(4U, dict_value->size());
ASSERT_TRUE(dict_value->HasKey("a"));
@@ -724,13 +701,13 @@
}
TEST_P(PrefHashFilterTest, EmptyCleared) {
- ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL));
- ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL));
+ ASSERT_FALSE(pref_store_contents_.Get(kAtomicPref, NULL));
+ ASSERT_FALSE(pref_store_contents_.Get(kSplitPref, NULL));
mock_pref_hash_store_->SetCheckResult(kAtomicPref,
PrefHashStoreTransaction::CLEARED);
mock_pref_hash_store_->SetCheckResult(kSplitPref,
PrefHashStoreTransaction::CLEARED);
- DoFilterOnLoad(false);
+ ASSERT_FALSE(pref_hash_filter_->FilterOnLoad(&pref_store_contents_));
ASSERT_EQ(arraysize(kTestTrackedPrefs),
mock_pref_hash_store_->checked_paths_count());
ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count());
@@ -738,14 +715,14 @@
// Regardless of the enforcement level, the only thing that should be done is
// to restore the hash for NULL. The value itself should still be NULL.
- ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL));
+ ASSERT_FALSE(pref_store_contents_.Get(kAtomicPref, NULL));
MockPrefHashStore::ValuePtrStrategyPair stored_atomic_value =
mock_pref_hash_store_->stored_value(kAtomicPref);
ASSERT_EQ(NULL, stored_atomic_value.first);
ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC,
stored_atomic_value.second);
- ASSERT_FALSE(pref_store_contents_->Get(kSplitPref, NULL));
+ ASSERT_FALSE(pref_store_contents_.Get(kSplitPref, NULL));
MockPrefHashStore::ValuePtrStrategyPair stored_split_value =
mock_pref_hash_store_->stored_value(kSplitPref);
ASSERT_EQ(NULL, stored_split_value.first);
@@ -760,14 +737,15 @@
// Ownership of this value is transfered to |pref_store_contents_|.
base::ListValue* list_value = new base::ListValue;
list_value->Append(base::Value::CreateStringValue("test"));
- pref_store_contents_->Set(kAtomicPref, list_value);
+ pref_store_contents_.Set(kAtomicPref, list_value);
- ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL));
+ ASSERT_TRUE(pref_store_contents_.Get(kAtomicPref, NULL));
mock_pref_hash_store_->SetCheckResult(kAtomicPref,
PrefHashStoreTransaction::WEAK_LEGACY);
- DoFilterOnLoad(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD);
+ ASSERT_EQ(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD,
+ pref_hash_filter_->FilterOnLoad(&pref_store_contents_));
ASSERT_EQ(arraysize(kTestTrackedPrefs),
mock_pref_hash_store_->checked_paths_count());
ASSERT_EQ(1u, mock_pref_hash_store_->stored_paths_count());
@@ -780,7 +758,7 @@
if (GetParam() == PrefHashFilter::ENFORCE_ON_LOAD) {
// Ensure the pref was cleared and the hash for NULL was restored if the
// current enforcement level prevents migration.
- ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL));
+ ASSERT_FALSE(pref_store_contents_.Get(kAtomicPref, NULL));
ASSERT_EQ(NULL, stored_atomic_value.first);
ASSERT_TRUE(RecordedReset());
@@ -788,7 +766,7 @@
// Otherwise the value should have remained intact and the hash should have
// been updated to match it.
const base::Value* atomic_value_in_store;
- ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, &atomic_value_in_store));
+ ASSERT_TRUE(pref_store_contents_.Get(kAtomicPref, &atomic_value_in_store));
ASSERT_EQ(list_value, atomic_value_in_store);
ASSERT_EQ(list_value, stored_atomic_value.first);
@@ -800,21 +778,21 @@
TEST_P(PrefHashFilterTest, InitialValueUnchangedLegacyId) {
// Ownership of these values is transfered to |pref_store_contents_|.
base::StringValue* string_value = new base::StringValue("string value");
- pref_store_contents_->Set(kAtomicPref, string_value);
+ pref_store_contents_.Set(kAtomicPref, string_value);
base::DictionaryValue* dict_value = new base::DictionaryValue;
dict_value->SetString("a", "foo");
dict_value->SetInteger("b", 1234);
- pref_store_contents_->Set(kSplitPref, dict_value);
+ pref_store_contents_.Set(kSplitPref, dict_value);
- ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL));
- ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, NULL));
+ ASSERT_TRUE(pref_store_contents_.Get(kAtomicPref, NULL));
+ ASSERT_TRUE(pref_store_contents_.Get(kSplitPref, NULL));
mock_pref_hash_store_->SetCheckResult(
kAtomicPref, PrefHashStoreTransaction::SECURE_LEGACY);
mock_pref_hash_store_->SetCheckResult(
kSplitPref, PrefHashStoreTransaction::SECURE_LEGACY);
- DoFilterOnLoad(false);
+ ASSERT_FALSE(pref_hash_filter_->FilterOnLoad(&pref_store_contents_));
ASSERT_EQ(arraysize(kTestTrackedPrefs),
mock_pref_hash_store_->checked_paths_count());
ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed());
@@ -830,7 +808,7 @@
ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC,
stored_atomic_value.second);
const base::Value* atomic_value_in_store;
- ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, &atomic_value_in_store));
+ ASSERT_TRUE(pref_store_contents_.Get(kAtomicPref, &atomic_value_in_store));
ASSERT_EQ(string_value, atomic_value_in_store);
ASSERT_EQ(string_value, stored_atomic_value.first);
@@ -839,7 +817,7 @@
ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT,
stored_split_value.second);
const base::Value* split_value_in_store;
- ASSERT_TRUE(pref_store_contents_->Get(kSplitPref, &split_value_in_store));
+ ASSERT_TRUE(pref_store_contents_.Get(kSplitPref, &split_value_in_store));
ASSERT_EQ(dict_value, split_value_in_store);
ASSERT_EQ(dict_value, stored_split_value.first);
@@ -854,15 +832,15 @@
base::Value* report_only_val = base::Value::CreateIntegerValue(3);
base::DictionaryValue* report_only_split_val = new base::DictionaryValue;
report_only_split_val->SetInteger("a", 1234);
- pref_store_contents_->Set(kAtomicPref, int_value1);
- pref_store_contents_->Set(kAtomicPref2, int_value2);
- pref_store_contents_->Set(kReportOnlyPref, report_only_val);
- pref_store_contents_->Set(kReportOnlySplitPref, report_only_split_val);
+ pref_store_contents_.Set(kAtomicPref, int_value1);
+ pref_store_contents_.Set(kAtomicPref2, int_value2);
+ pref_store_contents_.Set(kReportOnlyPref, report_only_val);
+ pref_store_contents_.Set(kReportOnlySplitPref, report_only_split_val);
- ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, NULL));
- ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref2, NULL));
- ASSERT_TRUE(pref_store_contents_->Get(kReportOnlyPref, NULL));
- ASSERT_TRUE(pref_store_contents_->Get(kReportOnlySplitPref, NULL));
+ ASSERT_TRUE(pref_store_contents_.Get(kAtomicPref, NULL));
+ ASSERT_TRUE(pref_store_contents_.Get(kAtomicPref2, NULL));
+ ASSERT_TRUE(pref_store_contents_.Get(kReportOnlyPref, NULL));
+ ASSERT_TRUE(pref_store_contents_.Get(kReportOnlySplitPref, NULL));
mock_pref_hash_store_->SetCheckResult(kAtomicPref,
PrefHashStoreTransaction::CHANGED);
@@ -873,7 +851,8 @@
mock_pref_hash_store_->SetCheckResult(kReportOnlySplitPref,
PrefHashStoreTransaction::CHANGED);
- DoFilterOnLoad(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD);
+ ASSERT_EQ(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD,
+ pref_hash_filter_->FilterOnLoad(&pref_store_contents_));
// All prefs should be checked and a new hash should be stored for each tested
// pref.
ASSERT_EQ(arraysize(kTestTrackedPrefs),
@@ -883,8 +862,8 @@
// No matter what the enforcement level is, the report only pref should never
// be reset.
- ASSERT_TRUE(pref_store_contents_->Get(kReportOnlyPref, NULL));
- ASSERT_TRUE(pref_store_contents_->Get(kReportOnlySplitPref, NULL));
+ ASSERT_TRUE(pref_store_contents_.Get(kReportOnlyPref, NULL));
+ ASSERT_TRUE(pref_store_contents_.Get(kReportOnlySplitPref, NULL));
ASSERT_EQ(report_only_val,
mock_pref_hash_store_->stored_value(kReportOnlyPref).first);
ASSERT_EQ(report_only_split_val,
@@ -892,8 +871,8 @@
// All other prefs should have been reset if the enforcement level allows it.
if (GetParam() == PrefHashFilter::ENFORCE_ON_LOAD) {
- ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref, NULL));
- ASSERT_FALSE(pref_store_contents_->Get(kAtomicPref2, NULL));
+ ASSERT_FALSE(pref_store_contents_.Get(kAtomicPref, NULL));
+ ASSERT_FALSE(pref_store_contents_.Get(kAtomicPref2, NULL));
ASSERT_EQ(NULL, mock_pref_hash_store_->stored_value(kAtomicPref).first);
ASSERT_EQ(NULL, mock_pref_hash_store_->stored_value(kAtomicPref2).first);
@@ -901,8 +880,8 @@
} else {
const base::Value* value_in_store;
const base::Value* value_in_store2;
- ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref, &value_in_store));
- ASSERT_TRUE(pref_store_contents_->Get(kAtomicPref2, &value_in_store2));
+ ASSERT_TRUE(pref_store_contents_.Get(kAtomicPref, &value_in_store));
+ ASSERT_TRUE(pref_store_contents_.Get(kAtomicPref2, &value_in_store2));
ASSERT_EQ(int_value1, value_in_store);
ASSERT_EQ(int_value1,
mock_pref_hash_store_->stored_value(kAtomicPref).first);
@@ -915,6 +894,103 @@
EXPECT_FALSE(mock_pref_hash_store_->commit_performed());
}
+TEST_P(PrefHashFilterTest, MigrateValuesTest) {
+ // Migration configuration should only contain the protected preferences.
+ std::vector<PrefHashFilter::TrackedPreferenceMetadata> configuration =
+ GetConfiguration(GetParam());
+ std::vector<PrefHashFilter::TrackedPreferenceMetadata>
+ migration_configuration;
+
+ for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it =
+ configuration.begin();
+ it != configuration.end();
+ ++it) {
+ if (it->enforcement_level >= PrefHashFilter::ENFORCE_ON_LOAD)
+ migration_configuration.push_back(*it);
+ }
+
+ // Discards the default created pref_hash_filter_.
+ InitializePrefHashFilter(migration_configuration);
+
+ scoped_refptr<TestingPrefStore> source(new TestingPrefStore);
+ scoped_refptr<TestingPrefStore> destination(new TestingPrefStore);
+
+ // If enforcing, should be migrated.
+ source->SetString(kAtomicPref, "foobar");
+ mock_pref_hash_store_->SetCheckResult(kAtomicPref,
+ PrefHashStoreTransaction::UNCHANGED);
+
+ // If enforcing, should be discarded due to pre-existing value in
+ // |destination|.
+ source->SetString(kAtomicPref2, "foobar2");
+ mock_pref_hash_store_->SetCheckResult(kAtomicPref2,
+ PrefHashStoreTransaction::UNCHANGED);
+
+ // If enforcing, should be kept preferentially to value from |source|. If not
+ // enforcing, should still be unaffected.
+ destination->SetString(kAtomicPref2, "foobar2 preexisting");
+ // Should stay in |destination| in both scenarios.
+ destination->SetString(kAtomicPref3, "foobar3");
+ mock_pref_hash_store_->SetCheckResult(kAtomicPref3,
+ PrefHashStoreTransaction::UNCHANGED);
+
+ // When enforcing, should be discarded due to MAC mismatch. If not enforcing,
+ // stays in |source|.
+ source->SetString(kAtomicPref4, "foobar4");
+ mock_pref_hash_store_->SetCheckResult(kAtomicPref4,
+ PrefHashStoreTransaction::CHANGED);
+
+ // Should remain in |source| in both scenarios.
+ source->SetString(kReportOnlyPref, "helloworld");
+ mock_pref_hash_store_->SetCheckResult(kReportOnlyPref,
+ PrefHashStoreTransaction::UNCHANGED);
+
+ // Perform the migration.
+ pref_hash_filter_->MigrateValues(source, destination);
+ ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed());
+
+ if (GetParam() == PrefHashFilter::ENFORCE_ON_LOAD) {
+ std::string value;
+
+ ASSERT_FALSE(source->GetValue(kAtomicPref, NULL));
+ ASSERT_FALSE(source->GetValue(kAtomicPref2, NULL));
+ ASSERT_FALSE(source->GetValue(kAtomicPref3, NULL));
+ ASSERT_FALSE(source->GetValue(kAtomicPref4, NULL));
+ ASSERT_TRUE(source->GetString(kReportOnlyPref, &value));
+ ASSERT_EQ("helloworld", value);
+
+ ASSERT_TRUE(destination->GetString(kAtomicPref, &value));
+ ASSERT_EQ("foobar", value);
+ ASSERT_TRUE(destination->GetString(kAtomicPref2, &value));
+ ASSERT_EQ("foobar2 preexisting", value);
+ ASSERT_TRUE(destination->GetString(kAtomicPref3, &value));
+ ASSERT_EQ("foobar3", value);
+ ASSERT_FALSE(destination->GetValue(kReportOnlyPref, NULL));
+ ASSERT_FALSE(destination->GetValue(kAtomicPref4, NULL));
+ } else {
+ std::string value;
+
+ ASSERT_TRUE(source->GetString(kAtomicPref, &value));
+ ASSERT_EQ("foobar", value);
+ ASSERT_TRUE(source->GetString(kAtomicPref2, &value));
+ ASSERT_EQ("foobar2", value);
+ ASSERT_FALSE(source->GetString(kAtomicPref3, &value));
+ ASSERT_TRUE(source->GetString(kAtomicPref4, &value));
+ ASSERT_EQ("foobar4", value);
+ ASSERT_TRUE(source->GetString(kReportOnlyPref, &value));
+ ASSERT_EQ("helloworld", value);
+
+ ASSERT_FALSE(destination->GetValue(kAtomicPref, NULL));
+ ASSERT_TRUE(destination->GetString(kAtomicPref2, &value));
+ ASSERT_EQ("foobar2 preexisting", value);
+ ASSERT_TRUE(destination->GetString(kAtomicPref3, &value));
+ ASSERT_EQ("foobar3", value);
+ ASSERT_FALSE(destination->GetValue(kAtomicPref4, NULL));
+ ASSERT_FALSE(destination->GetValue(kReportOnlyPref, NULL));
+ }
+ EXPECT_FALSE(mock_pref_hash_store_->commit_performed());
+}
+
INSTANTIATE_TEST_CASE_P(
PrefHashFilterTestInstance, PrefHashFilterTest,
testing::Values(PrefHashFilter::NO_ENFORCEMENT,
« no previous file with comments | « trunk/src/chrome/browser/prefs/pref_hash_filter.cc ('k') | trunk/src/chrome/browser/prefs/profile_pref_store_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698