Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / browser / service_worker / service_worker_utils_unittest.cc
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.
4
5 #include "content/browser/service_worker/service_worker_utils.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7
8 namespace content {
9
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")));
16
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")));
22
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")));
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")));
45 }
46
47 }  // namespace content