OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "googleurl/src/gurl.h" | 7 #include "googleurl/src/gurl.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace { | 10 namespace { |
11 | 11 |
12 static void AddPattern(URLPatternSet* set, const std::string& pattern) { | 12 void AddPattern(URLPatternSet* set, const std::string& pattern) { |
13 int schemes = URLPattern::SCHEME_ALL; | 13 int schemes = URLPattern::SCHEME_ALL; |
14 set->AddPattern(URLPattern(schemes, pattern)); | 14 set->AddPattern(URLPattern(schemes, pattern)); |
15 } | 15 } |
16 | 16 |
| 17 URLPatternSet Patterns(const std::string& pattern) { |
| 18 URLPatternSet set; |
| 19 AddPattern(&set, pattern); |
| 20 return set; |
17 } | 21 } |
| 22 |
| 23 URLPatternSet Patterns(const std::string& pattern1, |
| 24 const std::string& pattern2) { |
| 25 URLPatternSet set; |
| 26 AddPattern(&set, pattern1); |
| 27 AddPattern(&set, pattern2); |
| 28 return set; |
| 29 } |
| 30 |
| 31 } |
| 32 |
18 TEST(URLPatternSetTest, Empty) { | 33 TEST(URLPatternSetTest, Empty) { |
19 URLPatternSet set; | 34 URLPatternSet set; |
20 EXPECT_FALSE(set.MatchesURL(GURL("http://www.foo.com/bar"))); | 35 EXPECT_FALSE(set.MatchesURL(GURL("http://www.foo.com/bar"))); |
21 EXPECT_FALSE(set.MatchesURL(GURL())); | 36 EXPECT_FALSE(set.MatchesURL(GURL())); |
22 EXPECT_FALSE(set.MatchesURL(GURL("invalid"))); | 37 EXPECT_FALSE(set.MatchesURL(GURL("invalid"))); |
23 } | 38 } |
24 | 39 |
25 TEST(URLPatternSetTest, One) { | 40 TEST(URLPatternSetTest, One) { |
26 URLPatternSet set; | 41 URLPatternSet set; |
27 AddPattern(&set, "http://www.google.com/*"); | 42 AddPattern(&set, "http://www.google.com/*"); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 URLPatternSet set2; | 207 URLPatternSet set2; |
193 | 208 |
194 AddPattern(&set1, "http://www.google.com/*"); | 209 AddPattern(&set1, "http://www.google.com/*"); |
195 AddPattern(&set2, "http://www.google.com/*"); | 210 AddPattern(&set2, "http://www.google.com/*"); |
196 | 211 |
197 AddPattern(&set1, "http://www.google.com/*"); | 212 AddPattern(&set1, "http://www.google.com/*"); |
198 | 213 |
199 // The sets should still be equal after adding a duplicate. | 214 // The sets should still be equal after adding a duplicate. |
200 EXPECT_EQ(set2, set1); | 215 EXPECT_EQ(set2, set1); |
201 } | 216 } |
| 217 |
| 218 TEST(URLPatternSetTest, NwayUnion) { |
| 219 std::string google_a = "http://www.google.com/a*"; |
| 220 std::string google_b = "http://www.google.com/b*"; |
| 221 std::string google_c = "http://www.google.com/c*"; |
| 222 std::string yahoo_a = "http://www.yahoo.com/a*"; |
| 223 std::string yahoo_b = "http://www.yahoo.com/b*"; |
| 224 std::string yahoo_c = "http://www.yahoo.com/c*"; |
| 225 std::string reddit_a = "http://www.reddit.com/a*"; |
| 226 std::string reddit_b = "http://www.reddit.com/b*"; |
| 227 std::string reddit_c = "http://www.reddit.com/c*"; |
| 228 |
| 229 // Empty list. |
| 230 { |
| 231 std::vector<URLPatternSet> empty; |
| 232 |
| 233 URLPatternSet result; |
| 234 URLPatternSet::CreateUnion(empty, &result); |
| 235 |
| 236 URLPatternSet expected; |
| 237 EXPECT_EQ(expected, result); |
| 238 } |
| 239 |
| 240 // Singleton list. |
| 241 { |
| 242 std::vector<URLPatternSet> test; |
| 243 test.push_back(Patterns(google_a)); |
| 244 |
| 245 URLPatternSet result; |
| 246 URLPatternSet::CreateUnion(test, &result); |
| 247 |
| 248 URLPatternSet expected = Patterns(google_a); |
| 249 EXPECT_EQ(expected, result); |
| 250 } |
| 251 |
| 252 // List with 2 elements. |
| 253 { |
| 254 |
| 255 std::vector<URLPatternSet> test; |
| 256 test.push_back(Patterns(google_a, google_b)); |
| 257 test.push_back(Patterns(google_b, google_c)); |
| 258 |
| 259 URLPatternSet result; |
| 260 URLPatternSet::CreateUnion(test, &result); |
| 261 |
| 262 URLPatternSet expected; |
| 263 AddPattern(&expected, google_a); |
| 264 AddPattern(&expected, google_b); |
| 265 AddPattern(&expected, google_c); |
| 266 EXPECT_EQ(expected, result); |
| 267 } |
| 268 |
| 269 // List with 3 elements. |
| 270 { |
| 271 std::vector<URLPatternSet> test; |
| 272 test.push_back(Patterns(google_a, google_b)); |
| 273 test.push_back(Patterns(google_b, google_c)); |
| 274 test.push_back(Patterns(yahoo_a, yahoo_b)); |
| 275 |
| 276 URLPatternSet result; |
| 277 URLPatternSet::CreateUnion(test, &result); |
| 278 |
| 279 URLPatternSet expected; |
| 280 AddPattern(&expected, google_a); |
| 281 AddPattern(&expected, google_b); |
| 282 AddPattern(&expected, google_c); |
| 283 AddPattern(&expected, yahoo_a); |
| 284 AddPattern(&expected, yahoo_b); |
| 285 EXPECT_EQ(expected, result); |
| 286 } |
| 287 |
| 288 // List with 7 elements. |
| 289 { |
| 290 std::vector<URLPatternSet> test; |
| 291 test.push_back(Patterns(google_a)); |
| 292 test.push_back(Patterns(google_b)); |
| 293 test.push_back(Patterns(google_c)); |
| 294 test.push_back(Patterns(yahoo_a)); |
| 295 test.push_back(Patterns(yahoo_b)); |
| 296 test.push_back(Patterns(yahoo_c)); |
| 297 test.push_back(Patterns(reddit_a)); |
| 298 |
| 299 URLPatternSet result; |
| 300 URLPatternSet::CreateUnion(test, &result); |
| 301 |
| 302 URLPatternSet expected; |
| 303 AddPattern(&expected, google_a); |
| 304 AddPattern(&expected, google_b); |
| 305 AddPattern(&expected, google_c); |
| 306 AddPattern(&expected, yahoo_a); |
| 307 AddPattern(&expected, yahoo_b); |
| 308 AddPattern(&expected, yahoo_c); |
| 309 AddPattern(&expected, reddit_a); |
| 310 EXPECT_EQ(expected, result); |
| 311 } |
| 312 |
| 313 // List with 8 elements. |
| 314 { |
| 315 std::vector<URLPatternSet> test; |
| 316 test.push_back(Patterns(google_a)); |
| 317 test.push_back(Patterns(google_b)); |
| 318 test.push_back(Patterns(google_c)); |
| 319 test.push_back(Patterns(yahoo_a)); |
| 320 test.push_back(Patterns(yahoo_b)); |
| 321 test.push_back(Patterns(yahoo_c)); |
| 322 test.push_back(Patterns(reddit_a)); |
| 323 test.push_back(Patterns(reddit_b)); |
| 324 |
| 325 URLPatternSet result; |
| 326 URLPatternSet::CreateUnion(test, &result); |
| 327 |
| 328 URLPatternSet expected; |
| 329 AddPattern(&expected, google_a); |
| 330 AddPattern(&expected, google_b); |
| 331 AddPattern(&expected, google_c); |
| 332 AddPattern(&expected, yahoo_a); |
| 333 AddPattern(&expected, yahoo_b); |
| 334 AddPattern(&expected, yahoo_c); |
| 335 AddPattern(&expected, reddit_a); |
| 336 AddPattern(&expected, reddit_b); |
| 337 EXPECT_EQ(expected, result); |
| 338 } |
| 339 |
| 340 // List with 9 elements. |
| 341 { |
| 342 |
| 343 std::vector<URLPatternSet> test; |
| 344 test.push_back(Patterns(google_a)); |
| 345 test.push_back(Patterns(google_b)); |
| 346 test.push_back(Patterns(google_c)); |
| 347 test.push_back(Patterns(yahoo_a)); |
| 348 test.push_back(Patterns(yahoo_b)); |
| 349 test.push_back(Patterns(yahoo_c)); |
| 350 test.push_back(Patterns(reddit_a)); |
| 351 test.push_back(Patterns(reddit_b)); |
| 352 test.push_back(Patterns(reddit_c)); |
| 353 |
| 354 URLPatternSet result; |
| 355 URLPatternSet::CreateUnion(test, &result); |
| 356 |
| 357 URLPatternSet expected; |
| 358 AddPattern(&expected, google_a); |
| 359 AddPattern(&expected, google_b); |
| 360 AddPattern(&expected, google_c); |
| 361 AddPattern(&expected, yahoo_a); |
| 362 AddPattern(&expected, yahoo_b); |
| 363 AddPattern(&expected, yahoo_c); |
| 364 AddPattern(&expected, reddit_a); |
| 365 AddPattern(&expected, reddit_b); |
| 366 AddPattern(&expected, reddit_c); |
| 367 EXPECT_EQ(expected, result); |
| 368 } |
| 369 } |
OLD | NEW |