const char kAtomicPref[] = "atomic_pref";
const char kAtomicPref2[] = "atomic_pref2";
const char kAtomicPref3[] = "pref3";
+const char kAtomicPref4[] = "pref4";
const char kReportOnlyPref[] = "report_only";
const char kReportOnlySplitPref[] = "report_only_split_pref";
const char kSplitPref[] = "split_pref";
5, kAtomicPref3, PrefHashFilter::ENFORCE_ON_LOAD,
PrefHashFilter::TRACKING_STRATEGY_ATOMIC
},
+ {
+ 6, kAtomicPref4, PrefHashFilter::ENFORCE_ON_LOAD,
+ PrefHashFilter::TRACKING_STRATEGY_ATOMIC
+ },
};
} // namespace
ValuePtrStrategyPair;
MockPrefHashStore() : transactions_performed_(0),
- transaction_active_(false) {}
+ transaction_active_(false),
+ commit_performed_(false) {}
virtual ~MockPrefHashStore() {
EXPECT_FALSE(transaction_active_);
// Returns the number of transactions that were performed.
size_t transactions_performed() { return transactions_performed_; }
+ // Returns true if this MockPrefHashStore's CommitPendingWrite method was
+ // called.
+ bool commit_performed() { return commit_performed_; }
+
// Returns the number of paths checked.
size_t checked_paths_count() const {
return checked_values_.size();
// PrefHashStore implementation.
virtual scoped_ptr<PrefHashStoreTransaction> BeginTransaction() OVERRIDE;
+ virtual void CommitPendingWrite() OVERRIDE;
private:
// A MockPrefHashStoreTransaction is handed to the caller on
// active at a time).
bool transaction_active_;
+ // Whether CommitPendingWrite() was called.
+ bool commit_performed_;
+
DISALLOW_COPY_AND_ASSIGN(MockPrefHashStore);
};
new MockPrefHashStoreTransaction(this));
}
+void MockPrefHashStore::CommitPendingWrite() {
+ EXPECT_FALSE(commit_performed_);
+ commit_performed_ = true;
+}
+
PrefHashStoreTransaction::ValueState MockPrefHashStore::RecordCheckValue(
const std::string& path,
const base::Value* value,
class PrefHashFilterTest
: public testing::TestWithParam<PrefHashFilter::EnforcementLevel> {
public:
- PrefHashFilterTest() : mock_pref_hash_store_(NULL) {}
+ PrefHashFilterTest() : mock_pref_hash_store_(NULL),
+ pref_store_contents_(new base::DictionaryValue),
+ last_filter_on_load_modified_prefs_(false) {}
virtual void SetUp() OVERRIDE {
// Construct a PrefHashFilter and MockPrefHashStore for the test.
}
protected:
- // Creates a PrefHashFilter that uses a MockPrefHashStore. The
- // MockPrefHashStore (owned by the PrefHashFilter) is returned in
- // |mock_pref_hash_store|.
+ // Initializes |pref_hash_filter_| with a PrefHashFilter that uses a
+ // MockPrefHashStore. The raw pointer to the MockPrefHashStore (owned by the
+ // PrefHashFilter) is stored in |mock_pref_hash_store_|.
void InitializePrefHashFilter(const std::vector<
PrefHashFilter::TrackedPreferenceMetadata>& configuration) {
scoped_ptr<MockPrefHashStore> temp_mock_pref_hash_store(
}
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_;
- base::DictionaryValue pref_store_contents_;
+ scoped_ptr<base::DictionaryValue> pref_store_contents_;
+ bool last_filter_on_load_modified_prefs_;
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) {
- pref_hash_filter_->FilterOnLoad(&pref_store_contents_);
+ DoFilterOnLoad(false);
// All paths checked.
ASSERT_EQ(arraysize(kTestTrackedPrefs),
mock_pref_hash_store_->checked_paths_count());
}
ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed());
ASSERT_FALSE(RecordedReset());
+ EXPECT_FALSE(mock_pref_hash_store_->commit_performed());
}
TEST_P(PrefHashFilterTest, FilterTrackedPrefUpdate) {
ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed());
ASSERT_FALSE(RecordedReset());
+ EXPECT_TRUE(mock_pref_hash_store_->commit_performed());
}
TEST_P(PrefHashFilterTest, FilterSplitPrefUpdate) {
ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed());
ASSERT_FALSE(RecordedReset());
+ EXPECT_TRUE(mock_pref_hash_store_->commit_performed());
}
TEST_P(PrefHashFilterTest, FilterUntrackedPrefUpdate) {
mock_pref_hash_store_->stored_value(kSplitPref);
ASSERT_EQ(dict_value, stored_value_split.first);
ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_value_split.second);
+ EXPECT_TRUE(mock_pref_hash_store_->commit_performed());
}
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);
- pref_hash_filter_->FilterOnLoad(&pref_store_contents_);
+ DoFilterOnLoad(false);
ASSERT_EQ(arraysize(kTestTrackedPrefs),
mock_pref_hash_store_->checked_paths_count());
ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count());
ASSERT_EQ(NULL, stored_split_value.first);
ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT,
stored_split_value.second);
+ EXPECT_FALSE(mock_pref_hash_store_->commit_performed());
}
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);
- pref_hash_filter_->FilterOnLoad(&pref_store_contents_);
+ // If we are enforcing, expect this to report changes.
+ DoFilterOnLoad(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD);
ASSERT_EQ(arraysize(kTestTrackedPrefs),
mock_pref_hash_store_->checked_paths_count());
ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count());
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());
// 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);
ASSERT_FALSE(RecordedReset());
}
+ EXPECT_FALSE(mock_pref_hash_store_->commit_performed());
}
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);
- pref_hash_filter_->FilterOnLoad(&pref_store_contents_);
+ DoFilterOnLoad(false);
ASSERT_EQ(arraysize(kTestTrackedPrefs),
mock_pref_hash_store_->checked_paths_count());
ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count());
// 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);
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);
ASSERT_EQ(dict_value, stored_split_value.first);
ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT,
stored_split_value.second);
+ EXPECT_FALSE(mock_pref_hash_store_->commit_performed());
}
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);
mock_invalid_keys.push_back("c");
mock_pref_hash_store_->SetInvalidKeysResult(kSplitPref, mock_invalid_keys);
- pref_hash_filter_->FilterOnLoad(&pref_store_contents_);
+ DoFilterOnLoad(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD);
ASSERT_EQ(arraysize(kTestTrackedPrefs),
mock_pref_hash_store_->checked_paths_count());
ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count());
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"));
// 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"));
ASSERT_FALSE(RecordedReset());
}
+ EXPECT_FALSE(mock_pref_hash_store_->commit_performed());
}
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);
- pref_hash_filter_->FilterOnLoad(&pref_store_contents_);
+ DoFilterOnLoad(false);
ASSERT_EQ(arraysize(kTestTrackedPrefs),
mock_pref_hash_store_->checked_paths_count());
ASSERT_EQ(2u, mock_pref_hash_store_->stored_paths_count());
// 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);
ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT,
stored_split_value.second);
+ EXPECT_FALSE(mock_pref_hash_store_->commit_performed());
}
TEST_P(PrefHashFilterTest, InitialValueMigrated) {
// 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);
- pref_hash_filter_->FilterOnLoad(&pref_store_contents_);
+
+ DoFilterOnLoad(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD);
ASSERT_EQ(arraysize(kTestTrackedPrefs),
mock_pref_hash_store_->checked_paths_count());
ASSERT_EQ(1u, mock_pref_hash_store_->stored_paths_count());
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());
// 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);
ASSERT_FALSE(RecordedReset());
}
+ EXPECT_FALSE(mock_pref_hash_store_->commit_performed());
}
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);
- pref_hash_filter_->FilterOnLoad(&pref_store_contents_);
+ DoFilterOnLoad(false);
ASSERT_EQ(arraysize(kTestTrackedPrefs),
mock_pref_hash_store_->checked_paths_count());
ASSERT_EQ(1u, mock_pref_hash_store_->transactions_performed());
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);
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);
ASSERT_FALSE(RecordedReset());
+ EXPECT_FALSE(mock_pref_hash_store_->commit_performed());
}
TEST_P(PrefHashFilterTest, DontResetReportOnly) {
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);
PrefHashStoreTransaction::CHANGED);
mock_pref_hash_store_->SetCheckResult(kReportOnlySplitPref,
PrefHashStoreTransaction::CHANGED);
- pref_hash_filter_->FilterOnLoad(&pref_store_contents_);
+
+ DoFilterOnLoad(GetParam() >= PrefHashFilter::ENFORCE_ON_LOAD);
// All prefs should be checked and a new hash should be stored for each tested
// pref.
ASSERT_EQ(arraysize(kTestTrackedPrefs),
// 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,
// 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);
} 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);
ASSERT_FALSE(RecordedReset());
}
-}
-
-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);
-
- source->SetString(kAtomicPref, "foobar");
- source->SetString(kAtomicPref2, "foobar2");
- destination->SetString(kAtomicPref2, "foobar2 preexisting");
- destination->SetString(kAtomicPref3, "foobar3");
- source->SetString(kReportOnlyPref, "helloworld");
-
- mock_pref_hash_store_->SetCheckResult(kAtomicPref,
- PrefHashStoreTransaction::UNCHANGED);
- mock_pref_hash_store_->SetCheckResult(kAtomicPref2,
- PrefHashStoreTransaction::UNCHANGED);
- mock_pref_hash_store_->SetCheckResult(kAtomicPref3,
- PrefHashStoreTransaction::UNCHANGED);
- mock_pref_hash_store_->SetCheckResult(kReportOnlyPref,
- PrefHashStoreTransaction::UNCHANGED);
-
- 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_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));
- } 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(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->GetValue(kAtomicPref3, NULL));
- ASSERT_FALSE(destination->GetValue(kReportOnlyPref, NULL));
- }
+ EXPECT_FALSE(mock_pref_hash_store_->commit_performed());
}
INSTANTIATE_TEST_CASE_P(