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

Unified Diff: extensions/browser/api/vpn_provider/vpn_provider_apitest.cc

Issue 932063003: Add split tunnel interface to vpnProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replaced certain strings with equivalent constants Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/browser/api/vpn_provider/vpn_provider_api.cc ('k') | extensions/common/api/vpn_provider.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/api/vpn_provider/vpn_provider_apitest.cc
diff --git a/extensions/browser/api/vpn_provider/vpn_provider_apitest.cc b/extensions/browser/api/vpn_provider/vpn_provider_apitest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2d865979dd8e3e8271be0f03dce81bdccaaf1874
--- /dev/null
+++ b/extensions/browser/api/vpn_provider/vpn_provider_apitest.cc
@@ -0,0 +1,98 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/strings/stringprintf.h"
+#include "extensions/browser/api/vpn_provider/vpn_provider_api.h"
+#include "extensions/browser/api_test_utils.h"
+#include "extensions/common/extension.h"
+#include "extensions/common/test_util.h"
+#include "extensions/shell/test/shell_test.h"
+
+using extensions::api_test_utils::RunFunctionAndReturnSingleResult;
+using extensions::api_test_utils::RunFunctionAndReturnError;
+
+namespace extensions {
+
+const char* kErrorMessages[] = {"Address CIDR sanity check failed.",
+ "DNS server IP sanity check failed.",
+ "Unauthorized access."};
+
+struct SetParameterTestParams {
+ int err_index;
+ const char* address;
+ const char* dns_server;
+};
+
+const SetParameterTestParams set_parameter_tests[] = {
+ {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.
+ {0, "1", ""}, /*3 dots and separator missing*/
+ {0, "1..", ""}, /*A dot and separator missing*/
+ {0, "1...", ""}, /*Separator missing*/
+ {0, "1.../", ""}, /*No digit after separator in address*/
+ {1, "1.../0", ""}, /*Address passes sanity check, DNS incorrect*/
+ {1, "1.../0", "1.../"}, /*DNS is not CIDR*/
+ {2, "1.../0", "1..."}, /*Okay*/
+ {0, ".../", "..."}, /*Address has no digits*/
+ {0, "0.../", "..."}, /*Address has no digits post separator*/
+ {1, "0.../0", "..."}, /*Address passes sanity check, DNS incorrect*/
+ {2, "0.../0", "...0"}, /*Okay*/
+ {0, "1...:::/1279abe", ""}, /*: not allowed for ipv4*/
+ {0, "1.../1279abcde", ""}, /*hex not allowed after separator*/
+ {0, "1...abcde/1279", ""}, /*hex not allowed in ipv4*/
+ {1, "1.../1279", ""}, /*Address passes sanity check, DNS incorrect*/
+ {2, "1.../1279", "1..."}, /*Okay*/
+ {0, "1--++", ""}, /*+ and - not supported*/
+ {0, "1.1.1.1", ""}, /*Missing separator*/
+ {0, "1.1.1.1/", ""}, /*No digits after separator in address*/
+ {1, "1.1.1.1/1", ""}, /*Address passes sanity check, DNS incorrect*/
+ {2, "1.1.1.1/1", "1.1.1.1"}, /*Okay*/
+ {0, "1.1.1./e", "1.1.1."}, /*Hex not okay in ipv4*/
+ {2, "1.1.1./0", "1.1.1."}, /*Okay*/
+ {1, "1.../1279", "..."}, /*No digits in DNS*/
+ {1, "1.../1279", "e..."}, /*Hex not allowed in ipv4*/
+ {2, "1.../1279", "4..."}, /*Okay*/
+};
+
+class VpnProviderApiTest
+ : public AppShellTest,
+ public testing::WithParamInterface<const SetParameterTestParams*> {};
+
+IN_PROC_BROWSER_TEST_P(VpnProviderApiTest, SetParametersFunction) {
+ scoped_refptr<extensions::VpnProviderSetParametersFunction>
+ set_parameter_function(
+ new extensions::VpnProviderSetParametersFunction());
+ scoped_refptr<Extension> empty_extension = test_util::CreateEmptyExtension();
+
+ set_parameter_function->set_extension(empty_extension.get());
+ set_parameter_function->set_has_callback(true);
+
+ const std::string args =
+ "["
+ " {"
+ " \"address\": \"%s\","
+ " \"exclusionList\": [],"
+ " \"inclusionList\": [],"
+ " \"dnsServers\": [\"%s\"]"
+ " }"
+ "]";
+
+ LOG(ERROR) << "Address " << GetParam()->address;
+ LOG(ERROR) << "DNS servers " << GetParam()->dns_server;
+ 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.
+
+ EXPECT_EQ(kErrorMessages[GetParam()->err_index],
+ RunFunctionAndReturnError(
+ set_parameter_function.get(),
+ base::StringPrintf(args.c_str(), GetParam()->address,
+ GetParam()->dns_server),
+ browser_context()));
+}
+
+INSTANTIATE_TEST_CASE_P(
+ SetParameterTestParams,
+ VpnProviderApiTest,
+ testing::Range(&set_parameter_tests[0],
+ &set_parameter_tests[arraysize(set_parameter_tests)]));
+
+} // namespace extensions
« no previous file with comments | « extensions/browser/api/vpn_provider/vpn_provider_api.cc ('k') | extensions/common/api/vpn_provider.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698