Home | History | Annotate | Download | only in prefs
      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
      3 // found in the LICENSE file.
      4 
      5 #include <string>
      6 
      7 #include "base/values.h"
      8 #include "chrome/browser/prefs/proxy_prefs.h"
      9 #include "testing/gtest/include/gtest/gtest.h"
     10 
     11 TEST(ProxyPrefsTest, StringToProxyMode) {
     12   ProxyPrefs::ProxyMode mode;
     13   EXPECT_TRUE(ProxyPrefs::StringToProxyMode("direct", &mode));
     14   EXPECT_EQ(ProxyPrefs::MODE_DIRECT, mode);
     15   EXPECT_TRUE(ProxyPrefs::StringToProxyMode("auto_detect", &mode));
     16   EXPECT_EQ(ProxyPrefs::MODE_AUTO_DETECT, mode);
     17   EXPECT_TRUE(ProxyPrefs::StringToProxyMode("pac_script", &mode));
     18   EXPECT_EQ(ProxyPrefs::MODE_PAC_SCRIPT, mode);
     19   EXPECT_TRUE(ProxyPrefs::StringToProxyMode("system", &mode));
     20   EXPECT_EQ(ProxyPrefs::MODE_SYSTEM, mode);
     21   EXPECT_TRUE(ProxyPrefs::StringToProxyMode("fixed_servers", &mode));
     22   EXPECT_EQ(ProxyPrefs::MODE_FIXED_SERVERS, mode);
     23 
     24   EXPECT_FALSE(ProxyPrefs::StringToProxyMode("monkey", &mode));
     25 }
     26 
     27 TEST(ProxyPrefsTest, IntToProxyMode) {
     28   ASSERT_EQ(ProxyPrefs::MODE_DIRECT, 0);
     29   ASSERT_EQ(ProxyPrefs::MODE_AUTO_DETECT, 1);
     30   ASSERT_EQ(ProxyPrefs::MODE_PAC_SCRIPT, 2);
     31   ASSERT_EQ(ProxyPrefs::MODE_FIXED_SERVERS, 3);
     32   ASSERT_EQ(ProxyPrefs::MODE_SYSTEM, 4);
     33   // Update the following as necessary, don't change the previous ones.
     34   ASSERT_EQ(ProxyPrefs::kModeCount, 5);
     35 
     36   ProxyPrefs::ProxyMode mode;
     37   EXPECT_TRUE(ProxyPrefs::IntToProxyMode(0, &mode));
     38   EXPECT_EQ(ProxyPrefs::MODE_DIRECT, mode);
     39   EXPECT_TRUE(ProxyPrefs::IntToProxyMode(1, &mode));
     40   EXPECT_EQ(ProxyPrefs::MODE_AUTO_DETECT, mode);
     41   EXPECT_TRUE(ProxyPrefs::IntToProxyMode(2, &mode));
     42   EXPECT_EQ(ProxyPrefs::MODE_PAC_SCRIPT, mode);
     43   EXPECT_TRUE(ProxyPrefs::IntToProxyMode(3, &mode));
     44   EXPECT_EQ(ProxyPrefs::MODE_FIXED_SERVERS, mode);
     45   EXPECT_TRUE(ProxyPrefs::IntToProxyMode(4, &mode));
     46   EXPECT_EQ(ProxyPrefs::MODE_SYSTEM, mode);
     47 
     48   EXPECT_FALSE(ProxyPrefs::IntToProxyMode(-1, &mode));
     49   EXPECT_FALSE(ProxyPrefs::IntToProxyMode(ProxyPrefs::kModeCount, &mode));
     50 }
     51