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

Side by Side Diff: chrome/common/extensions/url_pattern_set_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 "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 {
11
12 static void AssertEqualExtents(const URLPatternSet& extent1,
13 const URLPatternSet& extent2) {
14 URLPatternList patterns1 = extent1.patterns();
15 URLPatternList patterns2 = extent2.patterns();
16 std::set<std::string> strings1;
17 EXPECT_EQ(patterns1.size(), patterns2.size());
18
19 for (size_t i = 0; i < patterns1.size(); ++i)
20 strings1.insert(patterns1.at(i).GetAsString());
21
22 std::set<std::string> strings2;
23 for (size_t i = 0; i < patterns2.size(); ++i)
24 strings2.insert(patterns2.at(i).GetAsString());
25
26 EXPECT_EQ(strings1, strings2);
27 }
28
29 } // namespace
30
31 static const int kAllSchemes = 10 static const int kAllSchemes =
32 URLPattern::SCHEME_HTTP | 11 URLPattern::SCHEME_HTTP |
33 URLPattern::SCHEME_HTTPS | 12 URLPattern::SCHEME_HTTPS |
34 URLPattern::SCHEME_FILE | 13 URLPattern::SCHEME_FILE |
35 URLPattern::SCHEME_FTP | 14 URLPattern::SCHEME_FTP |
36 URLPattern::SCHEME_CHROMEUI; 15 URLPattern::SCHEME_CHROMEUI;
37 16
38 TEST(URLPatternSetTest, Empty) { 17 TEST(URLPatternSetTest, Empty) {
39 URLPatternSet extent; 18 URLPatternSet extent;
40 EXPECT_FALSE(extent.MatchesURL(GURL("http://www.foo.com/bar"))); 19 EXPECT_FALSE(extent.MatchesURL(GURL("http://www.foo.com/bar")));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 extent1.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/f*")); 68 extent1.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/f*"));
90 extent1.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/b*")); 69 extent1.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/b*"));
91 70
92 URLPatternSet expected; 71 URLPatternSet expected;
93 expected.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/f*")); 72 expected.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/f*"));
94 expected.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/b*")); 73 expected.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/b*"));
95 74
96 // Union with an empty set. 75 // Union with an empty set.
97 URLPatternSet result; 76 URLPatternSet result;
98 URLPatternSet::CreateUnion(extent1, empty_extent, &result); 77 URLPatternSet::CreateUnion(extent1, empty_extent, &result);
99 AssertEqualExtents(expected, result); 78 EXPECT_EQ(expected, result);
100 79
101 // Union with a real set (including a duplicate). 80 // Union with a real set (including a duplicate).
102 URLPatternSet extent2; 81 URLPatternSet extent2;
103 extent2.AddPattern(URLPattern(kAllSchemes, "http://www.reddit.com/f*")); 82 extent2.AddPattern(URLPattern(kAllSchemes, "http://www.reddit.com/f*"));
104 extent2.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/z*")); 83 extent2.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/z*"));
105 extent2.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/f*")); 84 extent2.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/f*"));
106 85
107 expected.AddPattern(URLPattern(kAllSchemes, "http://www.reddit.com/f*")); 86 expected.AddPattern(URLPattern(kAllSchemes, "http://www.reddit.com/f*"));
108 expected.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/z*")); 87 expected.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/z*"));
109 // CreateUnion does not filter out duplicates right now. 88 // CreateUnion does not filter out duplicates right now.
110 expected.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/f*")); 89 expected.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/f*"));
111 90
112 result.ClearPatterns(); 91 result.ClearPatterns();
113 URLPatternSet::CreateUnion(extent1, extent2, &result); 92 URLPatternSet::CreateUnion(extent1, extent2, &result);
114 AssertEqualExtents(expected, result); 93 EXPECT_EQ(expected, result);
115 } 94 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/url_pattern_set.cc ('k') | chrome/common/extensions/url_pattern_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698