| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 GURL("http://www.example.com/a/x/b"))); | 62 GURL("http://www.example.com/a/x/b"))); |
| 63 ASSERT_TRUE( | 63 ASSERT_TRUE( |
| 64 ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/*/x/*"), | 64 ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/*/x/*"), |
| 65 GURL("http://www.example.com/*/x/b"))); | 65 GURL("http://www.example.com/*/x/b"))); |
| 66 | 66 |
| 67 // URLs canonicalize \ to / so this is equivalent to "...//*" and "...//x" | 67 // URLs canonicalize \ to / so this is equivalent to "...//*" and "...//x" |
| 68 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( | 68 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( |
| 69 GURL("http://www.example.com/\\*"), GURL("http://www.example.com/\\x"))); | 69 GURL("http://www.example.com/\\*"), GURL("http://www.example.com/\\x"))); |
| 70 } | 70 } |
| 71 | 71 |
| 72 TEST(ServiceWorkerUtilsTest, FindLongestScopeMatch_Basic) { |
| 73 LongestScopeMatcher matcher(GURL("http://www.example.com/xxx")); |
| 74 |
| 75 // "/xx*" should be matched longest. |
| 76 ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/x*"))); |
| 77 ASSERT_FALSE(matcher.MatchLongest(GURL("http://www.example.com/*"))); |
| 78 ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/xx*"))); |
| 79 |
| 80 // "xxx*" should be matched longer than "/xx*". |
| 81 ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/xxx*"))); |
| 82 |
| 83 ASSERT_FALSE(matcher.MatchLongest(GURL("http://www.example.com/xxxx*"))); |
| 84 } |
| 85 |
| 86 TEST(ServiceWorkerUtilsTest, FindLongestScopeMatch_SameLength) { |
| 87 LongestScopeMatcher matcher1(GURL("http://www.example.com/xxx")); |
| 88 |
| 89 // "/xxx" has the same length with "/xx*", so they are compared as strings |
| 90 // and "/xxx" should win. |
| 91 // TODO(nhiroki): This isn't in the spec (see: service_worker_utils.cc) |
| 92 ASSERT_TRUE(matcher1.MatchLongest(GURL("http://www.example.com/xxx"))); |
| 93 ASSERT_FALSE(matcher1.MatchLongest(GURL("http://www.example.com/xx*"))); |
| 94 |
| 95 LongestScopeMatcher matcher2(GURL("http://www.example.com/x(1)")); |
| 96 |
| 97 // "/xx*" should be prioritized over "/x(1)". |
| 98 // TODO(nhiroki): This isn't in the spec (see: service_worker_utils.cc) |
| 99 ASSERT_TRUE(matcher2.MatchLongest(GURL("http://www.example.com/x(1)"))); |
| 100 ASSERT_TRUE(matcher2.MatchLongest(GURL("http://www.example.com/x(1*"))); |
| 101 } |
| 102 |
| 72 } // namespace content | 103 } // namespace content |
| OLD | NEW |