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

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

Issue 3039005: Fix some issues with extensions: (Closed)
Patch Set: fix host perms Created 10 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
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | chrome/common/extensions/url_pattern.h » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 static const int kSchemes = URLPattern::SCHEMES_ALL; 10 static const int kAllSchemes =
11 URLPattern::SCHEME_HTTP |
12 URLPattern::SCHEME_HTTPS |
13 URLPattern::SCHEME_FILE |
14 URLPattern::SCHEME_FTP |
15 URLPattern::SCHEME_CHROMEUI;
11 16
12 TEST(ExtensionExtentTest, Empty) { 17 TEST(ExtensionExtentTest, Empty) {
13 ExtensionExtent extent; 18 ExtensionExtent extent;
14 EXPECT_FALSE(extent.ContainsURL(GURL("http://www.foo.com/bar"))); 19 EXPECT_FALSE(extent.ContainsURL(GURL("http://www.foo.com/bar")));
15 EXPECT_FALSE(extent.ContainsURL(GURL())); 20 EXPECT_FALSE(extent.ContainsURL(GURL()));
16 EXPECT_FALSE(extent.ContainsURL(GURL("invalid"))); 21 EXPECT_FALSE(extent.ContainsURL(GURL("invalid")));
17 } 22 }
18 23
19 TEST(ExtensionExtentTest, One) { 24 TEST(ExtensionExtentTest, One) {
20 ExtensionExtent extent; 25 ExtensionExtent extent;
21 extent.AddPattern(URLPattern(kSchemes, "http://www.google.com/*")); 26 extent.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/*"));
22 27
23 EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/"))); 28 EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/")));
24 EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/monkey"))); 29 EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/monkey")));
25 EXPECT_FALSE(extent.ContainsURL(GURL("https://www.google.com/"))); 30 EXPECT_FALSE(extent.ContainsURL(GURL("https://www.google.com/")));
26 EXPECT_FALSE(extent.ContainsURL(GURL("https://www.microsoft.com/"))); 31 EXPECT_FALSE(extent.ContainsURL(GURL("https://www.microsoft.com/")));
27 } 32 }
28 33
29 TEST(ExtensionExtentTest, Two) { 34 TEST(ExtensionExtentTest, Two) {
30 ExtensionExtent extent; 35 ExtensionExtent extent;
31 extent.AddPattern(URLPattern(kSchemes, "http://www.google.com/*")); 36 extent.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/*"));
32 extent.AddPattern(URLPattern(kSchemes, "http://www.yahoo.com/*")); 37 extent.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/*"));
33 38
34 EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/monkey"))); 39 EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/monkey")));
35 EXPECT_TRUE(extent.ContainsURL(GURL("http://www.yahoo.com/monkey"))); 40 EXPECT_TRUE(extent.ContainsURL(GURL("http://www.yahoo.com/monkey")));
36 EXPECT_FALSE(extent.ContainsURL(GURL("https://www.apple.com/monkey"))); 41 EXPECT_FALSE(extent.ContainsURL(GURL("https://www.apple.com/monkey")));
37 } 42 }
38 43
39 TEST(ExtensionExtentTest, OverlapsWith) { 44 TEST(ExtensionExtentTest, OverlapsWith) {
40 ExtensionExtent extent1; 45 ExtensionExtent extent1;
41 extent1.AddPattern(URLPattern(kSchemes, "http://www.google.com/f*")); 46 extent1.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/f*"));
42 extent1.AddPattern(URLPattern(kSchemes, "http://www.yahoo.com/b*")); 47 extent1.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/b*"));
43 48
44 ExtensionExtent extent2; 49 ExtensionExtent extent2;
45 extent2.AddPattern(URLPattern(kSchemes, "http://www.reddit.com/f*")); 50 extent2.AddPattern(URLPattern(kAllSchemes, "http://www.reddit.com/f*"));
46 extent2.AddPattern(URLPattern(kSchemes, "http://www.yahoo.com/z*")); 51 extent2.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/z*"));
47 52
48 ExtensionExtent extent3; 53 ExtensionExtent extent3;
49 extent3.AddPattern(URLPattern(kSchemes, "http://www.google.com/q/*")); 54 extent3.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/q/*"));
50 extent3.AddPattern(URLPattern(kSchemes, "http://www.yahoo.com/b/*")); 55 extent3.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/b/*"));
51 56
52 EXPECT_FALSE(extent1.OverlapsWith(extent2)); 57 EXPECT_FALSE(extent1.OverlapsWith(extent2));
53 EXPECT_FALSE(extent2.OverlapsWith(extent1)); 58 EXPECT_FALSE(extent2.OverlapsWith(extent1));
54 59
55 EXPECT_TRUE(extent1.OverlapsWith(extent3)); 60 EXPECT_TRUE(extent1.OverlapsWith(extent3));
56 EXPECT_TRUE(extent3.OverlapsWith(extent1)); 61 EXPECT_TRUE(extent3.OverlapsWith(extent1));
57 } 62 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | chrome/common/extensions/url_pattern.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698