| 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) { |
| 73 GURL url("http://www.example.com/xxx"); |
| 74 size_t pos = 0; |
| 75 |
| 76 std::vector<GURL> scopes; |
| 77 scopes.push_back(GURL("http://www.example.com/*")); |
| 78 scopes.push_back(GURL("http://www.example.com/x*")); |
| 79 scopes.push_back(GURL("http://www.example.com/xx*")); |
| 80 |
| 81 // Should be matched with "/xx*". |
| 82 ASSERT_TRUE(ServiceWorkerUtils::FindLongestScopeMatch(scopes, url, &pos)); |
| 83 ASSERT_EQ(2u, pos); |
| 84 pos = 0; |
| 85 |
| 86 scopes.push_back(GURL("http://www.example.com/xxx")); |
| 87 |
| 88 // Should be matched with "/xxx". |
| 89 ASSERT_TRUE(ServiceWorkerUtils::FindLongestScopeMatch(scopes, url, &pos)); |
| 90 ASSERT_EQ(3u, pos); |
| 91 pos = 0; |
| 92 |
| 93 scopes.push_back(GURL("http://www.example.com/xxx*")); |
| 94 |
| 95 // Should be matched with "/xxx*". |
| 96 ASSERT_TRUE(ServiceWorkerUtils::FindLongestScopeMatch(scopes, url, &pos)); |
| 97 ASSERT_EQ(4u, pos); |
| 98 } |
| 99 |
| 72 } // namespace content | 100 } // namespace content |
| OLD | NEW |