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

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

Issue 5701003: Intorduce a separate preference for 'proxy server mode' (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix indentation nit 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"
11 #include "chrome/browser/prefs/command_line_pref_store.h" 11 #include "chrome/browser/prefs/command_line_pref_store.h"
12 #include "chrome/browser/prefs/proxy_prefs.h"
12 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
14 15
15 namespace { 16 namespace {
16 17
17 class TestCommandLinePrefStore : public CommandLinePrefStore { 18 class TestCommandLinePrefStore : public CommandLinePrefStore {
18 public: 19 public:
19 explicit TestCommandLinePrefStore(CommandLine* cl) 20 explicit TestCommandLinePrefStore(CommandLine* cl)
20 : CommandLinePrefStore(cl) {} 21 : CommandLinePrefStore(cl) {}
21 22
22 bool ProxySwitchesAreValid() { 23 bool ProxySwitchesAreValid() {
23 return ValidateProxySwitches(); 24 return ValidateProxySwitches();
24 } 25 }
26
27 void VerifyIntPref(const std::string& path, int expected_value) {
28 Value* actual = NULL;
29 ASSERT_EQ(PrefStore::READ_OK, GetValue(path, &actual));
30 int int_result = -1;
31 EXPECT_TRUE(actual->GetAsInteger(&int_result));
32 EXPECT_EQ(expected_value, int_result);
33 }
25 }; 34 };
26 35
27 const char unknown_bool[] = "unknown_switch"; 36 const char unknown_bool[] = "unknown_switch";
28 const char unknown_string[] = "unknown_other_switch"; 37 const char unknown_string[] = "unknown_other_switch";
29 38
30 } // namespace 39 } // namespace
31 40
32 // Tests a simple string pref on the command line. 41 // Tests a simple string pref on the command line.
33 TEST(CommandLinePrefStoreTest, SimpleStringPref) { 42 TEST(CommandLinePrefStoreTest, SimpleStringPref) {
34 CommandLine cl(CommandLine::NO_PROGRAM); 43 CommandLine cl(CommandLine::NO_PROGRAM);
35 cl.AppendSwitchASCII(switches::kLang, "hi-MOM"); 44 cl.AppendSwitchASCII(switches::kLang, "hi-MOM");
36 CommandLinePrefStore store(&cl); 45 CommandLinePrefStore store(&cl);
37 46
38 Value* actual = NULL; 47 Value* actual = NULL;
39 EXPECT_EQ(PrefStore::READ_OK, 48 EXPECT_EQ(PrefStore::READ_OK,
40 store.GetValue(prefs::kApplicationLocale, &actual)); 49 store.GetValue(prefs::kApplicationLocale, &actual));
41 std::string result; 50 std::string result;
42 EXPECT_TRUE(actual->GetAsString(&result)); 51 EXPECT_TRUE(actual->GetAsString(&result));
43 EXPECT_EQ("hi-MOM", result); 52 EXPECT_EQ("hi-MOM", result);
44 } 53 }
45 54
46 // Tests a simple boolean pref on the command line. 55 // Tests a simple boolean pref on the command line.
47 TEST(CommandLinePrefStoreTest, SimpleBooleanPref) { 56 TEST(CommandLinePrefStoreTest, SimpleBooleanPref) {
48 CommandLine cl(CommandLine::NO_PROGRAM); 57 CommandLine cl(CommandLine::NO_PROGRAM);
49 cl.AppendSwitch(switches::kNoProxyServer); 58 cl.AppendSwitch(switches::kNoProxyServer);
50 CommandLinePrefStore store(&cl); 59 CommandLinePrefStore store(&cl);
51 60
52 Value* actual = NULL; 61 Value* actual = NULL;
53 ASSERT_EQ(PrefStore::READ_OK, store.GetValue(prefs::kNoProxyServer, &actual)); 62 ASSERT_EQ(PrefStore::READ_OK,
54 bool result; 63 store.GetValue(prefs::kProxyServerMode, &actual));
55 EXPECT_TRUE(actual->GetAsBoolean(&result)); 64 int result = -1;
56 EXPECT_TRUE(result); 65 EXPECT_TRUE(actual->GetAsInteger(&result));
66 EXPECT_EQ(ProxyPrefs::DISABLED, result);
57 } 67 }
58 68
59 // Tests a command line with no recognized prefs. 69 // Tests a command line with no recognized prefs.
60 TEST(CommandLinePrefStoreTest, NoPrefs) { 70 TEST(CommandLinePrefStoreTest, NoPrefs) {
61 CommandLine cl(CommandLine::NO_PROGRAM); 71 CommandLine cl(CommandLine::NO_PROGRAM);
62 cl.AppendSwitch(unknown_string); 72 cl.AppendSwitch(unknown_string);
63 cl.AppendSwitchASCII(unknown_bool, "a value"); 73 cl.AppendSwitchASCII(unknown_bool, "a value");
64 CommandLinePrefStore store(&cl); 74 CommandLinePrefStore store(&cl);
65 75
66 Value* actual = NULL; 76 Value* actual = NULL;
67 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_bool, &actual)); 77 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_bool, &actual));
68 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_string, &actual)); 78 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_string, &actual));
69 } 79 }
70 80
71 // Tests a complex command line with multiple known and unknown switches. 81 // Tests a complex command line with multiple known and unknown switches.
72 TEST(CommandLinePrefStoreTest, MultipleSwitches) { 82 TEST(CommandLinePrefStoreTest, MultipleSwitches) {
73 CommandLine cl(CommandLine::NO_PROGRAM); 83 CommandLine cl(CommandLine::NO_PROGRAM);
74 cl.AppendSwitch(unknown_string); 84 cl.AppendSwitch(unknown_string);
75 cl.AppendSwitch(switches::kProxyAutoDetect); 85 cl.AppendSwitch(switches::kProxyAutoDetect);
76 cl.AppendSwitchASCII(switches::kProxyServer, "proxy"); 86 cl.AppendSwitchASCII(switches::kProxyServer, "proxy");
77 cl.AppendSwitchASCII(switches::kProxyBypassList, "list"); 87 cl.AppendSwitchASCII(switches::kProxyBypassList, "list");
78 cl.AppendSwitchASCII(unknown_bool, "a value"); 88 cl.AppendSwitchASCII(unknown_bool, "a value");
79 CommandLinePrefStore store(&cl); 89 TestCommandLinePrefStore store(&cl);
80 90
81 Value* actual = NULL; 91 Value* actual = NULL;
82 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_bool, &actual)); 92 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_bool, &actual));
83 ASSERT_EQ(PrefStore::READ_OK, 93 store.VerifyIntPref(prefs::kProxyServerMode, ProxyPrefs::AUTO_DETECT);
84 store.GetValue(prefs::kProxyAutoDetect, &actual));
85 bool bool_result = false;
86 EXPECT_TRUE(actual->GetAsBoolean(&bool_result));
87 EXPECT_TRUE(bool_result);
88 94
89 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_string, &actual)); 95 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_string, &actual));
90 std::string string_result = ""; 96 std::string string_result = "";
91 ASSERT_EQ(PrefStore::READ_OK, store.GetValue(prefs::kProxyServer, &actual)); 97 ASSERT_EQ(PrefStore::READ_OK, store.GetValue(prefs::kProxyServer, &actual));
92 EXPECT_TRUE(actual->GetAsString(&string_result)); 98 EXPECT_TRUE(actual->GetAsString(&string_result));
93 EXPECT_EQ("proxy", string_result); 99 EXPECT_EQ("proxy", string_result);
94 ASSERT_EQ(PrefStore::READ_OK, 100 ASSERT_EQ(PrefStore::READ_OK,
95 store.GetValue(prefs::kProxyBypassList, &actual)); 101 store.GetValue(prefs::kProxyBypassList, &actual));
96 EXPECT_TRUE(actual->GetAsString(&string_result)); 102 EXPECT_TRUE(actual->GetAsString(&string_result));
97 EXPECT_EQ("list", string_result); 103 EXPECT_EQ("list", string_result);
(...skipping 19 matching lines...) Expand all
117 123
118 // All proxy switches except no-proxy. 124 // All proxy switches except no-proxy.
119 CommandLine cl2(CommandLine::NO_PROGRAM); 125 CommandLine cl2(CommandLine::NO_PROGRAM);
120 cl2.AppendSwitch(switches::kProxyAutoDetect); 126 cl2.AppendSwitch(switches::kProxyAutoDetect);
121 cl2.AppendSwitchASCII(switches::kProxyServer, "server"); 127 cl2.AppendSwitchASCII(switches::kProxyServer, "server");
122 cl2.AppendSwitchASCII(switches::kProxyPacUrl, "url"); 128 cl2.AppendSwitchASCII(switches::kProxyPacUrl, "url");
123 cl2.AppendSwitchASCII(switches::kProxyBypassList, "list"); 129 cl2.AppendSwitchASCII(switches::kProxyBypassList, "list");
124 TestCommandLinePrefStore store4(&cl2); 130 TestCommandLinePrefStore store4(&cl2);
125 EXPECT_TRUE(store4.ProxySwitchesAreValid()); 131 EXPECT_TRUE(store4.ProxySwitchesAreValid());
126 } 132 }
133
134 TEST(CommandLinePrefStoreTest, ManualProxyModeInference) {
135 CommandLine cl1(CommandLine::NO_PROGRAM);
136 cl1.AppendSwitch(unknown_string);
137 cl1.AppendSwitchASCII(switches::kProxyServer, "proxy");
138 TestCommandLinePrefStore store1(&cl1);
139 store1.VerifyIntPref(prefs::kProxyServerMode, ProxyPrefs::MANUAL);
140
141 CommandLine cl2(CommandLine::NO_PROGRAM);
142 cl2.AppendSwitch(unknown_string);
143 cl2.AppendSwitchASCII(switches::kProxyServer, "proxy");
144 TestCommandLinePrefStore store2(&cl2);
145 store2.VerifyIntPref(prefs::kProxyServerMode, ProxyPrefs::MANUAL);
Mattias Nissler (ping if slow) 2010/12/20 13:34:03 What's the difference between 1 and 2?
battre (please use the other) 2010/12/21 14:18:18 Deleted.
146
147 CommandLine cl3(CommandLine::NO_PROGRAM);
148 cl3.AppendSwitchASCII(switches::kProxyPacUrl, "proxy");
149 TestCommandLinePrefStore store3(&cl3);
150 store3.VerifyIntPref(prefs::kProxyServerMode, ProxyPrefs::MANUAL);
151 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698