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
3 // found in the LICENSE file.
5 #include "content/browser/service_worker/service_worker_utils.h"
6 #include "testing/gtest/include/gtest/gtest.h"
10 TEST(ServiceWorkerUtilsTest, ScopeMatches) {
11 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
12 GURL("http://www.example.com/*"), GURL("http://www.example.com/")));
13 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
14 GURL("http://www.example.com/*"),
15 GURL("http://www.example.com/page.html")));
17 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
18 GURL("http://www.example.com/*"), GURL("https://www.example.com/")));
19 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
20 GURL("http://www.example.com/*"),
21 GURL("https://www.example.com/page.html")));
23 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
24 GURL("http://www.example.com/*"), GURL("http://www.foo.com/")));
25 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
26 GURL("http://www.example.com/*"), GURL("https://www.foo.com/page.html")));
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")));
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/?")));
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")));
47 } // namespace content