OLD | NEW |
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 kAllSchemes = | 10 static const int kAllSchemes = |
(...skipping 11 matching lines...) Expand all Loading... |
22 } | 22 } |
23 | 23 |
24 TEST(ExtensionExtentTest, One) { | 24 TEST(ExtensionExtentTest, One) { |
25 ExtensionExtent extent; | 25 ExtensionExtent extent; |
26 extent.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/*")); | 26 extent.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/*")); |
27 | 27 |
28 EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/"))); | 28 EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/"))); |
29 EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/monkey"))); | 29 EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/monkey"))); |
30 EXPECT_FALSE(extent.ContainsURL(GURL("https://www.google.com/"))); | 30 EXPECT_FALSE(extent.ContainsURL(GURL("https://www.google.com/"))); |
31 EXPECT_FALSE(extent.ContainsURL(GURL("https://www.microsoft.com/"))); | 31 EXPECT_FALSE(extent.ContainsURL(GURL("https://www.microsoft.com/"))); |
| 32 EXPECT_FALSE(extent.ContainsURL(GURL("httpsv://www.microsoft.com/"))); |
32 } | 33 } |
33 | 34 |
34 TEST(ExtensionExtentTest, Two) { | 35 TEST(ExtensionExtentTest, Two) { |
35 ExtensionExtent extent; | 36 ExtensionExtent extent; |
36 extent.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/*")); | 37 extent.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/*")); |
37 extent.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/*")); | 38 extent.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/*")); |
38 | 39 |
39 EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/monkey"))); | 40 EXPECT_TRUE(extent.ContainsURL(GURL("http://www.google.com/monkey"))); |
40 EXPECT_TRUE(extent.ContainsURL(GURL("http://www.yahoo.com/monkey"))); | 41 EXPECT_TRUE(extent.ContainsURL(GURL("http://www.yahoo.com/monkey"))); |
41 EXPECT_FALSE(extent.ContainsURL(GURL("https://www.apple.com/monkey"))); | 42 EXPECT_FALSE(extent.ContainsURL(GURL("https://www.apple.com/monkey"))); |
| 43 EXPECT_FALSE(extent.ContainsURL(GURL("httpsv://www.apple.com/monkey"))); |
| 44 } |
| 45 |
| 46 TEST(ExtensionExtentTest, SeparateHTTPSAndHTTPSV) { |
| 47 ExtensionExtent extent; |
| 48 extent.AddPattern(URLPattern(kAllSchemes, "https://www.google.com/*")); |
| 49 |
| 50 EXPECT_FALSE(extent.ContainsURL(GURL("httpsv://www.google.com/"))); |
42 } | 51 } |
43 | 52 |
44 TEST(ExtensionExtentTest, OverlapsWith) { | 53 TEST(ExtensionExtentTest, OverlapsWith) { |
45 ExtensionExtent extent1; | 54 ExtensionExtent extent1; |
46 extent1.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/f*")); | 55 extent1.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/f*")); |
47 extent1.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/b*")); | 56 extent1.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/b*")); |
48 | 57 |
49 ExtensionExtent extent2; | 58 ExtensionExtent extent2; |
50 extent2.AddPattern(URLPattern(kAllSchemes, "http://www.reddit.com/f*")); | 59 extent2.AddPattern(URLPattern(kAllSchemes, "http://www.reddit.com/f*")); |
51 extent2.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/z*")); | 60 extent2.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/z*")); |
52 | 61 |
53 ExtensionExtent extent3; | 62 ExtensionExtent extent3; |
54 extent3.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/q/*")); | 63 extent3.AddPattern(URLPattern(kAllSchemes, "http://www.google.com/q/*")); |
55 extent3.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/b/*")); | 64 extent3.AddPattern(URLPattern(kAllSchemes, "http://www.yahoo.com/b/*")); |
56 | 65 |
57 EXPECT_FALSE(extent1.OverlapsWith(extent2)); | 66 EXPECT_FALSE(extent1.OverlapsWith(extent2)); |
58 EXPECT_FALSE(extent2.OverlapsWith(extent1)); | 67 EXPECT_FALSE(extent2.OverlapsWith(extent1)); |
59 | 68 |
60 EXPECT_TRUE(extent1.OverlapsWith(extent3)); | 69 EXPECT_TRUE(extent1.OverlapsWith(extent3)); |
61 EXPECT_TRUE(extent3.OverlapsWith(extent1)); | 70 EXPECT_TRUE(extent3.OverlapsWith(extent1)); |
62 } | 71 } |
OLD | NEW |