Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: content/browser/service_worker/service_worker_utils_unittest.cc

Issue 288693002: ServiceWorker: * is only wildcard at end of scope URLs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: leaner Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/service_worker/service_worker_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 matching lines...) Expand all
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 27
28 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( 28 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
29 GURL("http://www.example.com/"), GURL("http://www.example.com/"))); 29 GURL("http://www.example.com/"), GURL("http://www.example.com/")));
30 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( 30 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
31 GURL("http://www.example.com/"), GURL("http://www.example.com/x"))); 31 GURL("http://www.example.com/"), GURL("http://www.example.com/x")));
32 32
33 // '?' is not a wildcard.
33 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( 34 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
34 GURL("http://www.example.com/?"), GURL("http://www.example.com/x"))); 35 GURL("http://www.example.com/?"), GURL("http://www.example.com/x")));
35 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( 36 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
36 GURL("http://www.example.com/?"), GURL("http://www.example.com/"))); 37 GURL("http://www.example.com/?"), GURL("http://www.example.com/")));
37 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( 38 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
38 GURL("http://www.example.com/?"), GURL("http://www.example.com/xx"))); 39 GURL("http://www.example.com/?"), GURL("http://www.example.com/xx")));
39 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( 40 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
40 GURL("http://www.example.com/?"), GURL("http://www.example.com/?"))); 41 GURL("http://www.example.com/?"), GURL("http://www.example.com/?")));
41 42
43 // Query string is part of the resource.
44 ASSERT_TRUE(
45 ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/?a=b"),
46 GURL("http://www.example.com/?a=b")));
47 ASSERT_TRUE(
48 ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/?a=*"),
49 GURL("http://www.example.com/?a=b")));
50 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
51 GURL("http://www.example.com/*"), GURL("http://www.example.com/?a=b")));
52 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
53 GURL("http://www.example.com/"), GURL("http://www.example.com/?a=b")));
54
55 // '*' only has special meaning in terminal position.
56 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
57 GURL("http://www.example.com/*/x"), GURL("http://www.example.com/*/x")));
58 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
59 GURL("http://www.example.com/*/x"), GURL("http://www.example.com/a/x")));
60 ASSERT_FALSE(
61 ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/*/x/*"),
62 GURL("http://www.example.com/a/x/b")));
63 ASSERT_TRUE(
64 ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/*/x/*"),
65 GURL("http://www.example.com/*/x/b")));
66
42 // URLs canonicalize \ to / so this is equivalent to "...//*" and "...//x" 67 // URLs canonicalize \ to / so this is equivalent to "...//*" and "...//x"
43 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( 68 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
44 GURL("http://www.example.com/\\*"), GURL("http://www.example.com/\\x"))); 69 GURL("http://www.example.com/\\*"), GURL("http://www.example.com/\\x")));
45 } 70 }
46 71
47 } // namespace content 72 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698