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

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

Issue 5915004: Introduce incognito preference settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed whitespaces in mac files Created 9 years, 11 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
OLDNEW
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 #include "ui/base/ui_base_switches.h" 16 #include "ui/base/ui_base_switches.h"
16 17
17 namespace { 18 namespace {
18 19
(...skipping 15 matching lines...) Expand all
34 35
35 const char unknown_bool[] = "unknown_switch"; 36 const char unknown_bool[] = "unknown_switch";
36 const char unknown_string[] = "unknown_other_switch"; 37 const char unknown_string[] = "unknown_other_switch";
37 38
38 } // namespace 39 } // namespace
39 40
40 // Tests a simple string pref on the command line. 41 // Tests a simple string pref on the command line.
41 TEST(CommandLinePrefStoreTest, SimpleStringPref) { 42 TEST(CommandLinePrefStoreTest, SimpleStringPref) {
42 CommandLine cl(CommandLine::NO_PROGRAM); 43 CommandLine cl(CommandLine::NO_PROGRAM);
43 cl.AppendSwitchASCII(switches::kLang, "hi-MOM"); 44 cl.AppendSwitchASCII(switches::kLang, "hi-MOM");
44 CommandLinePrefStore store(&cl); 45 scoped_refptr<CommandLinePrefStore> store = new CommandLinePrefStore(&cl);
45 46
46 Value* actual = NULL; 47 Value* actual = NULL;
47 EXPECT_EQ(PrefStore::READ_OK, 48 EXPECT_EQ(PrefStore::READ_OK,
48 store.GetValue(prefs::kApplicationLocale, &actual)); 49 store->GetValue(prefs::kApplicationLocale, &actual));
49 std::string result; 50 std::string result;
50 EXPECT_TRUE(actual->GetAsString(&result)); 51 EXPECT_TRUE(actual->GetAsString(&result));
51 EXPECT_EQ("hi-MOM", result); 52 EXPECT_EQ("hi-MOM", result);
52 } 53 }
53 54
54 // Tests a simple boolean pref on the command line. 55 // Tests a simple boolean pref on the command line.
55 TEST(CommandLinePrefStoreTest, SimpleBooleanPref) { 56 TEST(CommandLinePrefStoreTest, SimpleBooleanPref) {
56 CommandLine cl(CommandLine::NO_PROGRAM); 57 CommandLine cl(CommandLine::NO_PROGRAM);
57 cl.AppendSwitch(switches::kNoProxyServer); 58 cl.AppendSwitch(switches::kNoProxyServer);
58 TestCommandLinePrefStore store(&cl); 59 scoped_refptr<TestCommandLinePrefStore> store =
60 new TestCommandLinePrefStore(&cl);
59 61
60 store.VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_DIRECT); 62 store->VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_DIRECT);
61 } 63 }
62 64
63 // Tests a command line with no recognized prefs. 65 // Tests a command line with no recognized prefs.
64 TEST(CommandLinePrefStoreTest, NoPrefs) { 66 TEST(CommandLinePrefStoreTest, NoPrefs) {
65 CommandLine cl(CommandLine::NO_PROGRAM); 67 CommandLine cl(CommandLine::NO_PROGRAM);
66 cl.AppendSwitch(unknown_string); 68 cl.AppendSwitch(unknown_string);
67 cl.AppendSwitchASCII(unknown_bool, "a value"); 69 cl.AppendSwitchASCII(unknown_bool, "a value");
68 CommandLinePrefStore store(&cl); 70 scoped_refptr<CommandLinePrefStore> store = new CommandLinePrefStore(&cl);
69 71
70 Value* actual = NULL; 72 Value* actual = NULL;
71 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_bool, &actual)); 73 EXPECT_EQ(PrefStore::READ_NO_VALUE, store->GetValue(unknown_bool, &actual));
72 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_string, &actual)); 74 EXPECT_EQ(PrefStore::READ_NO_VALUE, store->GetValue(unknown_string, &actual));
73 } 75 }
74 76
75 // Tests a complex command line with multiple known and unknown switches. 77 // Tests a complex command line with multiple known and unknown switches.
76 TEST(CommandLinePrefStoreTest, MultipleSwitches) { 78 TEST(CommandLinePrefStoreTest, MultipleSwitches) {
77 CommandLine cl(CommandLine::NO_PROGRAM); 79 CommandLine cl(CommandLine::NO_PROGRAM);
78 cl.AppendSwitch(unknown_string); 80 cl.AppendSwitch(unknown_string);
79 cl.AppendSwitch(switches::kProxyAutoDetect); 81 cl.AppendSwitch(switches::kProxyAutoDetect);
80 cl.AppendSwitchASCII(switches::kProxyServer, "proxy"); 82 cl.AppendSwitchASCII(switches::kProxyServer, "proxy");
81 cl.AppendSwitchASCII(switches::kProxyBypassList, "list"); 83 cl.AppendSwitchASCII(switches::kProxyBypassList, "list");
82 cl.AppendSwitchASCII(unknown_bool, "a value"); 84 cl.AppendSwitchASCII(unknown_bool, "a value");
83 TestCommandLinePrefStore store(&cl); 85 scoped_refptr<TestCommandLinePrefStore> store =
86 new TestCommandLinePrefStore(&cl);
84 87
85 Value* actual = NULL; 88 Value* actual = NULL;
86 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_bool, &actual)); 89 EXPECT_EQ(PrefStore::READ_NO_VALUE, store->GetValue(unknown_bool, &actual));
87 store.VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_AUTO_DETECT); 90 store->VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_AUTO_DETECT);
88 91
89 EXPECT_EQ(PrefStore::READ_NO_VALUE, store.GetValue(unknown_string, &actual)); 92 EXPECT_EQ(PrefStore::READ_NO_VALUE, store->GetValue(unknown_string, &actual));
90 std::string string_result = ""; 93 std::string string_result = "";
91 ASSERT_EQ(PrefStore::READ_OK, store.GetValue(prefs::kProxyServer, &actual)); 94 ASSERT_EQ(PrefStore::READ_OK, store->GetValue(prefs::kProxyServer, &actual));
92 EXPECT_TRUE(actual->GetAsString(&string_result)); 95 EXPECT_TRUE(actual->GetAsString(&string_result));
93 EXPECT_EQ("proxy", string_result); 96 EXPECT_EQ("proxy", string_result);
94 ASSERT_EQ(PrefStore::READ_OK, 97 ASSERT_EQ(PrefStore::READ_OK,
95 store.GetValue(prefs::kProxyBypassList, &actual)); 98 store->GetValue(prefs::kProxyBypassList, &actual));
96 EXPECT_TRUE(actual->GetAsString(&string_result)); 99 EXPECT_TRUE(actual->GetAsString(&string_result));
97 EXPECT_EQ("list", string_result); 100 EXPECT_EQ("list", string_result);
98 } 101 }
99 102
100 // Tests proxy switch validation. 103 // Tests proxy switch validation.
101 TEST(CommandLinePrefStoreTest, ProxySwitchValidation) { 104 TEST(CommandLinePrefStoreTest, ProxySwitchValidation) {
102 CommandLine cl(CommandLine::NO_PROGRAM); 105 CommandLine cl(CommandLine::NO_PROGRAM);
103 106
104 // No switches. 107 // No switches.
105 TestCommandLinePrefStore store(&cl); 108 scoped_refptr<TestCommandLinePrefStore> store =
106 EXPECT_TRUE(store.ProxySwitchesAreValid()); 109 new TestCommandLinePrefStore(&cl);
110 EXPECT_TRUE(store->ProxySwitchesAreValid());
107 111
108 // Only no-proxy. 112 // Only no-proxy.
109 cl.AppendSwitch(switches::kNoProxyServer); 113 cl.AppendSwitch(switches::kNoProxyServer);
110 TestCommandLinePrefStore store2(&cl); 114 scoped_refptr<TestCommandLinePrefStore> store2 =
111 EXPECT_TRUE(store2.ProxySwitchesAreValid()); 115 new TestCommandLinePrefStore(&cl);
116 EXPECT_TRUE(store2->ProxySwitchesAreValid());
112 117
113 // Another proxy switch too. 118 // Another proxy switch too.
114 cl.AppendSwitch(switches::kProxyAutoDetect); 119 cl.AppendSwitch(switches::kProxyAutoDetect);
115 TestCommandLinePrefStore store3(&cl); 120 scoped_refptr<TestCommandLinePrefStore> store3 =
116 EXPECT_FALSE(store3.ProxySwitchesAreValid()); 121 new TestCommandLinePrefStore(&cl);
122 EXPECT_FALSE(store3->ProxySwitchesAreValid());
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 scoped_refptr<TestCommandLinePrefStore> store4 =
125 EXPECT_TRUE(store4.ProxySwitchesAreValid()); 131 new TestCommandLinePrefStore(&cl2);
132 EXPECT_TRUE(store4->ProxySwitchesAreValid());
126 } 133 }
127 134
128 TEST(CommandLinePrefStoreTest, ManualProxyModeInference) { 135 TEST(CommandLinePrefStoreTest, ManualProxyModeInference) {
129 CommandLine cl1(CommandLine::NO_PROGRAM); 136 CommandLine cl1(CommandLine::NO_PROGRAM);
130 cl1.AppendSwitch(unknown_string); 137 cl1.AppendSwitch(unknown_string);
131 cl1.AppendSwitchASCII(switches::kProxyServer, "proxy"); 138 cl1.AppendSwitchASCII(switches::kProxyServer, "proxy");
132 TestCommandLinePrefStore store1(&cl1); 139 scoped_refptr<TestCommandLinePrefStore> store1 =
133 store1.VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_FIXED_SERVERS); 140 new TestCommandLinePrefStore(&cl1);
141 store1->VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_FIXED_SERVERS);
134 142
135 CommandLine cl2(CommandLine::NO_PROGRAM); 143 CommandLine cl2(CommandLine::NO_PROGRAM);
136 cl2.AppendSwitchASCII(switches::kProxyPacUrl, "proxy"); 144 cl2.AppendSwitchASCII(switches::kProxyPacUrl, "proxy");
137 TestCommandLinePrefStore store2(&cl2); 145 scoped_refptr<TestCommandLinePrefStore> store2 =
138 store2.VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_PAC_SCRIPT); 146 new TestCommandLinePrefStore(&cl2);
147 store2->VerifyIntPref(prefs::kProxyMode, ProxyPrefs::MODE_PAC_SCRIPT);
139 } 148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698