summaryrefslogtreecommitdiff
path: root/chromium/components/user_prefs
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-04-05 17:15:33 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-04-11 07:47:18 +0000
commit7324afb043a0b1e623d8e8eb906cdc53bdeb4685 (patch)
treea3fe2d74ea9c9e142c390dac4ca0e219382ace46 /chromium/components/user_prefs
parent6a4cabb866f66d4128a97cdc6d9d08ce074f1247 (diff)
downloadqtwebengine-chromium-7324afb043a0b1e623d8e8eb906cdc53bdeb4685.tar.gz
BASELINE: Update Chromium to 58.0.3029.54
Change-Id: I67f57065a7afdc8e4614adb5c0230281428df4d1 Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Diffstat (limited to 'chromium/components/user_prefs')
-rw-r--r--chromium/components/user_prefs/tracked/pref_hash_calculator.cc21
-rw-r--r--chromium/components/user_prefs/tracked/pref_hash_calculator.h11
-rw-r--r--chromium/components/user_prefs/tracked/pref_hash_calculator_unittest.cc62
-rw-r--r--chromium/components/user_prefs/tracked/pref_hash_filter_unittest.cc30
-rw-r--r--chromium/components/user_prefs/tracked/pref_hash_store_impl.cc36
-rw-r--r--chromium/components/user_prefs/tracked/pref_hash_store_impl.h6
-rw-r--r--chromium/components/user_prefs/tracked/registry_hash_store_contents_win_unittest.cc3
-rw-r--r--chromium/components/user_prefs/tracked/segregated_pref_store.cc14
-rw-r--r--chromium/components/user_prefs/tracked/segregated_pref_store.h1
-rw-r--r--chromium/components/user_prefs/tracked/segregated_pref_store_unittest.cc30
10 files changed, 134 insertions, 80 deletions
diff --git a/chromium/components/user_prefs/tracked/pref_hash_calculator.cc b/chromium/components/user_prefs/tracked/pref_hash_calculator.cc
index 12fb03d8fe8..8d73c1dcbc9 100644
--- a/chromium/components/user_prefs/tracked/pref_hash_calculator.cc
+++ b/chromium/components/user_prefs/tracked/pref_hash_calculator.cc
@@ -79,27 +79,12 @@ std::string GetMessage(const std::string& device_id,
return message;
}
-// Generates a device ID based on the input device ID. The derived device ID has
-// no useful properties beyond those of the input device ID except that it is
-// consistent with previous implementations.
-// TODO(gab): Remove this once UMA reports for
-// Settings.TrackedPreferenceMigratedLegacyDeviceId become insignificant.
-std::string GenerateDeviceIdLikePrefMetricsServiceDid(
- const std::string& original_device_id) {
- if (original_device_id.empty())
- return std::string();
- return base::ToLowerASCII(
- GetDigestString(original_device_id, "PrefMetricsService"));
-}
-
} // namespace
PrefHashCalculator::PrefHashCalculator(const std::string& seed,
- const std::string& device_id)
- : seed_(seed),
- device_id_(device_id),
- legacy_device_id_(GenerateDeviceIdLikePrefMetricsServiceDid(device_id)) {
-}
+ const std::string& device_id,
+ const std::string& legacy_device_id)
+ : seed_(seed), device_id_(device_id), legacy_device_id_(legacy_device_id) {}
PrefHashCalculator::~PrefHashCalculator() {
}
diff --git a/chromium/components/user_prefs/tracked/pref_hash_calculator.h b/chromium/components/user_prefs/tracked/pref_hash_calculator.h
index 1f9b74f0ad7..92b0c3a05d9 100644
--- a/chromium/components/user_prefs/tracked/pref_hash_calculator.h
+++ b/chromium/components/user_prefs/tracked/pref_hash_calculator.h
@@ -23,10 +23,13 @@ class PrefHashCalculator {
VALID_SECURE_LEGACY,
};
- // Constructs a PrefHashCalculator using |seed| and |device_id|. The same
- // parameters must be used in order to successfully validate generated hashes.
- // |device_id| may be empty.
- PrefHashCalculator(const std::string& seed, const std::string& device_id);
+ // Constructs a PrefHashCalculator using |seed|, |device_id| and
+ // |legacy_device_id|. The same parameters must be used in order to
+ // successfully validate generated hashes. |_device_id| or |legacy_device_id|
+ // may be empty.
+ PrefHashCalculator(const std::string& seed,
+ const std::string& device_id,
+ const std::string& legacy_device_id);
~PrefHashCalculator();
diff --git a/chromium/components/user_prefs/tracked/pref_hash_calculator_unittest.cc b/chromium/components/user_prefs/tracked/pref_hash_calculator_unittest.cc
index 4d29146ada9..11e38f1d76d 100644
--- a/chromium/components/user_prefs/tracked/pref_hash_calculator_unittest.cc
+++ b/chromium/components/user_prefs/tracked/pref_hash_calculator_unittest.cc
@@ -24,10 +24,10 @@ TEST(PrefHashCalculatorTest, TestCurrentAlgorithm) {
base::DictionaryValue dictionary_value_2;
dictionary_value_2.SetInteger("int value", 2);
- PrefHashCalculator calc1("seed1", "deviceid");
- PrefHashCalculator calc1_dup("seed1", "deviceid");
- PrefHashCalculator calc2("seed2", "deviceid");
- PrefHashCalculator calc3("seed1", "deviceid2");
+ PrefHashCalculator calc1("seed1", "deviceid", "legacydeviceid");
+ PrefHashCalculator calc1_dup("seed1", "deviceid", "legacydeviceid");
+ PrefHashCalculator calc2("seed2", "deviceid", "legacydeviceid");
+ PrefHashCalculator calc3("seed1", "deviceid2", "legacydeviceid");
// Two calculators with same seed produce same hash.
ASSERT_EQ(calc1.Calculate("pref_path", &string_value_1),
@@ -77,11 +77,9 @@ TEST(PrefHashCalculatorTest, CatchHashChanges) {
static const char kDeviceId[] = "test_device_id1";
std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue();
- std::unique_ptr<base::Value> bool_value(new base::FundamentalValue(false));
- std::unique_ptr<base::Value> int_value(
- new base::FundamentalValue(1234567890));
- std::unique_ptr<base::Value> double_value(
- new base::FundamentalValue(123.0987654321));
+ std::unique_ptr<base::Value> bool_value(new base::Value(false));
+ std::unique_ptr<base::Value> int_value(new base::Value(1234567890));
+ std::unique_ptr<base::Value> double_value(new base::Value(123.0987654321));
std::unique_ptr<base::Value> string_value(
new base::StringValue("testing with special chars:\n<>{}:^^@#$\\/"));
@@ -124,46 +122,46 @@ TEST(PrefHashCalculatorTest, CatchHashChanges) {
static const char kExpectedNullValue[] =
"82A9F3BBC7F9FF84C76B033C854E79EEB162783FA7B3E99FF9372FA8E12C44F7";
EXPECT_EQ(PrefHashCalculator::VALID,
- PrefHashCalculator(kSeed, kDeviceId)
+ PrefHashCalculator(kSeed, kDeviceId, "legacydeviceid")
.Validate("pref.path", null_value.get(), kExpectedNullValue));
static const char kExpectedBooleanValue[] =
"A520D8F43EA307B0063736DC9358C330539D0A29417580514C8B9862632C4CCC";
EXPECT_EQ(
PrefHashCalculator::VALID,
- PrefHashCalculator(kSeed, kDeviceId)
+ PrefHashCalculator(kSeed, kDeviceId, "legacydeviceid")
.Validate("pref.path", bool_value.get(), kExpectedBooleanValue));
static const char kExpectedIntegerValue[] =
"8D60DA1F10BF5AA29819D2D66D7CCEF9AABC5DA93C11A0D2BD21078D63D83682";
EXPECT_EQ(PrefHashCalculator::VALID,
- PrefHashCalculator(kSeed, kDeviceId)
+ PrefHashCalculator(kSeed, kDeviceId, "legacydeviceid")
.Validate("pref.path", int_value.get(), kExpectedIntegerValue));
static const char kExpectedDoubleValue[] =
"C9D94772516125BEEDAE68C109D44BC529E719EE020614E894CC7FB4098C545D";
EXPECT_EQ(
PrefHashCalculator::VALID,
- PrefHashCalculator(kSeed, kDeviceId)
+ PrefHashCalculator(kSeed, kDeviceId, "legacydeviceid")
.Validate("pref.path", double_value.get(), kExpectedDoubleValue));
static const char kExpectedStringValue[] =
"05ACCBD3B05C45C36CD06190F63EC577112311929D8380E26E5F13182EB68318";
EXPECT_EQ(
PrefHashCalculator::VALID,
- PrefHashCalculator(kSeed, kDeviceId)
+ PrefHashCalculator(kSeed, kDeviceId, "legacydeviceid")
.Validate("pref.path", string_value.get(), kExpectedStringValue));
static const char kExpectedDictValue[] =
"7A84DCC710D796C771F789A4DA82C952095AA956B6F1667EE42D0A19ECAA3C4A";
EXPECT_EQ(PrefHashCalculator::VALID,
- PrefHashCalculator(kSeed, kDeviceId)
+ PrefHashCalculator(kSeed, kDeviceId, "legacydeviceid")
.Validate("pref.path", dict_value.get(), kExpectedDictValue));
static const char kExpectedListValue[] =
"8D5A25972DF5AE20D041C780E7CA54E40F614AD53513A0724EE8D62D4F992740";
EXPECT_EQ(PrefHashCalculator::VALID,
- PrefHashCalculator(kSeed, kDeviceId)
+ PrefHashCalculator(kSeed, kDeviceId, "legacydeviceid")
.Validate("pref.path", list_value.get(), kExpectedListValue));
// Also test every value type together in the same dictionary.
@@ -178,28 +176,22 @@ TEST(PrefHashCalculatorTest, CatchHashChanges) {
static const char kExpectedEverythingValue[] =
"B97D09BE7005693574DCBDD03D8D9E44FB51F4008B73FB56A49A9FA671A1999B";
EXPECT_EQ(PrefHashCalculator::VALID,
- PrefHashCalculator(kSeed, kDeviceId)
+ PrefHashCalculator(kSeed, kDeviceId, "legacydeviceid")
.Validate("pref.path", &everything, kExpectedEverythingValue));
}
-TEST(PrefHashCalculatorTest, TestCompatibilityWithLegacyPrefMetricsServiceId) {
- static const char kSeed[] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
- 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
- 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00,
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
- 0x0C, 0x0D, 0x0E, 0x0F, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
- 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
- static const char kDeviceId[] =
- "D730D9CBD98C734A4FB097A1922275FE9F7E026A4EA1BE0E84";
- static const char kExpectedValue[] =
- "845EF34663FF8D32BE6707F40258FBA531C2BFC532E3B014AFB3476115C2A9DE";
+TEST(PrefHashCalculatorTest, TestCompatibilityWithLegacyDeviceId) {
+ static const char kSeed[] = "0123456789ABCDEF0123456789ABCDEF";
+ static const char kNewDeviceId[] = "new_test_device_id1";
+ static const char kLegacyDeviceId[] = "test_device_id1";
- base::ListValue startup_urls;
- startup_urls.Set(0, new base::StringValue("http://www.chromium.org/"));
+ // As in PrefHashCalculatorTest.CatchHashChanges.
+ const base::StringValue string_value(
+ "testing with special chars:\n<>{}:^^@#$\\/");
+ static const char kExpectedValue[] =
+ "05ACCBD3B05C45C36CD06190F63EC577112311929D8380E26E5F13182EB68318";
- EXPECT_EQ(
- PrefHashCalculator::VALID_SECURE_LEGACY,
- PrefHashCalculator(std::string(kSeed, arraysize(kSeed)), kDeviceId)
- .Validate("session.startup_urls", &startup_urls, kExpectedValue));
+ EXPECT_EQ(PrefHashCalculator::VALID_SECURE_LEGACY,
+ PrefHashCalculator(kSeed, kNewDeviceId, kLegacyDeviceId)
+ .Validate("pref.path", &string_value, kExpectedValue));
}
diff --git a/chromium/components/user_prefs/tracked/pref_hash_filter_unittest.cc b/chromium/components/user_prefs/tracked/pref_hash_filter_unittest.cc
index 1d3afd4b9fc..42ea4f5092a 100644
--- a/chromium/components/user_prefs/tracked/pref_hash_filter_unittest.cc
+++ b/chromium/components/user_prefs/tracked/pref_hash_filter_unittest.cc
@@ -802,12 +802,12 @@ TEST_P(PrefHashFilterTest, FilterUntrackedPrefUpdate) {
TEST_P(PrefHashFilterTest, MultiplePrefsFilterSerializeData) {
base::DictionaryValue root_dict;
// Ownership of the following values is transfered to |root_dict|.
- base::Value* int_value1 = new base::FundamentalValue(1);
- base::Value* int_value2 = new base::FundamentalValue(2);
- base::Value* int_value3 = new base::FundamentalValue(3);
- base::Value* int_value4 = new base::FundamentalValue(4);
+ base::Value* int_value1 = new base::Value(1);
+ base::Value* int_value2 = new base::Value(2);
+ base::Value* int_value3 = new base::Value(3);
+ base::Value* int_value4 = new base::Value(4);
base::DictionaryValue* dict_value = new base::DictionaryValue;
- dict_value->Set("a", new base::FundamentalValue(true));
+ dict_value->Set("a", new base::Value(true));
root_dict.Set(kAtomicPref, int_value1);
root_dict.Set(kAtomicPref2, int_value2);
root_dict.Set(kAtomicPref3, int_value3);
@@ -821,7 +821,7 @@ TEST_P(PrefHashFilterTest, MultiplePrefsFilterSerializeData) {
ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count());
// Update kAtomicPref3 again, nothing should be stored still.
- base::Value* int_value5 = new base::FundamentalValue(5);
+ base::Value* int_value5 = new base::Value(5);
root_dict.Set(kAtomicPref3, int_value5);
ASSERT_EQ(0u, mock_pref_hash_store_->stored_paths_count());
@@ -1014,7 +1014,7 @@ TEST_P(PrefHashFilterTest, InitialValueTrustedUnknown) {
TEST_P(PrefHashFilterTest, InitialValueChanged) {
// Ownership of this value is transfered to |pref_store_contents_|.
- base::Value* int_value = new base::FundamentalValue(1234);
+ base::Value* int_value = new base::Value(1234);
pref_store_contents_->Set(kAtomicPref, int_value);
base::DictionaryValue* dict_value = new base::DictionaryValue;
@@ -1187,9 +1187,9 @@ TEST_P(PrefHashFilterTest, InitialValueUnchangedLegacyId) {
TEST_P(PrefHashFilterTest, DontResetReportOnly) {
// Ownership of these values is transfered to |pref_store_contents_|.
- base::Value* int_value1 = new base::FundamentalValue(1);
- base::Value* int_value2 = new base::FundamentalValue(2);
- base::Value* report_only_val = new base::FundamentalValue(3);
+ base::Value* int_value1 = new base::Value(1);
+ base::Value* int_value2 = new base::Value(2);
+ base::Value* report_only_val = new base::Value(3);
base::DictionaryValue* report_only_split_val = new base::DictionaryValue;
report_only_split_val->SetInteger("a", 1234);
pref_store_contents_->Set(kAtomicPref, int_value1);
@@ -1264,10 +1264,10 @@ TEST_P(PrefHashFilterTest, DontResetReportOnly) {
TEST_P(PrefHashFilterTest, CallFilterSerializeDataCallbacks) {
base::DictionaryValue root_dict;
// Ownership of the following values is transfered to |root_dict|.
- base::Value* int_value1 = new base::FundamentalValue(1);
- base::Value* int_value2 = new base::FundamentalValue(2);
+ base::Value* int_value1 = new base::Value(1);
+ base::Value* int_value2 = new base::Value(2);
base::DictionaryValue* dict_value = new base::DictionaryValue;
- dict_value->Set("a", new base::FundamentalValue(true));
+ dict_value->Set("a", new base::Value(true));
root_dict.Set(kAtomicPref, int_value1);
root_dict.Set(kAtomicPref2, int_value2);
root_dict.Set(kSplitPref, dict_value);
@@ -1313,7 +1313,7 @@ TEST_P(PrefHashFilterTest, CallFilterSerializeDataCallbacks) {
TEST_P(PrefHashFilterTest, CallFilterSerializeDataCallbacksWithFailure) {
base::DictionaryValue root_dict;
// Ownership of the following values is transfered to |root_dict|.
- base::Value* int_value1 = new base::FundamentalValue(1);
+ base::Value* int_value1 = new base::Value(1);
root_dict.Set(kAtomicPref, int_value1);
// Only update kAtomicPref.
@@ -1341,7 +1341,7 @@ TEST_P(PrefHashFilterTest, CallFilterSerializeDataCallbacksWithFailure) {
TEST_P(PrefHashFilterTest, ExternalValidationValueChanged) {
// Ownership of this value is transfered to |pref_store_contents_|.
- base::Value* int_value = new base::FundamentalValue(1234);
+ base::Value* int_value = new base::Value(1234);
pref_store_contents_->Set(kAtomicPref, int_value);
base::DictionaryValue* dict_value = new base::DictionaryValue;
diff --git a/chromium/components/user_prefs/tracked/pref_hash_store_impl.cc b/chromium/components/user_prefs/tracked/pref_hash_store_impl.cc
index 80438d6954a..bb920ca4c98 100644
--- a/chromium/components/user_prefs/tracked/pref_hash_store_impl.cc
+++ b/chromium/components/user_prefs/tracked/pref_hash_store_impl.cc
@@ -9,9 +9,37 @@
#include "base/logging.h"
#include "base/macros.h"
-#include "base/metrics/histogram.h"
+#include "base/metrics/histogram_macros.h"
+#include "components/user_prefs/tracked/device_id.h"
#include "components/user_prefs/tracked/hash_store_contents.h"
+namespace {
+
+// Returns a deterministic ID for this machine.
+std::string GenerateDeviceId() {
+ static std::string cached_device_id;
+ if (!cached_device_id.empty())
+ return cached_device_id;
+
+ std::string device_id;
+ MachineIdStatus status = GetDeterministicMachineSpecificId(&device_id);
+ if (status != MachineIdStatus::NOT_IMPLEMENTED) {
+ // TODO(proberge): Remove this histogram once we validate that machine id
+ // generation is not flaky and consider adding a CHECK or DCHECK.
+ UMA_HISTOGRAM_BOOLEAN("Settings.MachineIdGenerationSuccess",
+ status == MachineIdStatus::SUCCESS);
+ }
+
+ if (status == MachineIdStatus::SUCCESS) {
+ cached_device_id = device_id;
+ return device_id;
+ }
+
+ return std::string();
+}
+
+} // namespace
+
class PrefHashStoreImpl::PrefHashStoreTransactionImpl
: public PrefHashStoreTransaction {
public:
@@ -49,10 +77,10 @@ class PrefHashStoreImpl::PrefHashStoreTransactionImpl
};
PrefHashStoreImpl::PrefHashStoreImpl(const std::string& seed,
- const std::string& device_id,
+ const std::string& legacy_device_id,
bool use_super_mac)
- : pref_hash_calculator_(seed, device_id), use_super_mac_(use_super_mac) {
-}
+ : pref_hash_calculator_(seed, GenerateDeviceId(), legacy_device_id),
+ use_super_mac_(use_super_mac) {}
PrefHashStoreImpl::~PrefHashStoreImpl() {
}
diff --git a/chromium/components/user_prefs/tracked/pref_hash_store_impl.h b/chromium/components/user_prefs/tracked/pref_hash_store_impl.h
index 1b5682eed4e..76b6f7597e1 100644
--- a/chromium/components/user_prefs/tracked/pref_hash_store_impl.h
+++ b/chromium/components/user_prefs/tracked/pref_hash_store_impl.h
@@ -25,12 +25,12 @@ class PrefHashStoreImpl : public PrefHashStore {
};
// Constructs a PrefHashStoreImpl that calculates hashes using
- // |seed| and |device_id| and stores them in |contents|.
+ // |seed| and |legacy_device_id| and stores them in |contents|.
//
- // The same |seed| and |device_id| must be used to load and validate
+ // The same |seed| and |legacy_device_id| must be used to load and validate
// previously stored hashes in |contents|.
PrefHashStoreImpl(const std::string& seed,
- const std::string& device_id,
+ const std::string& legacy_device_id,
bool use_super_mac);
~PrefHashStoreImpl() override;
diff --git a/chromium/components/user_prefs/tracked/registry_hash_store_contents_win_unittest.cc b/chromium/components/user_prefs/tracked/registry_hash_store_contents_win_unittest.cc
index a34d7ade788..8b53b920da3 100644
--- a/chromium/components/user_prefs/tracked/registry_hash_store_contents_win_unittest.cc
+++ b/chromium/components/user_prefs/tracked/registry_hash_store_contents_win_unittest.cc
@@ -30,7 +30,8 @@ class RegistryHashStoreContentsWinTest : public testing::Test {
RegistryHashStoreContentsWinTest() {}
void SetUp() override {
- registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
+ ASSERT_NO_FATAL_FAILURE(
+ registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER));
contents.reset(new RegistryHashStoreContentsWin(kRegistryPath, kStoreKey));
}
diff --git a/chromium/components/user_prefs/tracked/segregated_pref_store.cc b/chromium/components/user_prefs/tracked/segregated_pref_store.cc
index edb1f205992..297e2a7e58f 100644
--- a/chromium/components/user_prefs/tracked/segregated_pref_store.cc
+++ b/chromium/components/user_prefs/tracked/segregated_pref_store.cc
@@ -83,6 +83,20 @@ bool SegregatedPrefStore::GetValue(const std::string& key,
return StoreForKey(key)->GetValue(key, result);
}
+std::unique_ptr<base::DictionaryValue> SegregatedPrefStore::GetValues() const {
+ auto values = default_pref_store_->GetValues();
+ auto selected_pref_store_values = selected_pref_store_->GetValues();
+ for (const auto& key : selected_preference_names_) {
+ const base::Value* value = nullptr;
+ if (selected_pref_store_values->Get(key, &value)) {
+ values->Set(key, value->CreateDeepCopy());
+ } else {
+ values->Remove(key, nullptr);
+ }
+ }
+ return values;
+}
+
void SegregatedPrefStore::SetValue(const std::string& key,
std::unique_ptr<base::Value> value,
uint32_t flags) {
diff --git a/chromium/components/user_prefs/tracked/segregated_pref_store.h b/chromium/components/user_prefs/tracked/segregated_pref_store.h
index 016cca6d049..40629768f01 100644
--- a/chromium/components/user_prefs/tracked/segregated_pref_store.h
+++ b/chromium/components/user_prefs/tracked/segregated_pref_store.h
@@ -52,6 +52,7 @@ class SegregatedPrefStore : public PersistentPrefStore {
bool IsInitializationComplete() const override;
bool GetValue(const std::string& key,
const base::Value** result) const override;
+ std::unique_ptr<base::DictionaryValue> GetValues() const override;
// WriteablePrefStore implementation
void SetValue(const std::string& key,
diff --git a/chromium/components/user_prefs/tracked/segregated_pref_store_unittest.cc b/chromium/components/user_prefs/tracked/segregated_pref_store_unittest.cc
index 5d32d027d5e..a4b40b15778 100644
--- a/chromium/components/user_prefs/tracked/segregated_pref_store_unittest.cc
+++ b/chromium/components/user_prefs/tracked/segregated_pref_store_unittest.cc
@@ -24,6 +24,7 @@ namespace {
const char kSelectedPref[] = "selected_pref";
const char kUnselectedPref[] = "unselected_pref";
+const char kSharedPref[] = "shared_pref";
const char kValue1[] = "value1";
const char kValue2[] = "value2";
@@ -70,6 +71,7 @@ class SegregatedPrefStoreTest : public testing::Test {
std::set<std::string> selected_pref_names;
selected_pref_names.insert(kSelectedPref);
+ selected_pref_names.insert(kSharedPref);
segregated_store_ = new SegregatedPrefStore(default_store_, selected_store_,
selected_pref_names);
@@ -274,3 +276,31 @@ TEST_F(SegregatedPrefStoreTest, IsInitializationCompleteAsync) {
default_store_->SetBlockAsyncRead(false);
EXPECT_TRUE(segregated_store_->IsInitializationComplete());
}
+
+TEST_F(SegregatedPrefStoreTest, GetValues) {
+ // To check merge behavior, create selected and default stores so each has a
+ // key the other doesn't have and they have one key in common.
+ selected_store_->SetValue(kSelectedPref,
+ base::MakeUnique<base::StringValue>(kValue1),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ default_store_->SetValue(kUnselectedPref,
+ base::MakeUnique<base::StringValue>(kValue2),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ selected_store_->SetValue(kSharedPref,
+ base::MakeUnique<base::StringValue>(kValue1),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+
+ auto values = segregated_store_->GetValues();
+ const base::Value* value = nullptr;
+ // Check that a selected preference is returned.
+ ASSERT_TRUE(values->Get(kSelectedPref, &value));
+ EXPECT_TRUE(base::Value(kValue1).Equals(value));
+
+ // Check that a a default preference is returned.
+ ASSERT_TRUE(values->Get(kUnselectedPref, &value));
+ EXPECT_TRUE(base::Value(kValue2).Equals(value));
+
+ // Check that the selected preference is preferred.
+ ASSERT_TRUE(values->Get(kSharedPref, &value));
+ EXPECT_TRUE(base::Value(kValue1).Equals(value));
+}