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 7003098: Start refractoring extension permissions into ExtensionPermissionSet. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: See if rebasing fixes the tests... Created 9 years, 6 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
10 static const int kAllSchemes = 31 static const int kAllSchemes =
11 URLPattern::SCHEME_HTTP | 32 URLPattern::SCHEME_HTTP |
12 URLPattern::SCHEME_HTTPS | 33 URLPattern::SCHEME_HTTPS |
13 URLPattern::SCHEME_FILE | 34 URLPattern::SCHEME_FILE |
14 URLPattern::SCHEME_FTP | 35 URLPattern::SCHEME_FTP |
15 URLPattern::SCHEME_CHROMEUI; 36 URLPattern::SCHEME_CHROMEUI;
16 37
17 TEST(URLPatternSetTest, Empty) { 38 TEST(URLPatternSetTest, Empty) {
18 URLPatternSet extent; 39 URLPatternSet extent;
19 EXPECT_FALSE(extent.MatchesURL(GURL("http://www.foo.com/bar"))); 40 EXPECT_FALSE(extent.MatchesURL(GURL("http://www.foo.com/bar")));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 URLPatternSet extent3; 74 URLPatternSet extent3;
54 extent3.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/q/*")); 75 extent3.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/q/*"));
55 extent3.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/b/*")); 76 extent3.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/b/*"));
56 77
57 EXPECT_FALSE(extent1.OverlapsWith(extent2)); 78 EXPECT_FALSE(extent1.OverlapsWith(extent2));
58 EXPECT_FALSE(extent2.OverlapsWith(extent1)); 79 EXPECT_FALSE(extent2.OverlapsWith(extent1));
59 80
60 EXPECT_TRUE(extent1.OverlapsWith(extent3)); 81 EXPECT_TRUE(extent1.OverlapsWith(extent3));
61 EXPECT_TRUE(extent3.OverlapsWith(extent1)); 82 EXPECT_TRUE(extent3.OverlapsWith(extent1));
62 } 83 }
84
85 TEST(URLPatternSetTest, CreateUnion) {
86 URLPatternSet empty_extent;
87
88 URLPatternSet extent1;
89 extent1.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/f*"));
90 extent1.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/b*"));
91
92 URLPatternSet expected;
93 expected.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/f*"));
94 expected.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/b*"));
95
96 // Union with an empty set.
97 URLPatternSet result;
98 URLPatternSet::CreateUnion(extent1, empty_extent, &result);
99 AssertEqualExtents(expected, result);
100
101 // Union with a real set (including a duplicate).
102 URLPatternSet extent2;
103 extent2.AddPattern(URLPattern(kAllSchemes, "http://www.reddit.com/f*"));
104 extent2.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/z*"));
105 extent2.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/f*"));
106
107 expected.AddPattern(URLPattern(kAllSchemes, "http://www.reddit.com/f*"));
108 expected.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/z*"));
109 // CreateUnion does not filter out duplicates right now.
110 expected.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/f*"));
111
112 result.ClearPatterns();
113 URLPatternSet::CreateUnion(extent1, extent2, &result);
114 AssertEqualExtents(expected, result);
115 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/url_pattern_set.cc ('k') | chrome/renderer/extensions/bindings_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698