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

Unified Diff: components/update_client/utils_unittest.cc

Issue 2102083002: Allow component installers to specify a map of installer attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 6 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 | « components/update_client/utils.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/update_client/utils_unittest.cc
diff --git a/components/update_client/utils_unittest.cc b/components/update_client/utils_unittest.cc
index bd9246088b2615ea0584a19f28f4fea24c7aa4ae..5865419e67aeb16c636f37ce06bd7f6e23ff8c9c 100644
--- a/components/update_client/utils_unittest.cc
+++ b/components/update_client/utils_unittest.cc
@@ -75,33 +75,59 @@ TEST(UpdateClientUtils, IsValidBrand) {
EXPECT_FALSE(IsValidBrand(std::string("T ES"))); // Contains white space.
EXPECT_FALSE(IsValidBrand(std::string("<TE"))); // Has <.
EXPECT_FALSE(IsValidBrand(std::string("TE>"))); // Has >.
- EXPECT_FALSE(IsValidAp(std::string("\""))); // Has "
- EXPECT_FALSE(IsValidAp(std::string("\\"))); // Has backslash.
+ EXPECT_FALSE(IsValidBrand(std::string("\""))); // Has "
+ EXPECT_FALSE(IsValidBrand(std::string("\\"))); // Has backslash.
EXPECT_FALSE(IsValidBrand(std::string("\xaa"))); // Has non-ASCII char.
}
-// Tests that the ap matches ^[-+_=a-zA-Z0-9]{0,256}$
-TEST(UpdateClientUtils, IsValidAp) {
- EXPECT_TRUE(IsValidAp(std::string("a=1")));
- EXPECT_TRUE(IsValidAp(std::string("")));
- EXPECT_TRUE(IsValidAp(std::string("A")));
- EXPECT_TRUE(IsValidAp(std::string("Z")));
- EXPECT_TRUE(IsValidAp(std::string("a")));
- EXPECT_TRUE(IsValidAp(std::string("z")));
- EXPECT_TRUE(IsValidAp(std::string("0")));
- EXPECT_TRUE(IsValidAp(std::string("9")));
- EXPECT_TRUE(IsValidAp(std::string(256, 'a')));
- EXPECT_TRUE(IsValidAp(std::string("-+_=")));
-
- EXPECT_FALSE(IsValidAp(std::string(257, 'a'))); // Too long.
- EXPECT_FALSE(IsValidAp(std::string(" ap"))); // Begins with white space.
- EXPECT_FALSE(IsValidAp(std::string("ap "))); // Ends with white space.
- EXPECT_FALSE(IsValidAp(std::string("a p"))); // Contains white space.
- EXPECT_FALSE(IsValidAp(std::string("<ap"))); // Has <.
- EXPECT_FALSE(IsValidAp(std::string("ap>"))); // Has >.
- EXPECT_FALSE(IsValidAp(std::string("\""))); // Has "
- EXPECT_FALSE(IsValidAp(std::string("\\"))); // Has backspace.
- EXPECT_FALSE(IsValidAp(std::string("\xaa"))); // Has non-ASCII char.
+// Tests that the name of an InstallerAttribute matches ^[-_=a-zA-Z0-9]{1,256}$
+TEST(UpdateClientUtils, IsValidInstallerAttributeName) {
+ // Test the length boundaries.
+ EXPECT_FALSE(IsValidInstallerAttribute(
+ make_pair(std::string(0, 'a'), std::string("value"))));
+ EXPECT_TRUE(IsValidInstallerAttribute(
+ make_pair(std::string(1, 'a'), std::string("value"))));
+ EXPECT_TRUE(IsValidInstallerAttribute(
+ make_pair(std::string(256, 'a'), std::string("value"))));
+ EXPECT_FALSE(IsValidInstallerAttribute(
+ make_pair(std::string(257, 'a'), std::string("value"))));
+
+ const char* const valid_names[] = {"A", "Z", "a", "a-b", "A_B",
+ "z", "0", "9", "-_"};
+ for (const auto& name : valid_names)
+ EXPECT_TRUE(IsValidInstallerAttribute(
+ make_pair(std::string(name), std::string("value"))));
+
+ const char* const invalid_names[] = {
+ "", "a=1", " name", "name ", "na me", "<name", "name>",
+ "\"", "\\", "\xaa", ".", ",", ";", "+"};
+ for (const auto& name : invalid_names)
+ EXPECT_FALSE(IsValidInstallerAttribute(
+ make_pair(std::string(name), std::string("value"))));
+}
+
+// Tests that the value of an InstallerAttribute matches
+// ^[-.,;+_=a-zA-Z0-9]{0,256}$
+TEST(UpdateClientUtils, IsValidInstallerAttributeValue) {
+ // Test the length boundaries.
+ EXPECT_TRUE(IsValidInstallerAttribute(
+ make_pair(std::string("name"), std::string(0, 'a'))));
+ EXPECT_TRUE(IsValidInstallerAttribute(
+ make_pair(std::string("name"), std::string(256, 'a'))));
+ EXPECT_FALSE(IsValidInstallerAttribute(
+ make_pair(std::string("name"), std::string(257, 'a'))));
+
+ const char* const valid_values[] = {"", "a=1", "A", "Z", "a",
+ "z", "0", "9", "-.,;+_="};
+ for (const auto& value : valid_values)
+ EXPECT_TRUE(IsValidInstallerAttribute(
+ make_pair(std::string("name"), std::string(value))));
+
+ const char* const invalid_values[] = {" ap", "ap ", "a p", "<ap",
+ "ap>", "\"", "\\", "\xaa"};
+ for (const auto& value : invalid_values)
+ EXPECT_FALSE(IsValidInstallerAttribute(
+ make_pair(std::string("name"), std::string(value))));
}
TEST(UpdateClientUtils, RemoveUnsecureUrls) {
« no previous file with comments | « components/update_client/utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698