| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 public: | 25 public: |
| 26 explicit TestCommandLinePrefStore(CommandLine* cl) | 26 explicit TestCommandLinePrefStore(CommandLine* cl) |
| 27 : CommandLinePrefStore(cl) {} | 27 : CommandLinePrefStore(cl) {} |
| 28 | 28 |
| 29 bool ProxySwitchesAreValid() { | 29 bool ProxySwitchesAreValid() { |
| 30 return ValidateProxySwitches(); | 30 return ValidateProxySwitches(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void VerifyProxyMode(ProxyPrefs::ProxyMode expected_mode) { | 33 void VerifyProxyMode(ProxyPrefs::ProxyMode expected_mode) { |
| 34 const Value* value = NULL; | 34 const Value* value = NULL; |
| 35 ASSERT_EQ(PrefStore::READ_OK, GetValue(prefs::kProxy, &value)); | 35 ASSERT_TRUE(GetValue(prefs::kProxy, &value)); |
| 36 ASSERT_EQ(Value::TYPE_DICTIONARY, value->GetType()); | 36 ASSERT_EQ(Value::TYPE_DICTIONARY, value->GetType()); |
| 37 ProxyConfigDictionary dict(static_cast<const DictionaryValue*>(value)); | 37 ProxyConfigDictionary dict(static_cast<const DictionaryValue*>(value)); |
| 38 ProxyPrefs::ProxyMode actual_mode; | 38 ProxyPrefs::ProxyMode actual_mode; |
| 39 ASSERT_TRUE(dict.GetMode(&actual_mode)); | 39 ASSERT_TRUE(dict.GetMode(&actual_mode)); |
| 40 EXPECT_EQ(expected_mode, actual_mode); | 40 EXPECT_EQ(expected_mode, actual_mode); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void VerifySSLCipherSuites(const char* const* ciphers, | 43 void VerifySSLCipherSuites(const char* const* ciphers, |
| 44 size_t cipher_count) { | 44 size_t cipher_count) { |
| 45 const Value* value = NULL; | 45 const Value* value = NULL; |
| 46 ASSERT_EQ(PrefStore::READ_OK, | 46 ASSERT_TRUE(GetValue(prefs::kCipherSuiteBlacklist, &value)); |
| 47 GetValue(prefs::kCipherSuiteBlacklist, &value)); | |
| 48 ASSERT_EQ(Value::TYPE_LIST, value->GetType()); | 47 ASSERT_EQ(Value::TYPE_LIST, value->GetType()); |
| 49 const ListValue* list_value = static_cast<const ListValue*>(value); | 48 const ListValue* list_value = static_cast<const ListValue*>(value); |
| 50 ASSERT_EQ(cipher_count, list_value->GetSize()); | 49 ASSERT_EQ(cipher_count, list_value->GetSize()); |
| 51 | 50 |
| 52 std::string cipher_string; | 51 std::string cipher_string; |
| 53 for (ListValue::const_iterator it = list_value->begin(); | 52 for (ListValue::const_iterator it = list_value->begin(); |
| 54 it != list_value->end(); ++it, ++ciphers) { | 53 it != list_value->end(); ++it, ++ciphers) { |
| 55 ASSERT_TRUE((*it)->GetAsString(&cipher_string)); | 54 ASSERT_TRUE((*it)->GetAsString(&cipher_string)); |
| 56 EXPECT_EQ(*ciphers, cipher_string); | 55 EXPECT_EQ(*ciphers, cipher_string); |
| 57 } | 56 } |
| 58 } | 57 } |
| 59 | 58 |
| 60 private: | 59 private: |
| 61 virtual ~TestCommandLinePrefStore() {} | 60 virtual ~TestCommandLinePrefStore() {} |
| 62 }; | 61 }; |
| 63 | 62 |
| 64 // Tests a simple string pref on the command line. | 63 // Tests a simple string pref on the command line. |
| 65 TEST(CommandLinePrefStoreTest, SimpleStringPref) { | 64 TEST(CommandLinePrefStoreTest, SimpleStringPref) { |
| 66 CommandLine cl(CommandLine::NO_PROGRAM); | 65 CommandLine cl(CommandLine::NO_PROGRAM); |
| 67 cl.AppendSwitchASCII(switches::kLang, "hi-MOM"); | 66 cl.AppendSwitchASCII(switches::kLang, "hi-MOM"); |
| 68 scoped_refptr<CommandLinePrefStore> store = new CommandLinePrefStore(&cl); | 67 scoped_refptr<CommandLinePrefStore> store = new CommandLinePrefStore(&cl); |
| 69 | 68 |
| 70 const Value* actual = NULL; | 69 const Value* actual = NULL; |
| 71 EXPECT_EQ(PrefStore::READ_OK, | 70 EXPECT_TRUE(store->GetValue(prefs::kApplicationLocale, &actual)); |
| 72 store->GetValue(prefs::kApplicationLocale, &actual)); | |
| 73 std::string result; | 71 std::string result; |
| 74 EXPECT_TRUE(actual->GetAsString(&result)); | 72 EXPECT_TRUE(actual->GetAsString(&result)); |
| 75 EXPECT_EQ("hi-MOM", result); | 73 EXPECT_EQ("hi-MOM", result); |
| 76 } | 74 } |
| 77 | 75 |
| 78 // Tests a simple boolean pref on the command line. | 76 // Tests a simple boolean pref on the command line. |
| 79 TEST(CommandLinePrefStoreTest, SimpleBooleanPref) { | 77 TEST(CommandLinePrefStoreTest, SimpleBooleanPref) { |
| 80 CommandLine cl(CommandLine::NO_PROGRAM); | 78 CommandLine cl(CommandLine::NO_PROGRAM); |
| 81 cl.AppendSwitch(switches::kNoProxyServer); | 79 cl.AppendSwitch(switches::kNoProxyServer); |
| 82 scoped_refptr<TestCommandLinePrefStore> store = | 80 scoped_refptr<TestCommandLinePrefStore> store = |
| 83 new TestCommandLinePrefStore(&cl); | 81 new TestCommandLinePrefStore(&cl); |
| 84 | 82 |
| 85 store->VerifyProxyMode(ProxyPrefs::MODE_DIRECT); | 83 store->VerifyProxyMode(ProxyPrefs::MODE_DIRECT); |
| 86 } | 84 } |
| 87 | 85 |
| 88 // Tests a command line with no recognized prefs. | 86 // Tests a command line with no recognized prefs. |
| 89 TEST(CommandLinePrefStoreTest, NoPrefs) { | 87 TEST(CommandLinePrefStoreTest, NoPrefs) { |
| 90 CommandLine cl(CommandLine::NO_PROGRAM); | 88 CommandLine cl(CommandLine::NO_PROGRAM); |
| 91 cl.AppendSwitch(unknown_string); | 89 cl.AppendSwitch(unknown_string); |
| 92 cl.AppendSwitchASCII(unknown_bool, "a value"); | 90 cl.AppendSwitchASCII(unknown_bool, "a value"); |
| 93 scoped_refptr<CommandLinePrefStore> store = new CommandLinePrefStore(&cl); | 91 scoped_refptr<CommandLinePrefStore> store = new CommandLinePrefStore(&cl); |
| 94 | 92 |
| 95 const Value* actual = NULL; | 93 const Value* actual = NULL; |
| 96 EXPECT_EQ(PrefStore::READ_NO_VALUE, store->GetValue(unknown_bool, &actual)); | 94 EXPECT_FALSE(store->GetValue(unknown_bool, &actual)); |
| 97 EXPECT_EQ(PrefStore::READ_NO_VALUE, store->GetValue(unknown_string, &actual)); | 95 EXPECT_FALSE(store->GetValue(unknown_string, &actual)); |
| 98 } | 96 } |
| 99 | 97 |
| 100 // Tests a complex command line with multiple known and unknown switches. | 98 // Tests a complex command line with multiple known and unknown switches. |
| 101 TEST(CommandLinePrefStoreTest, MultipleSwitches) { | 99 TEST(CommandLinePrefStoreTest, MultipleSwitches) { |
| 102 CommandLine cl(CommandLine::NO_PROGRAM); | 100 CommandLine cl(CommandLine::NO_PROGRAM); |
| 103 cl.AppendSwitch(unknown_string); | 101 cl.AppendSwitch(unknown_string); |
| 104 cl.AppendSwitchASCII(switches::kProxyServer, "proxy"); | 102 cl.AppendSwitchASCII(switches::kProxyServer, "proxy"); |
| 105 cl.AppendSwitchASCII(switches::kProxyBypassList, "list"); | 103 cl.AppendSwitchASCII(switches::kProxyBypassList, "list"); |
| 106 cl.AppendSwitchASCII(unknown_bool, "a value"); | 104 cl.AppendSwitchASCII(unknown_bool, "a value"); |
| 107 scoped_refptr<TestCommandLinePrefStore> store = | 105 scoped_refptr<TestCommandLinePrefStore> store = |
| 108 new TestCommandLinePrefStore(&cl); | 106 new TestCommandLinePrefStore(&cl); |
| 109 | 107 |
| 110 const Value* actual = NULL; | 108 const Value* actual = NULL; |
| 111 EXPECT_EQ(PrefStore::READ_NO_VALUE, store->GetValue(unknown_bool, &actual)); | 109 EXPECT_FALSE(store->GetValue(unknown_bool, &actual)); |
| 112 EXPECT_EQ(PrefStore::READ_NO_VALUE, store->GetValue(unknown_string, &actual)); | 110 EXPECT_FALSE(store->GetValue(unknown_string, &actual)); |
| 113 | 111 |
| 114 store->VerifyProxyMode(ProxyPrefs::MODE_FIXED_SERVERS); | 112 store->VerifyProxyMode(ProxyPrefs::MODE_FIXED_SERVERS); |
| 115 | 113 |
| 116 const Value* value = NULL; | 114 const Value* value = NULL; |
| 117 ASSERT_EQ(PrefStore::READ_OK, store->GetValue(prefs::kProxy, &value)); | 115 ASSERT_TRUE(store->GetValue(prefs::kProxy, &value)); |
| 118 ASSERT_EQ(Value::TYPE_DICTIONARY, value->GetType()); | 116 ASSERT_EQ(Value::TYPE_DICTIONARY, value->GetType()); |
| 119 ProxyConfigDictionary dict(static_cast<const DictionaryValue*>(value)); | 117 ProxyConfigDictionary dict(static_cast<const DictionaryValue*>(value)); |
| 120 | 118 |
| 121 std::string string_result = ""; | 119 std::string string_result = ""; |
| 122 | 120 |
| 123 ASSERT_TRUE(dict.GetProxyServer(&string_result)); | 121 ASSERT_TRUE(dict.GetProxyServer(&string_result)); |
| 124 EXPECT_EQ("proxy", string_result); | 122 EXPECT_EQ("proxy", string_result); |
| 125 | 123 |
| 126 ASSERT_TRUE(dict.GetBypassList(&string_result)); | 124 ASSERT_TRUE(dict.GetBypassList(&string_result)); |
| 127 EXPECT_EQ("list", string_result); | 125 EXPECT_EQ("list", string_result); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 cl3.AppendSwitchASCII(switches::kCipherSuiteBlacklist, | 208 cl3.AppendSwitchASCII(switches::kCipherSuiteBlacklist, |
| 211 "0x0004;MOAR;0x0005"); | 209 "0x0004;MOAR;0x0005"); |
| 212 scoped_refptr<TestCommandLinePrefStore> store3 = | 210 scoped_refptr<TestCommandLinePrefStore> store3 = |
| 213 new TestCommandLinePrefStore(&cl3); | 211 new TestCommandLinePrefStore(&cl3); |
| 214 const char* const expected_ciphers3[] = { | 212 const char* const expected_ciphers3[] = { |
| 215 "0x0004;MOAR;0x0005" | 213 "0x0004;MOAR;0x0005" |
| 216 }; | 214 }; |
| 217 store3->VerifySSLCipherSuites(expected_ciphers3, | 215 store3->VerifySSLCipherSuites(expected_ciphers3, |
| 218 arraysize(expected_ciphers3)); | 216 arraysize(expected_ciphers3)); |
| 219 } | 217 } |
| OLD | NEW |