| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/common/extensions/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
| 6 | 6 |
| 7 #if defined(TOOLKIT_GTK) | 7 #if defined(TOOLKIT_GTK) |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 | 1098 |
| 1099 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { | 1099 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { |
| 1100 EXPECT_EQ(kTests[i].expect_success, | 1100 EXPECT_EQ(kTests[i].expect_success, |
| 1101 extension->HasApiPermission(kTests[i].permission_name)) | 1101 extension->HasApiPermission(kTests[i].permission_name)) |
| 1102 << "Permission being tested: " << kTests[i].permission_name; | 1102 << "Permission being tested: " << kTests[i].permission_name; |
| 1103 } | 1103 } |
| 1104 } | 1104 } |
| 1105 | 1105 |
| 1106 TEST(ExtensionTest, GetDistinctHosts) { | 1106 TEST(ExtensionTest, GetDistinctHosts) { |
| 1107 std::vector<std::string> expected; | 1107 std::vector<std::string> expected; |
| 1108 std::vector<std::string> expected_no_rcd; |
| 1108 expected.push_back("www.foo.com"); | 1109 expected.push_back("www.foo.com"); |
| 1109 expected.push_back("www.bar.com"); | 1110 expected.push_back("www.bar.com"); |
| 1110 expected.push_back("www.baz.com"); | 1111 expected.push_back("www.baz.com"); |
| 1112 expected_no_rcd.push_back("www.foo."); |
| 1113 expected_no_rcd.push_back("www.bar."); |
| 1114 expected_no_rcd.push_back("www.baz."); |
| 1111 URLPatternList actual; | 1115 URLPatternList actual; |
| 1112 | 1116 |
| 1113 { | 1117 { |
| 1114 SCOPED_TRACE("no dupes"); | 1118 SCOPED_TRACE("no dupes"); |
| 1115 | 1119 |
| 1116 // Simple list with no dupes. | 1120 // Simple list with no dupes. |
| 1117 actual.push_back( | 1121 actual.push_back( |
| 1118 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); | 1122 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); |
| 1119 actual.push_back( | 1123 actual.push_back( |
| 1120 URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/path")); | 1124 URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/path")); |
| 1121 actual.push_back( | 1125 actual.push_back( |
| 1122 URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path")); | 1126 URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path")); |
| 1123 CompareLists(expected, | 1127 CompareLists(expected, |
| 1124 Extension::GetDistinctHosts(actual)); | 1128 Extension::GetDistinctHosts(actual, true)); |
| 1129 CompareLists(expected_no_rcd, |
| 1130 Extension::GetDistinctHosts(actual, false)); |
| 1125 } | 1131 } |
| 1126 | 1132 |
| 1127 { | 1133 { |
| 1128 SCOPED_TRACE("two dupes"); | 1134 SCOPED_TRACE("two dupes"); |
| 1129 | 1135 |
| 1130 // Add some dupes. | 1136 // Add some dupes. |
| 1131 actual.push_back( | 1137 actual.push_back( |
| 1132 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); | 1138 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); |
| 1133 actual.push_back( | 1139 actual.push_back( |
| 1134 URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path")); | 1140 URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path")); |
| 1135 CompareLists(expected, | 1141 CompareLists(expected, |
| 1136 Extension::GetDistinctHosts(actual)); | 1142 Extension::GetDistinctHosts(actual, true)); |
| 1143 CompareLists(expected_no_rcd, |
| 1144 Extension::GetDistinctHosts(actual, false)); |
| 1137 } | 1145 } |
| 1138 | 1146 |
| 1139 { | 1147 { |
| 1140 SCOPED_TRACE("schemes differ"); | 1148 SCOPED_TRACE("schemes differ"); |
| 1141 | 1149 |
| 1142 // Add a pattern that differs only by scheme. This should be filtered out. | 1150 // Add a pattern that differs only by scheme. This should be filtered out. |
| 1143 actual.push_back( | 1151 actual.push_back( |
| 1144 URLPattern(URLPattern::SCHEME_HTTPS, "https://www.bar.com/path")); | 1152 URLPattern(URLPattern::SCHEME_HTTPS, "https://www.bar.com/path")); |
| 1145 CompareLists(expected, | 1153 CompareLists(expected, |
| 1146 Extension::GetDistinctHosts(actual)); | 1154 Extension::GetDistinctHosts(actual, true)); |
| 1155 CompareLists(expected_no_rcd, |
| 1156 Extension::GetDistinctHosts(actual, false)); |
| 1147 } | 1157 } |
| 1148 | 1158 |
| 1149 { | 1159 { |
| 1150 SCOPED_TRACE("paths differ"); | 1160 SCOPED_TRACE("paths differ"); |
| 1151 | 1161 |
| 1152 // Add some dupes by path. | 1162 // Add some dupes by path. |
| 1153 actual.push_back( | 1163 actual.push_back( |
| 1154 URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/pathypath")); | 1164 URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/pathypath")); |
| 1155 CompareLists(expected, | 1165 CompareLists(expected, |
| 1156 Extension::GetDistinctHosts(actual)); | 1166 Extension::GetDistinctHosts(actual, true)); |
| 1167 CompareLists(expected_no_rcd, |
| 1168 Extension::GetDistinctHosts(actual, false)); |
| 1157 } | 1169 } |
| 1158 | 1170 |
| 1159 { | 1171 { |
| 1160 SCOPED_TRACE("subdomains differ"); | 1172 SCOPED_TRACE("subdomains differ"); |
| 1161 | 1173 |
| 1162 // We don't do anything special for subdomains. | 1174 // We don't do anything special for subdomains. |
| 1163 actual.push_back( | 1175 actual.push_back( |
| 1164 URLPattern(URLPattern::SCHEME_HTTP, "http://monkey.www.bar.com/path")); | 1176 URLPattern(URLPattern::SCHEME_HTTP, "http://monkey.www.bar.com/path")); |
| 1165 actual.push_back( | 1177 actual.push_back( |
| 1166 URLPattern(URLPattern::SCHEME_HTTP, "http://bar.com/path")); | 1178 URLPattern(URLPattern::SCHEME_HTTP, "http://bar.com/path")); |
| 1167 | 1179 |
| 1168 expected.push_back("monkey.www.bar.com"); | 1180 expected.push_back("monkey.www.bar.com"); |
| 1169 expected.push_back("bar.com"); | 1181 expected.push_back("bar.com"); |
| 1182 expected_no_rcd.push_back("monkey.www.bar."); |
| 1183 expected_no_rcd.push_back("bar."); |
| 1184 |
| 1170 | 1185 |
| 1171 CompareLists(expected, | 1186 CompareLists(expected, |
| 1172 Extension::GetDistinctHosts(actual)); | 1187 Extension::GetDistinctHosts(actual, true)); |
| 1188 CompareLists(expected_no_rcd, |
| 1189 Extension::GetDistinctHosts(actual, false)); |
| 1173 } | 1190 } |
| 1174 | 1191 |
| 1175 { | 1192 { |
| 1176 SCOPED_TRACE("RCDs differ"); | 1193 SCOPED_TRACE("RCDs differ"); |
| 1177 | 1194 |
| 1178 // Now test for RCD uniquing. | 1195 // Now test for RCD uniquing. |
| 1179 actual.push_back( | 1196 actual.push_back( |
| 1180 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); | 1197 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); |
| 1181 actual.push_back( | 1198 actual.push_back( |
| 1182 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); | 1199 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); |
| 1183 actual.push_back( | 1200 actual.push_back( |
| 1184 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.de/path")); | 1201 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.de/path")); |
| 1185 actual.push_back( | 1202 actual.push_back( |
| 1186 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca.us/path")); | 1203 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca.us/path")); |
| 1187 actual.push_back( | 1204 actual.push_back( |
| 1188 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); | 1205 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); |
| 1189 actual.push_back( | 1206 actual.push_back( |
| 1190 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com.my/path")); | 1207 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com.my/path")); |
| 1191 | 1208 |
| 1192 // This is an unknown RCD, which shouldn't be uniqued out. | 1209 // This is an unknown RCD, which shouldn't be uniqued out. |
| 1193 actual.push_back( | 1210 actual.push_back( |
| 1194 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.xyzzy/path")); | 1211 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.xyzzy/path")); |
| 1195 | 1212 |
| 1196 expected.push_back("www.foo.xyzzy"); | 1213 expected.push_back("www.foo.xyzzy"); |
| 1214 expected_no_rcd.push_back("www.foo.xyzzy"); |
| 1197 | 1215 |
| 1198 CompareLists(expected, | 1216 CompareLists(expected, |
| 1199 Extension::GetDistinctHosts(actual)); | 1217 Extension::GetDistinctHosts(actual, true)); |
| 1218 CompareLists(expected_no_rcd, |
| 1219 Extension::GetDistinctHosts(actual, false)); |
| 1200 } | 1220 } |
| 1201 } | 1221 } |
| 1202 | 1222 |
| 1203 TEST(ExtensionTest, GenerateId) { | 1223 TEST(ExtensionTest, GenerateId) { |
| 1204 std::string result; | 1224 std::string result; |
| 1205 EXPECT_FALSE(Extension::GenerateId("", &result)); | 1225 EXPECT_FALSE(Extension::GenerateId("", &result)); |
| 1206 | 1226 |
| 1207 EXPECT_TRUE(Extension::GenerateId("test", &result)); | 1227 EXPECT_TRUE(Extension::GenerateId("test", &result)); |
| 1208 EXPECT_EQ(result, "jpignaibiiemhngfjkcpokkamffknabf"); | 1228 EXPECT_EQ(result, "jpignaibiiemhngfjkcpokkamffknabf"); |
| 1209 | 1229 |
| 1210 EXPECT_TRUE(Extension::GenerateId("_", &result)); | 1230 EXPECT_TRUE(Extension::GenerateId("_", &result)); |
| 1211 EXPECT_EQ(result, "ncocknphbhhlhkikpnnlmbcnbgdempcd"); | 1231 EXPECT_EQ(result, "ncocknphbhhlhkikpnnlmbcnbgdempcd"); |
| 1212 | 1232 |
| 1213 EXPECT_TRUE(Extension::GenerateId( | 1233 EXPECT_TRUE(Extension::GenerateId( |
| 1214 "this_string_is_longer_than_a_single_sha256_hash_digest", &result)); | 1234 "this_string_is_longer_than_a_single_sha256_hash_digest", &result)); |
| 1215 EXPECT_EQ(result, "jimneklojkjdibfkgiiophfhjhbdgcfi"); | 1235 EXPECT_EQ(result, "jimneklojkjdibfkgiiophfhjhbdgcfi"); |
| 1216 } | 1236 } |
| OLD | NEW |