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

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

Issue 3935001: Rename CommandLine::ARGUMENTS_ONLY to NO_PROGRAM. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years, 2 months 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
« no previous file with comments | « chrome/browser/jumplist_win.cc ('k') | chrome/browser/prefs/pref_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 13 matching lines...) Expand all
24 } 24 }
25 }; 25 };
26 26
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::ARGUMENTS_ONLY); 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); 37 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
38 38
39 std::string result; 39 std::string result;
40 EXPECT_TRUE(store.prefs()->GetString(prefs::kApplicationLocale, &result)); 40 EXPECT_TRUE(store.prefs()->GetString(prefs::kApplicationLocale, &result));
41 EXPECT_EQ("hi-MOM", result); 41 EXPECT_EQ("hi-MOM", result);
42 } 42 }
43 43
44 // Tests a simple boolean pref on the command line. 44 // Tests a simple boolean pref on the command line.
45 TEST(CommandLinePrefStoreTest, SimpleBooleanPref) { 45 TEST(CommandLinePrefStoreTest, SimpleBooleanPref) {
46 CommandLine cl(CommandLine::ARGUMENTS_ONLY); 46 CommandLine cl(CommandLine::NO_PROGRAM);
47 cl.AppendSwitch(switches::kNoProxyServer); 47 cl.AppendSwitch(switches::kNoProxyServer);
48 CommandLinePrefStore store(&cl); 48 CommandLinePrefStore store(&cl);
49 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); 49 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
50 50
51 bool result; 51 bool result;
52 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &result)); 52 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &result));
53 EXPECT_TRUE(result); 53 EXPECT_TRUE(result);
54 } 54 }
55 55
56 // Tests a command line with no recognized prefs. 56 // Tests a command line with no recognized prefs.
57 TEST(CommandLinePrefStoreTest, NoPrefs) { 57 TEST(CommandLinePrefStoreTest, NoPrefs) {
58 CommandLine cl(CommandLine::ARGUMENTS_ONLY); 58 CommandLine cl(CommandLine::NO_PROGRAM);
59 cl.AppendSwitch(unknown_string); 59 cl.AppendSwitch(unknown_string);
60 cl.AppendSwitchASCII(unknown_bool, "a value"); 60 cl.AppendSwitchASCII(unknown_bool, "a value");
61 CommandLinePrefStore store(&cl); 61 CommandLinePrefStore store(&cl);
62 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); 62 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
63 63
64 bool bool_result = false; 64 bool bool_result = false;
65 EXPECT_FALSE(store.prefs()->GetBoolean(unknown_bool, &bool_result)); 65 EXPECT_FALSE(store.prefs()->GetBoolean(unknown_bool, &bool_result));
66 EXPECT_FALSE(bool_result); 66 EXPECT_FALSE(bool_result);
67 67
68 std::string string_result = ""; 68 std::string string_result = "";
69 EXPECT_FALSE(store.prefs()->GetString(unknown_string, &string_result)); 69 EXPECT_FALSE(store.prefs()->GetString(unknown_string, &string_result));
70 EXPECT_EQ("", string_result); 70 EXPECT_EQ("", string_result);
71 } 71 }
72 72
73 // Tests a complex command line with multiple known and unknown switches. 73 // Tests a complex command line with multiple known and unknown switches.
74 TEST(CommandLinePrefStoreTest, MultipleSwitches) { 74 TEST(CommandLinePrefStoreTest, MultipleSwitches) {
75 CommandLine cl(CommandLine::ARGUMENTS_ONLY); 75 CommandLine cl(CommandLine::NO_PROGRAM);
76 cl.AppendSwitch(unknown_string); 76 cl.AppendSwitch(unknown_string);
77 cl.AppendSwitch(switches::kProxyAutoDetect); 77 cl.AppendSwitch(switches::kProxyAutoDetect);
78 cl.AppendSwitchASCII(switches::kProxyServer, "proxy"); 78 cl.AppendSwitchASCII(switches::kProxyServer, "proxy");
79 cl.AppendSwitchASCII(switches::kProxyBypassList, "list"); 79 cl.AppendSwitchASCII(switches::kProxyBypassList, "list");
80 cl.AppendSwitchASCII(unknown_bool, "a value"); 80 cl.AppendSwitchASCII(unknown_bool, "a value");
81 CommandLinePrefStore store(&cl); 81 CommandLinePrefStore store(&cl);
82 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); 82 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
83 83
84 bool bool_result = false; 84 bool bool_result = false;
85 EXPECT_FALSE(store.prefs()->GetBoolean(unknown_bool, &bool_result)); 85 EXPECT_FALSE(store.prefs()->GetBoolean(unknown_bool, &bool_result));
86 EXPECT_FALSE(bool_result); 86 EXPECT_FALSE(bool_result);
87 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result)); 87 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result));
88 EXPECT_TRUE(bool_result); 88 EXPECT_TRUE(bool_result);
89 89
90 std::string string_result = ""; 90 std::string string_result = "";
91 EXPECT_FALSE(store.prefs()->GetString(unknown_string, &string_result)); 91 EXPECT_FALSE(store.prefs()->GetString(unknown_string, &string_result));
92 EXPECT_EQ("", string_result); 92 EXPECT_EQ("", string_result);
93 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 93 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
94 EXPECT_EQ("proxy", string_result); 94 EXPECT_EQ("proxy", string_result);
95 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyBypassList, 95 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyBypassList,
96 &string_result)); 96 &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::ARGUMENTS_ONLY); 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); 106 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
107 EXPECT_TRUE(store.ProxySwitchesAreValid()); 107 EXPECT_TRUE(store.ProxySwitchesAreValid());
108 108
109 // Only no-proxy. 109 // Only no-proxy.
110 cl.AppendSwitch(switches::kNoProxyServer); 110 cl.AppendSwitch(switches::kNoProxyServer);
111 TestCommandLinePrefStore store2(&cl); 111 TestCommandLinePrefStore store2(&cl);
112 EXPECT_EQ(store2.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); 112 EXPECT_EQ(store2.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
113 EXPECT_TRUE(store2.ProxySwitchesAreValid()); 113 EXPECT_TRUE(store2.ProxySwitchesAreValid());
114 114
115 // Another proxy switch too. 115 // Another proxy switch too.
116 cl.AppendSwitch(switches::kProxyAutoDetect); 116 cl.AppendSwitch(switches::kProxyAutoDetect);
117 TestCommandLinePrefStore store3(&cl); 117 TestCommandLinePrefStore store3(&cl);
118 EXPECT_EQ(store3.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); 118 EXPECT_EQ(store3.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
119 EXPECT_FALSE(store3.ProxySwitchesAreValid()); 119 EXPECT_FALSE(store3.ProxySwitchesAreValid());
120 120
121 // All proxy switches except no-proxy. 121 // All proxy switches except no-proxy.
122 CommandLine cl2(CommandLine::ARGUMENTS_ONLY); 122 CommandLine cl2(CommandLine::NO_PROGRAM);
123 cl2.AppendSwitch(switches::kProxyAutoDetect); 123 cl2.AppendSwitch(switches::kProxyAutoDetect);
124 cl2.AppendSwitchASCII(switches::kProxyServer, "server"); 124 cl2.AppendSwitchASCII(switches::kProxyServer, "server");
125 cl2.AppendSwitchASCII(switches::kProxyPacUrl, "url"); 125 cl2.AppendSwitchASCII(switches::kProxyPacUrl, "url");
126 cl2.AppendSwitchASCII(switches::kProxyBypassList, "list"); 126 cl2.AppendSwitchASCII(switches::kProxyBypassList, "list");
127 TestCommandLinePrefStore store4(&cl2); 127 TestCommandLinePrefStore store4(&cl2);
128 EXPECT_EQ(store4.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); 128 EXPECT_EQ(store4.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
129 EXPECT_TRUE(store4.ProxySwitchesAreValid()); 129 EXPECT_TRUE(store4.ProxySwitchesAreValid());
130 } 130 }
OLDNEW
« no previous file with comments | « chrome/browser/jumplist_win.cc ('k') | chrome/browser/prefs/pref_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698