OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "components/update_client/utils.h" | 7 #include "components/update_client/utils.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "url/gurl.h" | 9 #include "url/gurl.h" |
10 | 10 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 EXPECT_FALSE(IsValidBrand(std::string("TESTS"))); // Too long. | 74 EXPECT_FALSE(IsValidBrand(std::string("TESTS"))); // Too long. |
75 EXPECT_FALSE(IsValidBrand(std::string("TES1"))); // Has digit. | 75 EXPECT_FALSE(IsValidBrand(std::string("TES1"))); // Has digit. |
76 EXPECT_FALSE(IsValidBrand(std::string(" TES"))); // Begins with white space. | 76 EXPECT_FALSE(IsValidBrand(std::string(" TES"))); // Begins with white space. |
77 EXPECT_FALSE(IsValidBrand(std::string("TES "))); // Ends with white space. | 77 EXPECT_FALSE(IsValidBrand(std::string("TES "))); // Ends with white space. |
78 EXPECT_FALSE(IsValidBrand(std::string("T ES"))); // Contains white space. | 78 EXPECT_FALSE(IsValidBrand(std::string("T ES"))); // Contains white space. |
79 EXPECT_FALSE(IsValidBrand(std::string("<TE"))); // Has <. | 79 EXPECT_FALSE(IsValidBrand(std::string("<TE"))); // Has <. |
80 EXPECT_FALSE(IsValidBrand(std::string("TE>"))); // Has >. | 80 EXPECT_FALSE(IsValidBrand(std::string("TE>"))); // Has >. |
81 EXPECT_FALSE(IsValidBrand(std::string("\xaa"))); // Has non-ASCII char. | 81 EXPECT_FALSE(IsValidBrand(std::string("\xaa"))); // Has non-ASCII char. |
82 } | 82 } |
83 | 83 |
84 // Tests that the ap matches ^([-+_=a-zA-Z0-9]{0,256})$ | |
85 TEST(UpdateClientUtils, IsValidAp) { | |
86 EXPECT_TRUE(IsValidAp(std::string("a=1"))); | |
87 EXPECT_TRUE(IsValidAp(std::string(""))); | |
88 EXPECT_TRUE(IsValidAp(std::string("A"))); | |
89 EXPECT_TRUE(IsValidAp(std::string("Z"))); | |
90 EXPECT_TRUE(IsValidAp(std::string("a"))); | |
91 EXPECT_TRUE(IsValidAp(std::string("z"))); | |
92 EXPECT_TRUE(IsValidAp(std::string("0"))); | |
93 EXPECT_TRUE(IsValidAp(std::string("9"))); | |
94 EXPECT_TRUE(IsValidAp(std::string(256, 'a'))); | |
95 EXPECT_TRUE(IsValidAp(std::string("-+_="))); | |
96 | |
97 EXPECT_FALSE(IsValidAp(std::string(257, 'a'))); // Too long. | |
98 EXPECT_FALSE(IsValidAp(std::string(" ap"))); // Begins with white space. | |
99 EXPECT_FALSE(IsValidAp(std::string("ap "))); // Ends with white space. | |
100 EXPECT_FALSE(IsValidAp(std::string("a p"))); // Contains white space. | |
101 EXPECT_FALSE(IsValidAp(std::string("<ap"))); // Has <. | |
102 EXPECT_FALSE(IsValidAp(std::string("ap>"))); // Has >. | |
103 EXPECT_FALSE(IsValidAp(std::string("\xaa"))); // Has non-ASCII char. | |
waffles
2016/04/08 21:06:16
Please add a test for " and \ as well.
Sorin Jianu
2016/04/08 21:13:42
Done.
| |
104 } | |
105 | |
84 TEST(UpdateClientUtils, RemoveUnsecureUrls) { | 106 TEST(UpdateClientUtils, RemoveUnsecureUrls) { |
85 const GURL test1[] = {GURL("http://foo"), GURL("https://foo")}; | 107 const GURL test1[] = {GURL("http://foo"), GURL("https://foo")}; |
86 std::vector<GURL> urls(std::begin(test1), std::end(test1)); | 108 std::vector<GURL> urls(std::begin(test1), std::end(test1)); |
87 RemoveUnsecureUrls(&urls); | 109 RemoveUnsecureUrls(&urls); |
88 EXPECT_EQ(1u, urls.size()); | 110 EXPECT_EQ(1u, urls.size()); |
89 EXPECT_EQ(urls[0], GURL("https://foo")); | 111 EXPECT_EQ(urls[0], GURL("https://foo")); |
90 | 112 |
91 const GURL test2[] = {GURL("https://foo"), GURL("http://foo")}; | 113 const GURL test2[] = {GURL("https://foo"), GURL("http://foo")}; |
92 urls.assign(std::begin(test2), std::end(test2)); | 114 urls.assign(std::begin(test2), std::end(test2)); |
93 RemoveUnsecureUrls(&urls); | 115 RemoveUnsecureUrls(&urls); |
(...skipping 12 matching lines...) Expand all Loading... | |
106 RemoveUnsecureUrls(&urls); | 128 RemoveUnsecureUrls(&urls); |
107 EXPECT_EQ(0u, urls.size()); | 129 EXPECT_EQ(0u, urls.size()); |
108 | 130 |
109 const GURL test5[] = {GURL("http://foo"), GURL("http://bar")}; | 131 const GURL test5[] = {GURL("http://foo"), GURL("http://bar")}; |
110 urls.assign(std::begin(test5), std::end(test5)); | 132 urls.assign(std::begin(test5), std::end(test5)); |
111 RemoveUnsecureUrls(&urls); | 133 RemoveUnsecureUrls(&urls); |
112 EXPECT_EQ(0u, urls.size()); | 134 EXPECT_EQ(0u, urls.size()); |
113 } | 135 } |
114 | 136 |
115 } // namespace update_client | 137 } // namespace update_client |
OLD | NEW |