OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ref_counted.h" |
9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 #include "chrome/browser/prefs/command_line_pref_store.h" | 12 #include "chrome/browser/prefs/command_line_pref_store.h" |
12 #include "chrome/browser/prefs/proxy_prefs.h" | 13 #include "chrome/browser/prefs/proxy_prefs.h" |
13 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 class TestCommandLinePrefStore : public CommandLinePrefStore { | 19 class TestCommandLinePrefStore : public CommandLinePrefStore { |
(...skipping 14 matching lines...) Expand all Loading... |
33 | 34 |
34 const char unknown_bool[] = "unknown_switch"; | 35 const char unknown_bool[] = "unknown_switch"; |
35 const char unknown_string[] = "unknown_other_switch"; | 36 const char unknown_string[] = "unknown_other_switch"; |
36 | 37 |
37 } // namespace | 38 } // namespace |
38 | 39 |
39 // Tests a simple string pref on the command line. | 40 // Tests a simple string pref on the command line. |
40 TEST(CommandLinePrefStoreTest, SimpleStringPref) { | 41 TEST(CommandLinePrefStoreTest, SimpleStringPref) { |
41 CommandLine cl(CommandLine::NO_PROGRAM); | 42 CommandLine cl(CommandLine::NO_PROGRAM); |
42 cl.AppendSwitchASCII(switches::kLang, "hi-MOM"); | 43 cl.AppendSwitchASCII(switches::kLang, "hi-MOM"); |
43 CommandLinePrefStore store(&cl); | 44 scoped_refptr<CommandLinePrefStore> store = new CommandLinePrefStore(&cl); |
44 | 45 |
45 Value* actual = NULL; | 46 Value* actual = NULL; |
46 EXPECT_EQ(PrefStore::READ_OK, | 47 EXPECT_EQ(PrefStore::READ_OK, |
47 store.GetValue(prefs::kApplicationLocale, &actual)); | 48 store->GetValue(prefs::kApplicationLocale, &actual)); |
48 std::string result; | 49 std::string result; |
49 EXPECT_TRUE(actual->GetAsString(&result)); | 50 EXPECT_TRUE(actual->GetAsString(&result)); |
50 EXPECT_EQ("hi-MOM", result); | 51 EXPECT_EQ("hi-MOM", result); |
51 } | 52 } |
52 | 53 |
53 // Tests a simple boolean pref on the command line. | 54 // Tests a simple boolean pref on the command line. |
54 TEST(CommandLinePrefStoreTest, SimpleBooleanPref) { | 55 TEST(CommandLinePrefStoreTest, SimpleBooleanPref) { |
55 CommandLine cl(CommandLine::NO_PROGRAM); | 56 CommandLine cl(CommandLine::NO_PROGRAM); |
56 cl.AppendSwitch(switches::kNoProxyServer); | 57 cl.AppendSwitch(switches::kNoProxyServer); |
57 TestCommandLinePrefStore store(&cl); | 58 scoped_refptr<TestCommandLinePrefStore> store = |
| 59 new TestCommandLinePrefStore(&cl); |
58 | 60 |
59 store.VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_DIRECT); | 61 store->VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_DIRECT); |
60 } | 62 } |
61 | 63 |
62 // Tests a command line with no recognized prefs. | 64 // Tests a command line with no recognized prefs. |
63 TEST(CommandLinePrefStoreTest, NoPrefs) { | 65 TEST(CommandLinePrefStoreTest, NoPrefs) { |
64 CommandLine cl(CommandLine::NO_PROGRAM); | 66 CommandLine cl(CommandLine::NO_PROGRAM); |
65 cl.AppendSwitch(unknown_string); | 67 cl.AppendSwitch(unknown_string); |
66 cl.AppendSwitchASCII(unknown_bool, "a value"); | 68 cl.AppendSwitchASCII(unknown_bool, "a value"); |
67 CommandLinePrefStore store(&cl); | 69 scoped_refptr<CommandLinePrefStore> store = new CommandLinePrefStore(&cl); |
68 | 70 |
69 Value* actual = NULL; | 71 Value* actual = NULL; |
70 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_bool, &actual)); | 72 EXPECT_EQ(PrefStore::READ_NO_VALUE, store->GetValue(unknown_bool, &actual)); |
71 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_string, &actual)); | 73 EXPECT_EQ(PrefStore::READ_NO_VALUE, store->GetValue(unknown_string, &actual)); |
72 } | 74 } |
73 | 75 |
74 // Tests a complex command line with multiple known and unknown switches. | 76 // Tests a complex command line with multiple known and unknown switches. |
75 TEST(CommandLinePrefStoreTest, MultipleSwitches) { | 77 TEST(CommandLinePrefStoreTest, MultipleSwitches) { |
76 CommandLine cl(CommandLine::NO_PROGRAM); | 78 CommandLine cl(CommandLine::NO_PROGRAM); |
77 cl.AppendSwitch(unknown_string); | 79 cl.AppendSwitch(unknown_string); |
78 cl.AppendSwitch(switches::kProxyAutoDetect); | 80 cl.AppendSwitch(switches::kProxyAutoDetect); |
79 cl.AppendSwitchASCII(switches::kProxyServer, "proxy"); | 81 cl.AppendSwitchASCII(switches::kProxyServer, "proxy"); |
80 cl.AppendSwitchASCII(switches::kProxyBypassList, "list"); | 82 cl.AppendSwitchASCII(switches::kProxyBypassList, "list"); |
81 cl.AppendSwitchASCII(unknown_bool, "a value"); | 83 cl.AppendSwitchASCII(unknown_bool, "a value"); |
82 TestCommandLinePrefStore store(&cl); | 84 scoped_refptr<TestCommandLinePrefStore> store = |
| 85 new TestCommandLinePrefStore(&cl); |
83 | 86 |
84 Value* actual = NULL; | 87 Value* actual = NULL; |
85 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_bool, &actual)); | 88 EXPECT_EQ(PrefStore::READ_NO_VALUE, store->GetValue(unknown_bool, &actual)); |
86 store.VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_AUTO_DETECT); | 89 store->VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_AUTO_DETECT); |
87 | 90 |
88 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_string, &actual)); | 91 EXPECT_EQ(PrefStore::READ_NO_VALUE, store->GetValue(unknown_string, &actual)); |
89 std::string string_result = ""; | 92 std::string string_result = ""; |
90 ASSERT_EQ(PrefStore::READ_OK, store.GetValue(prefs::kProxyServer, &actual)); | 93 ASSERT_EQ(PrefStore::READ_OK, store->GetValue(prefs::kProxyServer, &actual)); |
91 EXPECT_TRUE(actual->GetAsString(&string_result)); | 94 EXPECT_TRUE(actual->GetAsString(&string_result)); |
92 EXPECT_EQ("proxy", string_result); | 95 EXPECT_EQ("proxy", string_result); |
93 ASSERT_EQ(PrefStore::READ_OK, | 96 ASSERT_EQ(PrefStore::READ_OK, |
94 store.GetValue(prefs::kProxyBypassList, &actual)); | 97 store->GetValue(prefs::kProxyBypassList, &actual)); |
95 EXPECT_TRUE(actual->GetAsString(&string_result)); | 98 EXPECT_TRUE(actual->GetAsString(&string_result)); |
96 EXPECT_EQ("list", string_result); | 99 EXPECT_EQ("list", string_result); |
97 } | 100 } |
98 | 101 |
99 // Tests proxy switch validation. | 102 // Tests proxy switch validation. |
100 TEST(CommandLinePrefStoreTest, ProxySwitchValidation) { | 103 TEST(CommandLinePrefStoreTest, ProxySwitchValidation) { |
101 CommandLine cl(CommandLine::NO_PROGRAM); | 104 CommandLine cl(CommandLine::NO_PROGRAM); |
102 | 105 |
103 // No switches. | 106 // No switches. |
104 TestCommandLinePrefStore store(&cl); | 107 scoped_refptr<TestCommandLinePrefStore> store = |
105 EXPECT_TRUE(store.ProxySwitchesAreValid()); | 108 new TestCommandLinePrefStore(&cl); |
| 109 EXPECT_TRUE(store->ProxySwitchesAreValid()); |
106 | 110 |
107 // Only no-proxy. | 111 // Only no-proxy. |
108 cl.AppendSwitch(switches::kNoProxyServer); | 112 cl.AppendSwitch(switches::kNoProxyServer); |
109 TestCommandLinePrefStore store2(&cl); | 113 scoped_refptr<TestCommandLinePrefStore> store2 = |
110 EXPECT_TRUE(store2.ProxySwitchesAreValid()); | 114 new TestCommandLinePrefStore(&cl); |
| 115 EXPECT_TRUE(store2->ProxySwitchesAreValid()); |
111 | 116 |
112 // Another proxy switch too. | 117 // Another proxy switch too. |
113 cl.AppendSwitch(switches::kProxyAutoDetect); | 118 cl.AppendSwitch(switches::kProxyAutoDetect); |
114 TestCommandLinePrefStore store3(&cl); | 119 scoped_refptr<TestCommandLinePrefStore> store3 = |
115 EXPECT_FALSE(store3.ProxySwitchesAreValid()); | 120 new TestCommandLinePrefStore(&cl); |
| 121 EXPECT_FALSE(store3->ProxySwitchesAreValid()); |
116 | 122 |
117 // All proxy switches except no-proxy. | 123 // All proxy switches except no-proxy. |
118 CommandLine cl2(CommandLine::NO_PROGRAM); | 124 CommandLine cl2(CommandLine::NO_PROGRAM); |
119 cl2.AppendSwitch(switches::kProxyAutoDetect); | 125 cl2.AppendSwitch(switches::kProxyAutoDetect); |
120 cl2.AppendSwitchASCII(switches::kProxyServer, "server"); | 126 cl2.AppendSwitchASCII(switches::kProxyServer, "server"); |
121 cl2.AppendSwitchASCII(switches::kProxyPacUrl, "url"); | 127 cl2.AppendSwitchASCII(switches::kProxyPacUrl, "url"); |
122 cl2.AppendSwitchASCII(switches::kProxyBypassList, "list"); | 128 cl2.AppendSwitchASCII(switches::kProxyBypassList, "list"); |
123 TestCommandLinePrefStore store4(&cl2); | 129 scoped_refptr<TestCommandLinePrefStore> store4 = |
124 EXPECT_TRUE(store4.ProxySwitchesAreValid()); | 130 new TestCommandLinePrefStore(&cl2); |
| 131 EXPECT_TRUE(store4->ProxySwitchesAreValid()); |
125 } | 132 } |
126 | 133 |
127 TEST(CommandLinePrefStoreTest, ManualProxyModeInference) { | 134 TEST(CommandLinePrefStoreTest, ManualProxyModeInference) { |
128 CommandLine cl1(CommandLine::NO_PROGRAM); | 135 CommandLine cl1(CommandLine::NO_PROGRAM); |
129 cl1.AppendSwitch(unknown_string); | 136 cl1.AppendSwitch(unknown_string); |
130 cl1.AppendSwitchASCII(switches::kProxyServer, "proxy"); | 137 cl1.AppendSwitchASCII(switches::kProxyServer, "proxy"); |
131 TestCommandLinePrefStore store1(&cl1); | 138 scoped_refptr<TestCommandLinePrefStore> store1 = |
132 store1.VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_FIXED_SERVERS); | 139 new TestCommandLinePrefStore(&cl1); |
| 140 store1->VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_FIXED_SERVERS); |
133 | 141 |
134 CommandLine cl2(CommandLine::NO_PROGRAM); | 142 CommandLine cl2(CommandLine::NO_PROGRAM); |
135 cl2.AppendSwitchASCII(switches::kProxyPacUrl, "proxy"); | 143 cl2.AppendSwitchASCII(switches::kProxyPacUrl, "proxy"); |
136 TestCommandLinePrefStore store2(&cl2); | 144 scoped_refptr<TestCommandLinePrefStore> store2 = |
137 store2.VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_PAC_SCRIPT); | 145 new TestCommandLinePrefStore(&cl2); |
| 146 store2->VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_PAC_SCRIPT); |
138 } | 147 } |
OLD | NEW |