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

Side by Side Diff: chrome/browser/prefs/command_line_pref_store_unittest.cc

Issue 5646003: Sanitize PrefStore interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix PrefService mock construction in PrefServiceTest to include command line store. Created 10 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <gtest/gtest.h> 5 #include <gtest/gtest.h>
6 6
7 #include "app/app_switches.h" 7 #include "app/app_switches.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 16 matching lines...) Expand all
27 const char unknown_bool[] = "unknown_switch"; 27 const char unknown_bool[] = "unknown_switch";
28 const char unknown_string[] = "unknown_other_switch"; 28 const char unknown_string[] = "unknown_other_switch";
29 29
30 } // namespace 30 } // namespace
31 31
32 // Tests a simple string pref on the command line. 32 // Tests a simple string pref on the command line.
33 TEST(CommandLinePrefStoreTest, SimpleStringPref) { 33 TEST(CommandLinePrefStoreTest, SimpleStringPref) {
34 CommandLine cl(CommandLine::NO_PROGRAM); 34 CommandLine cl(CommandLine::NO_PROGRAM);
35 cl.AppendSwitchASCII(switches::kLang, "hi-MOM"); 35 cl.AppendSwitchASCII(switches::kLang, "hi-MOM");
36 CommandLinePrefStore store(&cl); 36 CommandLinePrefStore store(&cl);
37 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
38 37
38 Value* actual = NULL;
39 EXPECT_EQ(PrefStore::READ_OK,
40 store.GetValue(prefs::kApplicationLocale, &actual));
39 std::string result; 41 std::string result;
40 EXPECT_TRUE(store.prefs()->GetString(prefs::kApplicationLocale, &result)); 42 EXPECT_TRUE(actual->GetAsString(&result));
41 EXPECT_EQ("hi-MOM", result); 43 EXPECT_EQ("hi-MOM", result);
42 } 44 }
43 45
44 // Tests a simple boolean pref on the command line. 46 // Tests a simple boolean pref on the command line.
45 TEST(CommandLinePrefStoreTest, SimpleBooleanPref) { 47 TEST(CommandLinePrefStoreTest, SimpleBooleanPref) {
46 CommandLine cl(CommandLine::NO_PROGRAM); 48 CommandLine cl(CommandLine::NO_PROGRAM);
47 cl.AppendSwitch(switches::kNoProxyServer); 49 cl.AppendSwitch(switches::kNoProxyServer);
48 CommandLinePrefStore store(&cl); 50 CommandLinePrefStore store(&cl);
49 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
50 51
52 Value* actual = NULL;
53 ASSERT_EQ(PrefStore::READ_OK, store.GetValue(prefs::kNoProxyServer, &actual));
51 bool result; 54 bool result;
52 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &result)); 55 EXPECT_TRUE(actual->GetAsBoolean(&result));
53 EXPECT_TRUE(result); 56 EXPECT_TRUE(result);
54 } 57 }
55 58
56 // Tests a command line with no recognized prefs. 59 // Tests a command line with no recognized prefs.
57 TEST(CommandLinePrefStoreTest, NoPrefs) { 60 TEST(CommandLinePrefStoreTest, NoPrefs) {
58 CommandLine cl(CommandLine::NO_PROGRAM); 61 CommandLine cl(CommandLine::NO_PROGRAM);
59 cl.AppendSwitch(unknown_string); 62 cl.AppendSwitch(unknown_string);
60 cl.AppendSwitchASCII(unknown_bool, "a value"); 63 cl.AppendSwitchASCII(unknown_bool, "a value");
61 CommandLinePrefStore store(&cl); 64 CommandLinePrefStore store(&cl);
62 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
63 65
64 bool bool_result = false; 66 Value* actual = NULL;
65 EXPECT_FALSE(store.prefs()->GetBoolean(unknown_bool, &bool_result)); 67 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_bool, &actual));
66 EXPECT_FALSE(bool_result); 68 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_string, &actual));
67
68 std::string string_result = "";
69 EXPECT_FALSE(store.prefs()->GetString(unknown_string, &string_result));
70 EXPECT_EQ("", string_result);
71 } 69 }
72 70
73 // Tests a complex command line with multiple known and unknown switches. 71 // Tests a complex command line with multiple known and unknown switches.
74 TEST(CommandLinePrefStoreTest, MultipleSwitches) { 72 TEST(CommandLinePrefStoreTest, MultipleSwitches) {
75 CommandLine cl(CommandLine::NO_PROGRAM); 73 CommandLine cl(CommandLine::NO_PROGRAM);
76 cl.AppendSwitch(unknown_string); 74 cl.AppendSwitch(unknown_string);
77 cl.AppendSwitch(switches::kProxyAutoDetect); 75 cl.AppendSwitch(switches::kProxyAutoDetect);
78 cl.AppendSwitchASCII(switches::kProxyServer, "proxy"); 76 cl.AppendSwitchASCII(switches::kProxyServer, "proxy");
79 cl.AppendSwitchASCII(switches::kProxyBypassList, "list"); 77 cl.AppendSwitchASCII(switches::kProxyBypassList, "list");
80 cl.AppendSwitchASCII(unknown_bool, "a value"); 78 cl.AppendSwitchASCII(unknown_bool, "a value");
81 CommandLinePrefStore store(&cl); 79 CommandLinePrefStore store(&cl);
82 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
83 80
81 Value* actual = NULL;
82 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_bool, &actual));
83 ASSERT_EQ(PrefStore::READ_OK,
84 store.GetValue(prefs::kProxyAutoDetect, &actual));
84 bool bool_result = false; 85 bool bool_result = false;
85 EXPECT_FALSE(store.prefs()->GetBoolean(unknown_bool, &bool_result)); 86 EXPECT_TRUE(actual->GetAsBoolean(&bool_result));
86 EXPECT_FALSE(bool_result);
87 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result));
88 EXPECT_TRUE(bool_result); 87 EXPECT_TRUE(bool_result);
89 88
89 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_string, &actual));
90 std::string string_result = ""; 90 std::string string_result = "";
91 EXPECT_FALSE(store.prefs()->GetString(unknown_string, &string_result)); 91 ASSERT_EQ(PrefStore::READ_OK, store.GetValue(prefs::kProxyServer, &actual));
92 EXPECT_EQ("", string_result); 92 EXPECT_TRUE(actual->GetAsString(&string_result));
93 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
94 EXPECT_EQ("proxy", string_result); 93 EXPECT_EQ("proxy", string_result);
95 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyBypassList, 94 ASSERT_EQ(PrefStore::READ_OK,
96 &string_result)); 95 store.GetValue(prefs::kProxyBypassList, &actual));
96 EXPECT_TRUE(actual->GetAsString(&string_result));
97 EXPECT_EQ("list", string_result); 97 EXPECT_EQ("list", string_result);
98 } 98 }
99 99
100 // Tests proxy switch validation. 100 // Tests proxy switch validation.
101 TEST(CommandLinePrefStoreTest, ProxySwitchValidation) { 101 TEST(CommandLinePrefStoreTest, ProxySwitchValidation) {
102 CommandLine cl(CommandLine::NO_PROGRAM); 102 CommandLine cl(CommandLine::NO_PROGRAM);
103 103
104 // No switches. 104 // No switches.
105 TestCommandLinePrefStore store(&cl); 105 TestCommandLinePrefStore store(&cl);
106 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
107 EXPECT_TRUE(store.ProxySwitchesAreValid()); 106 EXPECT_TRUE(store.ProxySwitchesAreValid());
108 107
109 // Only no-proxy. 108 // Only no-proxy.
110 cl.AppendSwitch(switches::kNoProxyServer); 109 cl.AppendSwitch(switches::kNoProxyServer);
111 TestCommandLinePrefStore store2(&cl); 110 TestCommandLinePrefStore store2(&cl);
112 EXPECT_EQ(store2.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
113 EXPECT_TRUE(store2.ProxySwitchesAreValid()); 111 EXPECT_TRUE(store2.ProxySwitchesAreValid());
114 112
115 // Another proxy switch too. 113 // Another proxy switch too.
116 cl.AppendSwitch(switches::kProxyAutoDetect); 114 cl.AppendSwitch(switches::kProxyAutoDetect);
117 TestCommandLinePrefStore store3(&cl); 115 TestCommandLinePrefStore store3(&cl);
118 EXPECT_EQ(store3.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
119 EXPECT_FALSE(store3.ProxySwitchesAreValid()); 116 EXPECT_FALSE(store3.ProxySwitchesAreValid());
120 117
121 // All proxy switches except no-proxy. 118 // All proxy switches except no-proxy.
122 CommandLine cl2(CommandLine::NO_PROGRAM); 119 CommandLine cl2(CommandLine::NO_PROGRAM);
123 cl2.AppendSwitch(switches::kProxyAutoDetect); 120 cl2.AppendSwitch(switches::kProxyAutoDetect);
124 cl2.AppendSwitchASCII(switches::kProxyServer, "server"); 121 cl2.AppendSwitchASCII(switches::kProxyServer, "server");
125 cl2.AppendSwitchASCII(switches::kProxyPacUrl, "url"); 122 cl2.AppendSwitchASCII(switches::kProxyPacUrl, "url");
126 cl2.AppendSwitchASCII(switches::kProxyBypassList, "list"); 123 cl2.AppendSwitchASCII(switches::kProxyBypassList, "list");
127 TestCommandLinePrefStore store4(&cl2); 124 TestCommandLinePrefStore store4(&cl2);
128 EXPECT_EQ(store4.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
129 EXPECT_TRUE(store4.ProxySwitchesAreValid()); 125 EXPECT_TRUE(store4.ProxySwitchesAreValid());
130 } 126 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/command_line_pref_store.cc ('k') | chrome/browser/prefs/default_pref_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698