OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/service_worker/service_worker_utils.h" | 5 #include "content/browser/service_worker/service_worker_utils.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 | 7 |
8 namespace content { | 8 namespace content { |
9 | 9 |
10 TEST(ServiceWorkerUtilsTest, ScopeMatches) { | 10 TEST(ServiceWorkerUtilsTest, ScopeMatches) { |
(...skipping 12 matching lines...) Expand all Loading... |
23 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( | 23 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( |
24 GURL("http://www.example.com/*"), GURL("http://www.foo.com/"))); | 24 GURL("http://www.example.com/*"), GURL("http://www.foo.com/"))); |
25 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( | 25 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( |
26 GURL("http://www.example.com/*"), GURL("https://www.foo.com/page.html"))); | 26 GURL("http://www.example.com/*"), GURL("https://www.foo.com/page.html"))); |
27 | 27 |
28 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( | 28 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( |
29 GURL("http://www.example.com/"), GURL("http://www.example.com/"))); | 29 GURL("http://www.example.com/"), GURL("http://www.example.com/"))); |
30 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( | 30 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( |
31 GURL("http://www.example.com/"), GURL("http://www.example.com/x"))); | 31 GURL("http://www.example.com/"), GURL("http://www.example.com/x"))); |
32 | 32 |
| 33 // '?' is not a wildcard. |
33 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( | 34 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( |
34 GURL("http://www.example.com/?"), GURL("http://www.example.com/x"))); | 35 GURL("http://www.example.com/?"), GURL("http://www.example.com/x"))); |
35 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( | 36 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( |
36 GURL("http://www.example.com/?"), GURL("http://www.example.com/"))); | 37 GURL("http://www.example.com/?"), GURL("http://www.example.com/"))); |
37 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( | 38 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( |
38 GURL("http://www.example.com/?"), GURL("http://www.example.com/xx"))); | 39 GURL("http://www.example.com/?"), GURL("http://www.example.com/xx"))); |
39 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( | 40 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( |
40 GURL("http://www.example.com/?"), GURL("http://www.example.com/?"))); | 41 GURL("http://www.example.com/?"), GURL("http://www.example.com/?"))); |
41 | 42 |
| 43 // '*' only has special meaning in terminal position. |
| 44 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( |
| 45 GURL("http://www.example.com/*/x"), GURL("http://www.example.com/*/x"))); |
| 46 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( |
| 47 GURL("http://www.example.com/*/x"), GURL("http://www.example.com/a/x"))); |
| 48 ASSERT_FALSE( |
| 49 ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/*/x/*"), |
| 50 GURL("http://www.example.com/a/x/b"))); |
| 51 ASSERT_TRUE( |
| 52 ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/*/x/*"), |
| 53 GURL("http://www.example.com/*/x/b"))); |
| 54 |
42 // URLs canonicalize \ to / so this is equivalent to "...//*" and "...//x" | 55 // URLs canonicalize \ to / so this is equivalent to "...//*" and "...//x" |
43 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( | 56 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( |
44 GURL("http://www.example.com/\\*"), GURL("http://www.example.com/\\x"))); | 57 GURL("http://www.example.com/\\*"), GURL("http://www.example.com/\\x"))); |
45 } | 58 } |
46 | 59 |
47 } // namespace content | 60 } // namespace content |
OLD | NEW |