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

Side by Side Diff: chrome/common/extensions/url_pattern_unittest.cc

Issue 7049032: Make URLPattern::OverlapsWith handle wildcards better by expanding them to explicit schemes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/url_pattern.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "chrome/common/extensions/url_pattern.h" 6 #include "chrome/common/extensions/url_pattern.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "googleurl/src/gurl.h" 8 #include "googleurl/src/gurl.h"
9 9
10 // See url_pattern.h for examples of valid and invalid patterns. 10 // See url_pattern.h for examples of valid and invalid patterns.
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 TestPatternOverlap(pattern5, pattern6, true); 359 TestPatternOverlap(pattern5, pattern6, true);
360 360
361 // Test that scheme restrictions work. 361 // Test that scheme restrictions work.
362 TestPatternOverlap(pattern1, pattern8, true); 362 TestPatternOverlap(pattern1, pattern8, true);
363 TestPatternOverlap(pattern1, pattern9, false); 363 TestPatternOverlap(pattern1, pattern9, false);
364 TestPatternOverlap(pattern1, pattern10, true); 364 TestPatternOverlap(pattern1, pattern10, true);
365 365
366 // Test that '<all_urls>' includes file URLs, while scheme '*' does not. 366 // Test that '<all_urls>' includes file URLs, while scheme '*' does not.
367 TestPatternOverlap(pattern7, pattern8, false); 367 TestPatternOverlap(pattern7, pattern8, false);
368 TestPatternOverlap(pattern7, pattern10, true); 368 TestPatternOverlap(pattern7, pattern10, true);
369
370 // Test that wildcard schemes are handled correctly, especially when compared
371 // to each-other.
372 URLPattern pattern11(kAllSchemes, "http://example.com/*");
373 URLPattern pattern12(kAllSchemes, "*://example.com/*");
374 URLPattern pattern13(kAllSchemes, "*://example.com/foo/*");
375 URLPattern pattern14(kAllSchemes, "*://google.com/*");
376 TestPatternOverlap(pattern8, pattern12, true);
377 TestPatternOverlap(pattern9, pattern12, true);
378 TestPatternOverlap(pattern10, pattern12, true);
379 TestPatternOverlap(pattern11, pattern12, true);
380 TestPatternOverlap(pattern12, pattern13, true);
381 TestPatternOverlap(pattern11, pattern13, true);
382 TestPatternOverlap(pattern14, pattern12, false);
383 TestPatternOverlap(pattern14, pattern13, false);
369 } 384 }
370 385
371 TEST(ExtensionURLPatternTest, ConvertToExplicitSchemes) { 386 TEST(ExtensionURLPatternTest, ConvertToExplicitSchemes) {
372 std::vector<URLPattern> all_urls(URLPattern( 387 std::vector<URLPattern> all_urls(URLPattern(
373 kAllSchemes, 388 kAllSchemes,
374 "<all_urls>").ConvertToExplicitSchemes()); 389 "<all_urls>").ConvertToExplicitSchemes());
375 390
376 std::vector<URLPattern> all_schemes(URLPattern( 391 std::vector<URLPattern> all_schemes(URLPattern(
377 kAllSchemes, 392 kAllSchemes,
378 "*://google.com/foo").ConvertToExplicitSchemes()); 393 "*://google.com/foo").ConvertToExplicitSchemes());
(...skipping 11 matching lines...) Expand all
390 EXPECT_EQ("https://*/*", all_urls[1].GetAsString()); 405 EXPECT_EQ("https://*/*", all_urls[1].GetAsString());
391 EXPECT_EQ("file:///*", all_urls[2].GetAsString()); 406 EXPECT_EQ("file:///*", all_urls[2].GetAsString());
392 EXPECT_EQ("ftp://*/*", all_urls[3].GetAsString()); 407 EXPECT_EQ("ftp://*/*", all_urls[3].GetAsString());
393 EXPECT_EQ("chrome://*/*", all_urls[4].GetAsString()); 408 EXPECT_EQ("chrome://*/*", all_urls[4].GetAsString());
394 409
395 EXPECT_EQ("http://google.com/foo", all_schemes[0].GetAsString()); 410 EXPECT_EQ("http://google.com/foo", all_schemes[0].GetAsString());
396 EXPECT_EQ("https://google.com/foo", all_schemes[1].GetAsString()); 411 EXPECT_EQ("https://google.com/foo", all_schemes[1].GetAsString());
397 412
398 EXPECT_EQ("http://google.com/monkey", monkey[0].GetAsString()); 413 EXPECT_EQ("http://google.com/monkey", monkey[0].GetAsString());
399 } 414 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/url_pattern.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698