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

Side by Side Diff: components/proxy_config/proxy_config_dictionary_unittest.cc

Issue 2785883003: Use unique_ptr<DictionaryValue> in ProxyConfigDictionary (Closed)
Patch Set: Fix compilation Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2011 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 "components/proxy_config/proxy_config_dictionary.h" 5 #include "components/proxy_config/proxy_config_dictionary.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility>
9 10
10 #include "base/values.h" 11 #include "base/values.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 struct ProxyConfigHolder { 14 struct ProxyConfigHolder {
14 ProxyPrefs::ProxyMode mode; 15 ProxyPrefs::ProxyMode mode;
15 std::string pac_url; 16 std::string pac_url;
16 std::string proxy_server; 17 std::string proxy_server;
17 std::string bypass_list; 18 std::string bypass_list;
18 }; 19 };
19 20
20 TEST(ProxyConfigDictionaryTest, CreateDirect) { 21 TEST(ProxyConfigDictionaryTest, CreateDirect) {
21 std::unique_ptr<base::DictionaryValue> dict_value( 22 std::unique_ptr<base::DictionaryValue> dict_value =
22 ProxyConfigDictionary::CreateDirect()); 23 ProxyConfigDictionary::CreateDirect();
23 ProxyConfigDictionary dict(dict_value.get()); 24 ProxyConfigDictionary dict(std::move(dict_value));
24 ProxyConfigHolder h; 25 ProxyConfigHolder h;
25 26
26 ASSERT_TRUE(dict.GetMode(&h.mode)); 27 ASSERT_TRUE(dict.GetMode(&h.mode));
27 EXPECT_EQ(ProxyPrefs::MODE_DIRECT, h.mode); 28 EXPECT_EQ(ProxyPrefs::MODE_DIRECT, h.mode);
28 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list)); 29 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list));
29 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server)); 30 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server));
30 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list)); 31 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list));
31 } 32 }
32 33
33 TEST(ProxyConfigDictionaryTest, CreateAutoDetect) { 34 TEST(ProxyConfigDictionaryTest, CreateAutoDetect) {
34 std::unique_ptr<base::DictionaryValue> dict_value( 35 std::unique_ptr<base::DictionaryValue> dict_value =
35 ProxyConfigDictionary::CreateAutoDetect()); 36 ProxyConfigDictionary::CreateAutoDetect();
36 ProxyConfigDictionary dict(dict_value.get()); 37 ProxyConfigDictionary dict(std::move(dict_value));
37 ProxyConfigHolder h; 38 ProxyConfigHolder h;
38 39
39 ASSERT_TRUE(dict.GetMode(&h.mode)); 40 ASSERT_TRUE(dict.GetMode(&h.mode));
40 EXPECT_EQ(ProxyPrefs::MODE_AUTO_DETECT, h.mode); 41 EXPECT_EQ(ProxyPrefs::MODE_AUTO_DETECT, h.mode);
41 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list)); 42 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list));
42 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server)); 43 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server));
43 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list)); 44 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list));
44 } 45 }
45 46
46 TEST(ProxyConfigDictionaryTest, CreatePacScript) { 47 TEST(ProxyConfigDictionaryTest, CreatePacScript) {
47 std::unique_ptr<base::DictionaryValue> dict_value( 48 std::unique_ptr<base::DictionaryValue> dict_value =
48 ProxyConfigDictionary::CreatePacScript("pac", false)); 49 ProxyConfigDictionary::CreatePacScript("pac", false);
49 ProxyConfigDictionary dict(dict_value.get()); 50 ProxyConfigDictionary dict(std::move(dict_value));
50 ProxyConfigHolder h; 51 ProxyConfigHolder h;
51 52
52 ASSERT_TRUE(dict.GetMode(&h.mode)); 53 ASSERT_TRUE(dict.GetMode(&h.mode));
53 EXPECT_EQ(ProxyPrefs::MODE_PAC_SCRIPT, h.mode); 54 EXPECT_EQ(ProxyPrefs::MODE_PAC_SCRIPT, h.mode);
54 ASSERT_TRUE(dict.GetPacUrl(&h.bypass_list)); 55 ASSERT_TRUE(dict.GetPacUrl(&h.bypass_list));
55 EXPECT_EQ("pac", h.bypass_list); 56 EXPECT_EQ("pac", h.bypass_list);
56 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server)); 57 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server));
57 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list)); 58 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list));
58 } 59 }
59 60
60 TEST(ProxyConfigDictionaryTest, CreateFixedServers) { 61 TEST(ProxyConfigDictionaryTest, CreateFixedServers) {
61 std::unique_ptr<base::DictionaryValue> dict_value( 62 std::unique_ptr<base::DictionaryValue> dict_value =
62 ProxyConfigDictionary::CreateFixedServers("http://1.2.3.4", 63 ProxyConfigDictionary::CreateFixedServers("http://1.2.3.4", "http://foo");
63 "http://foo")); 64 ProxyConfigDictionary dict(std::move(dict_value));
64 ProxyConfigDictionary dict(dict_value.get());
65 ProxyConfigHolder h; 65 ProxyConfigHolder h;
66 66
67 ASSERT_TRUE(dict.GetMode(&h.mode)); 67 ASSERT_TRUE(dict.GetMode(&h.mode));
68 EXPECT_EQ(ProxyPrefs::MODE_FIXED_SERVERS, h.mode); 68 EXPECT_EQ(ProxyPrefs::MODE_FIXED_SERVERS, h.mode);
69 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list)); 69 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list));
70 ASSERT_TRUE(dict.GetProxyServer(&h.proxy_server)); 70 ASSERT_TRUE(dict.GetProxyServer(&h.proxy_server));
71 EXPECT_EQ("http://1.2.3.4", h.proxy_server); 71 EXPECT_EQ("http://1.2.3.4", h.proxy_server);
72 ASSERT_TRUE(dict.GetBypassList(&h.bypass_list)); 72 ASSERT_TRUE(dict.GetBypassList(&h.bypass_list));
73 EXPECT_EQ("http://foo", h.bypass_list); 73 EXPECT_EQ("http://foo", h.bypass_list);
74 } 74 }
75 75
76 TEST(ProxyConfigDictionaryTest, CreateSystem) { 76 TEST(ProxyConfigDictionaryTest, CreateSystem) {
77 std::unique_ptr<base::DictionaryValue> dict_value( 77 std::unique_ptr<base::DictionaryValue> dict_value =
78 ProxyConfigDictionary::CreateSystem()); 78 ProxyConfigDictionary::CreateSystem();
79 ProxyConfigDictionary dict(dict_value.get()); 79 ProxyConfigDictionary dict(std::move(dict_value));
80 ProxyConfigHolder h; 80 ProxyConfigHolder h;
81 81
82 ASSERT_TRUE(dict.GetMode(&h.mode)); 82 ASSERT_TRUE(dict.GetMode(&h.mode));
83 EXPECT_EQ(ProxyPrefs::MODE_SYSTEM, h.mode); 83 EXPECT_EQ(ProxyPrefs::MODE_SYSTEM, h.mode);
84 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list)); 84 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list));
85 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server)); 85 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server));
86 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list)); 86 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list));
87 } 87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698