OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/webui/local_state/local_state_ui.h" |
| 6 |
| 7 #include "base/values.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 TEST(LocalStateUiTest, FilterPrefs) { |
| 11 std::vector<std::string> prefixes = {"foo", "bar", "baz"}; |
| 12 |
| 13 std::vector<std::string> invalid_pref_keys = {"fo", "ar", "afoo"}; |
| 14 std::vector<std::string> valid_pref_keys = {"foo", "foom", "bar.stuff"}; |
| 15 |
| 16 std::vector<std::string> all_pref_keys = invalid_pref_keys; |
| 17 all_pref_keys.insert(all_pref_keys.end(), valid_pref_keys.begin(), |
| 18 valid_pref_keys.end()); |
| 19 |
| 20 base::DictionaryValue prefs; |
| 21 for (const std::string& key : all_pref_keys) { |
| 22 prefs.Set(key, new base::StringValue(key + "_value")); |
| 23 } |
| 24 |
| 25 internal::FilterPrefs(prefixes, &prefs); |
| 26 |
| 27 for (const std::string& invalid_key : invalid_pref_keys) { |
| 28 std::string value; |
| 29 EXPECT_FALSE(prefs.GetString(invalid_key, &value)); |
| 30 } |
| 31 |
| 32 for (const std::string& valid_key : valid_pref_keys) { |
| 33 std::string value; |
| 34 EXPECT_TRUE(prefs.GetString(valid_key, &value)); |
| 35 EXPECT_EQ(valid_key + "_value", value); |
| 36 } |
| 37 } |
OLD | NEW |