OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 "base/strings/stringprintf.h" | |
6 #include "extensions/browser/api/vpn_provider/vpn_provider_api.h" | |
7 #include "extensions/browser/api_test_utils.h" | |
8 #include "extensions/common/extension.h" | |
9 #include "extensions/common/test_util.h" | |
10 #include "extensions/shell/test/shell_test.h" | |
11 | |
12 using extensions::api_test_utils::RunFunctionAndReturnSingleResult; | |
13 using extensions::api_test_utils::RunFunctionAndReturnError; | |
14 | |
15 namespace extensions { | |
16 | |
17 const char* kErrorMessages[] = {"Address CIDR sanity check failed.", | |
18 "DNS server IP sanity check failed.", | |
19 "Unauthorized access."}; | |
20 | |
21 struct SetParameterTestParams { | |
22 int err_index; | |
23 const char* address; | |
24 const char* dns_server; | |
25 }; | |
26 | |
27 const SetParameterTestParams set_parameter_tests[] = { | |
28 {0, "1+++", ""}, /*+ not allowed*/ | |
not at google - send to devlin
2015/02/19 19:06:24
Use // comments not /* ?
kaliamoorthi
2015/02/20 10:33:21
Done.
| |
29 {0, "1", ""}, /*3 dots and separator missing*/ | |
30 {0, "1..", ""}, /*A dot and separator missing*/ | |
31 {0, "1...", ""}, /*Separator missing*/ | |
32 {0, "1.../", ""}, /*No digit after separator in address*/ | |
33 {1, "1.../0", ""}, /*Address passes sanity check, DNS incorrect*/ | |
34 {1, "1.../0", "1.../"}, /*DNS is not CIDR*/ | |
35 {2, "1.../0", "1..."}, /*Okay*/ | |
36 {0, ".../", "..."}, /*Address has no digits*/ | |
37 {0, "0.../", "..."}, /*Address has no digits post separator*/ | |
38 {1, "0.../0", "..."}, /*Address passes sanity check, DNS incorrect*/ | |
39 {2, "0.../0", "...0"}, /*Okay*/ | |
40 {0, "1...:::/1279abe", ""}, /*: not allowed for ipv4*/ | |
41 {0, "1.../1279abcde", ""}, /*hex not allowed after separator*/ | |
42 {0, "1...abcde/1279", ""}, /*hex not allowed in ipv4*/ | |
43 {1, "1.../1279", ""}, /*Address passes sanity check, DNS incorrect*/ | |
44 {2, "1.../1279", "1..."}, /*Okay*/ | |
45 {0, "1--++", ""}, /*+ and - not supported*/ | |
46 {0, "1.1.1.1", ""}, /*Missing separator*/ | |
47 {0, "1.1.1.1/", ""}, /*No digits after separator in address*/ | |
48 {1, "1.1.1.1/1", ""}, /*Address passes sanity check, DNS incorrect*/ | |
49 {2, "1.1.1.1/1", "1.1.1.1"}, /*Okay*/ | |
50 {0, "1.1.1./e", "1.1.1."}, /*Hex not okay in ipv4*/ | |
51 {2, "1.1.1./0", "1.1.1."}, /*Okay*/ | |
52 {1, "1.../1279", "..."}, /*No digits in DNS*/ | |
53 {1, "1.../1279", "e..."}, /*Hex not allowed in ipv4*/ | |
54 {2, "1.../1279", "4..."}, /*Okay*/ | |
55 }; | |
56 | |
57 class VpnProviderApiTest | |
58 : public AppShellTest, | |
59 public testing::WithParamInterface<const SetParameterTestParams*> {}; | |
60 | |
61 IN_PROC_BROWSER_TEST_P(VpnProviderApiTest, SetParametersFunction) { | |
62 scoped_refptr<extensions::VpnProviderSetParametersFunction> | |
63 set_parameter_function( | |
64 new extensions::VpnProviderSetParametersFunction()); | |
65 scoped_refptr<Extension> empty_extension = test_util::CreateEmptyExtension(); | |
66 | |
67 set_parameter_function->set_extension(empty_extension.get()); | |
68 set_parameter_function->set_has_callback(true); | |
69 | |
70 const std::string args = | |
71 "[" | |
72 " {" | |
73 " \"address\": \"%s\"," | |
74 " \"exclusionList\": []," | |
75 " \"inclusionList\": []," | |
76 " \"dnsServers\": [\"%s\"]" | |
77 " }" | |
78 "]"; | |
79 | |
80 LOG(ERROR) << "Address " << GetParam()->address; | |
81 LOG(ERROR) << "DNS servers " << GetParam()->dns_server; | |
82 LOG(ERROR) << "Expected message " << kErrorMessages[GetParam()->err_index]; | |
not at google - send to devlin
2015/02/19 19:06:24
Take out logging?
kaliamoorthi
2015/02/20 10:33:21
Done.
| |
83 | |
84 EXPECT_EQ(kErrorMessages[GetParam()->err_index], | |
85 RunFunctionAndReturnError( | |
86 set_parameter_function.get(), | |
87 base::StringPrintf(args.c_str(), GetParam()->address, | |
88 GetParam()->dns_server), | |
89 browser_context())); | |
90 } | |
91 | |
92 INSTANTIATE_TEST_CASE_P( | |
93 SetParameterTestParams, | |
94 VpnProviderApiTest, | |
95 testing::Range(&set_parameter_tests[0], | |
96 &set_parameter_tests[arraysize(set_parameter_tests)])); | |
97 | |
98 } // namespace extensions | |
OLD | NEW |