| 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) { |
| 11 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( | 11 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( |
| 12 GURL("http://www.example.com/*"), GURL("http://www.example.com/"))); | 12 GURL("http://www.example.com/*"), GURL("http://www.example.com/"))); |
| 13 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( | 13 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( |
| 14 GURL("http://www.example.com/*"), | 14 GURL("http://www.example.com/*"), |
| 15 GURL("http://www.example.com/page.html"))); | 15 GURL("http://www.example.com/page.html"))); |
| 16 | 16 |
| 17 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( | 17 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( |
| 18 GURL("http://www.example.com/*"), GURL("https://www.example.com/"))); | 18 GURL("http://www.example.com/*"), GURL("https://www.example.com/"))); |
| 19 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( | 19 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( |
| 20 GURL("http://www.example.com/*"), | 20 GURL("http://www.example.com/*"), |
| 21 GURL("https://www.example.com/page.html"))); | 21 GURL("https://www.example.com/page.html"))); |
| 22 | 22 |
| 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 |
| 28 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( |
| 29 GURL("http://www.example.com/"), GURL("http://www.example.com/"))); |
| 30 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( |
| 31 GURL("http://www.example.com/"), GURL("http://www.example.com/x"))); |
| 32 |
| 33 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( |
| 34 GURL("http://www.example.com/?"), GURL("http://www.example.com/x"))); |
| 35 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( |
| 36 GURL("http://www.example.com/?"), GURL("http://www.example.com/"))); |
| 37 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( |
| 38 GURL("http://www.example.com/?"), GURL("http://www.example.com/xx"))); |
| 39 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( |
| 40 GURL("http://www.example.com/?"), GURL("http://www.example.com/?"))); |
| 41 |
| 42 // URLs canonicalize \ to / so this is equivalent to "...//*" and "...//x" |
| 43 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( |
| 44 GURL("http://www.example.com/\\*"), GURL("http://www.example.com/\\x"))); |
| 27 } | 45 } |
| 28 | 46 |
| 29 } // namespace content | 47 } // namespace content |
| OLD | NEW |