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("\""))); // Has " |
| 104 EXPECT_FALSE(IsValidAp(std::string("\\"))); // Has backspace. |
| 105 EXPECT_FALSE(IsValidAp(std::string("\xaa"))); // Has non-ASCII char. |
| 106 } |
| 107 |
84 TEST(UpdateClientUtils, RemoveUnsecureUrls) { | 108 TEST(UpdateClientUtils, RemoveUnsecureUrls) { |
85 const GURL test1[] = {GURL("http://foo"), GURL("https://foo")}; | 109 const GURL test1[] = {GURL("http://foo"), GURL("https://foo")}; |
86 std::vector<GURL> urls(std::begin(test1), std::end(test1)); | 110 std::vector<GURL> urls(std::begin(test1), std::end(test1)); |
87 RemoveUnsecureUrls(&urls); | 111 RemoveUnsecureUrls(&urls); |
88 EXPECT_EQ(1u, urls.size()); | 112 EXPECT_EQ(1u, urls.size()); |
89 EXPECT_EQ(urls[0], GURL("https://foo")); | 113 EXPECT_EQ(urls[0], GURL("https://foo")); |
90 | 114 |
91 const GURL test2[] = {GURL("https://foo"), GURL("http://foo")}; | 115 const GURL test2[] = {GURL("https://foo"), GURL("http://foo")}; |
92 urls.assign(std::begin(test2), std::end(test2)); | 116 urls.assign(std::begin(test2), std::end(test2)); |
93 RemoveUnsecureUrls(&urls); | 117 RemoveUnsecureUrls(&urls); |
(...skipping 12 matching lines...) Expand all Loading... |
106 RemoveUnsecureUrls(&urls); | 130 RemoveUnsecureUrls(&urls); |
107 EXPECT_EQ(0u, urls.size()); | 131 EXPECT_EQ(0u, urls.size()); |
108 | 132 |
109 const GURL test5[] = {GURL("http://foo"), GURL("http://bar")}; | 133 const GURL test5[] = {GURL("http://foo"), GURL("http://bar")}; |
110 urls.assign(std::begin(test5), std::end(test5)); | 134 urls.assign(std::begin(test5), std::end(test5)); |
111 RemoveUnsecureUrls(&urls); | 135 RemoveUnsecureUrls(&urls); |
112 EXPECT_EQ(0u, urls.size()); | 136 EXPECT_EQ(0u, urls.size()); |
113 } | 137 } |
114 | 138 |
115 } // namespace update_client | 139 } // namespace update_client |
OLD | NEW |