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

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

Issue 304423004: ServiceWorker: Scope should match url in longest-prefix-match way (won't commit) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compile error Created 6 years, 6 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 GURL("http://www.example.com/a/x/b"))); 62 GURL("http://www.example.com/a/x/b")));
63 ASSERT_TRUE( 63 ASSERT_TRUE(
64 ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/*/x/*"), 64 ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/*/x/*"),
65 GURL("http://www.example.com/*/x/b"))); 65 GURL("http://www.example.com/*/x/b")));
66 66
67 // URLs canonicalize \ to / so this is equivalent to "...//*" and "...//x" 67 // URLs canonicalize \ to / so this is equivalent to "...//*" and "...//x"
68 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( 68 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
69 GURL("http://www.example.com/\\*"), GURL("http://www.example.com/\\x"))); 69 GURL("http://www.example.com/\\*"), GURL("http://www.example.com/\\x")));
70 } 70 }
71 71
72 TEST(ServiceWorkerUtilsTest, FindLongestScopeMatch) {
73 GURL url("http://www.example.com/xxx");
74 size_t pos = 0;
75
76 std::vector<GURL> scopes;
77 scopes.push_back(GURL("http://www.example.com/*"));
78 scopes.push_back(GURL("http://www.example.com/x*"));
79 scopes.push_back(GURL("http://www.example.com/xx*"));
80
81 // Should be matched with "/xx*".
82 ASSERT_TRUE(ServiceWorkerUtils::FindLongestScopeMatch(scopes, url, &pos));
83 ASSERT_EQ(2u, pos);
84 pos = 0;
85
86 scopes.push_back(GURL("http://www.example.com/xxx"));
87
88 // Should be matched with "/xxx".
89 ASSERT_TRUE(ServiceWorkerUtils::FindLongestScopeMatch(scopes, url, &pos));
90 ASSERT_EQ(3u, pos);
91 pos = 0;
92
93 scopes.push_back(GURL("http://www.example.com/xxx*"));
94
95 // Should be matched with "/xxx*".
96 ASSERT_TRUE(ServiceWorkerUtils::FindLongestScopeMatch(scopes, url, &pos));
97 ASSERT_EQ(4u, pos);
98 }
99
72 } // namespace content 100 } // 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