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

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: 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
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 // '*' only has special meaning in terminal position.
44 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
45 GURL("http://www.example.com/*/x"), GURL("http://www.example.com/*/x")));
46 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
47 GURL("http://www.example.com/*/x"), GURL("http://www.example.com/a/x")));
48 ASSERT_FALSE(
49 ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/*/x/*"),
50 GURL("http://www.example.com/a/x/b")));
51 ASSERT_TRUE(
52 ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/*/x/*"),
53 GURL("http://www.example.com/*/x/b")));
54
42 // URLs canonicalize \ to / so this is equivalent to "...//*" and "...//x" 55 // URLs canonicalize \ to / so this is equivalent to "...//*" and "...//x"
43 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( 56 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
44 GURL("http://www.example.com/\\*"), GURL("http://www.example.com/\\x"))); 57 GURL("http://www.example.com/\\*"), GURL("http://www.example.com/\\x")));
45 } 58 }
46 59
47 } // namespace content 60 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698