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 "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 TEST(LocalStateUiTest, FilterPrefs) { |
| 10 std::vector<std::string> prefixes = {"foo", "bar", "baz"}; |
| 11 |
| 12 std::vector<std::string> invalid_pref_keys = {"fo", "ar", "afoo"}; |
| 13 std::vector<std::string> valid_pref_keys = {"foo", "foom", "bar.stuff"}; |
| 14 |
| 15 std::vector<std::string> all_pref_keys = invalid_pref_keys; |
| 16 all_pref_keys.insert(all_pref_keys.end(), valid_pref_keys.begin(), |
| 17 valid_pref_keys.end()); |
| 18 |
| 19 base::DictionaryValue prefs; |
| 20 for (const std::string& key : all_pref_keys) { |
| 21 prefs.Set(key, new base::StringValue(key + "_value")); |
| 22 } |
| 23 |
| 24 internal::FilterPrefs(prefixes, &prefs); |
| 25 |
| 26 for (const std::string& invalid_key : invalid_pref_keys) { |
| 27 std::string value; |
| 28 EXPECT_FALSE(prefs.GetString(invalid_key, &value)); |
| 29 } |
| 30 |
| 31 for (const std::string& valid_key : valid_pref_keys) { |
| 32 std::string value; |
| 33 EXPECT_TRUE(prefs.GetString(valid_key, &value)); |
| 34 EXPECT_EQ(valid_key + "_value", value); |
| 35 } |
| 36 } |
OLD | NEW |