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

Unified Diff: content/browser/service_worker/service_worker_utils_unittest.cc

Issue 294593002: ServiceWorker: Support longest-prefix-match for registration scope (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remake (drop the exact-match) 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_utils_unittest.cc
diff --git a/content/browser/service_worker/service_worker_utils_unittest.cc b/content/browser/service_worker/service_worker_utils_unittest.cc
index d6e0ba1a02c12f6f136810d468b4862836919038..ed8e83cfff969e779c9060ef5a739f8526925d83 100644
--- a/content/browser/service_worker/service_worker_utils_unittest.cc
+++ b/content/browser/service_worker/service_worker_utils_unittest.cc
@@ -69,4 +69,32 @@ TEST(ServiceWorkerUtilsTest, ScopeMatches) {
GURL("http://www.example.com/\\*"), GURL("http://www.example.com/\\x")));
}
+TEST(ServiceWorkerUtilsTest, FindLongestScopeMatch) {
+ GURL url("http://www.example.com/xxx");
+ size_t pos = 0;
+
+ std::vector<GURL> scopes;
+ scopes.push_back(GURL("http://www.example.com/*"));
+ scopes.push_back(GURL("http://www.example.com/x*"));
+ scopes.push_back(GURL("http://www.example.com/xx*"));
+
+ // Should be matched with "/xx*".
+ ASSERT_TRUE(ServiceWorkerUtils::FindLongestScopeMatch(scopes, url, &pos));
+ ASSERT_EQ(2u, pos);
+ pos = 0;
+
+ scopes.push_back(GURL("http://www.example.com/xxx"));
+
+ // Should be matched with "/xxx".
+ ASSERT_TRUE(ServiceWorkerUtils::FindLongestScopeMatch(scopes, url, &pos));
+ ASSERT_EQ(3u, pos);
+ pos = 0;
+
+ scopes.push_back(GURL("http://www.example.com/xxx*"));
+
+ // Should be matched with "/xxx*".
+ ASSERT_TRUE(ServiceWorkerUtils::FindLongestScopeMatch(scopes, url, &pos));
+ ASSERT_EQ(4u, pos);
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698