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

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: Fixed nits from Benjamin and a build failure 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
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..ab8259d9af2fd11193a6d68082ea684af0b1786f
--- /dev/null
+++ b/extensions/browser/api/vpn_provider/vpn_provider_apitest.cc
@@ -0,0 +1,94 @@
+// 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
+ {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\"]"
+ " }"
+ "]";
+
+ 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

Powered by Google App Engine
This is Rietveld 408576698