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

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

Issue 7347011: Update URLPatternSet to contain a std::set instead of std::vector. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows compile errors. Created 9 years, 5 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
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 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 EXPECT_EQ(URLPattern::PARSE_SUCCESS, 573 EXPECT_EQ(URLPattern::PARSE_SUCCESS,
574 pattern1.Parse(pattern_str, URLPattern::IGNORE_PORTS)); 574 pattern1.Parse(pattern_str, URLPattern::IGNORE_PORTS));
575 EXPECT_EQ(URLPattern::PARSE_SUCCESS, 575 EXPECT_EQ(URLPattern::PARSE_SUCCESS,
576 pattern2.Parse(pattern_str, URLPattern::USE_PORTS)); 576 pattern2.Parse(pattern_str, URLPattern::USE_PORTS));
577 577
578 EXPECT_EQ(pattern_str, pattern1.GetAsString()); 578 EXPECT_EQ(pattern_str, pattern1.GetAsString());
579 EXPECT_EQ(pattern_str, pattern2.GetAsString()); 579 EXPECT_EQ(pattern_str, pattern2.GetAsString());
580 EXPECT_FALSE(pattern1.MatchesURL(url)); 580 EXPECT_FALSE(pattern1.MatchesURL(url));
581 EXPECT_FALSE(pattern2.MatchesURL(url)); 581 EXPECT_FALSE(pattern2.MatchesURL(url));
582 } 582 }
583
584 TEST(ExtensionURLPatternTest, Equals) {
585 const struct {
586 const char* pattern1;
587 const char* pattern2;
588 bool expected_equal;
589 } kEqualsTestCases[] = {
590 // schemes
591 { "http://en.google.com/blah/*/foo",
592 "https://en.google.com/blah/*/foo",
593 false
594 },
595 { "https://en.google.com/blah/*/foo",
596 "https://en.google.com/blah/*/foo",
597 true
598 },
599 { "https://en.google.com/blah/*/foo",
600 "ftp://en.google.com/blah/*/foo",
601 false
602 },
603
604 // subdomains
605 { "https://en.google.com/blah/*/foo",
606 "https://fr.google.com/blah/*/foo",
607 false
608 },
609 { "https://www.google.com/blah/*/foo",
610 "https://*.google.com/blah/*/foo",
611 false
612 },
613 { "https://*.google.com/blah/*/foo",
614 "https://*.google.com/blah/*/foo",
615 true
616 },
617
618 // domains
619 { "http://en.example.com/blah/*/foo",
620 "http://en.google.com/blah/*/foo",
621 false
622 },
623
624 // ports
625 { "http://en.google.com:8000/blah/*/foo",
626 "http://en.google.com/blah/*/foo",
627 false
628 },
629 { "http://fr.google.com:8000/blah/*/foo",
630 "http://fr.google.com:8000/blah/*/foo",
631 true
632 },
633 { "http://en.google.com:8000/blah/*/foo",
634 "http://en.google.com:8080/blah/*/foo",
635 false
636 },
637
638 // paths
639 { "http://en.google.com/blah/*/foo",
640 "http://en.google.com/blah/*",
641 false
642 },
643 { "http://en.google.com/*",
644 "http://en.google.com/",
645 false
646 },
647 { "http://en.google.com/*",
648 "http://en.google.com/*",
649 true
650 },
651
652 // all_urls
653 { "<all_urls>",
654 "<all_urls>",
655 true
656 },
657 { "<all_urls>",
658 "http://*/*",
659 false
660 }
661 };
662
663 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kEqualsTestCases); ++i) {
664 std::string message = kEqualsTestCases[i].pattern1;
665 message += " ";
666 message += kEqualsTestCases[i].pattern2;
667
668 URLPattern pattern1(URLPattern::SCHEME_ALL);
669 URLPattern pattern2(URLPattern::SCHEME_ALL);
670
671 pattern1.Parse(kEqualsTestCases[i].pattern1, URLPattern::USE_PORTS);
672 pattern2.Parse(kEqualsTestCases[i].pattern2, URLPattern::USE_PORTS);
673 EXPECT_EQ(kEqualsTestCases[i].expected_equal, pattern1 == pattern2)
674 << message;
675 }
676 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/url_pattern_set_unittest.cc ('k') | chrome/common/extensions/user_script.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698