| 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..ae813abf6375b348627c8d5d43abb42f575e69c9 100644 | 
| --- a/content/browser/service_worker/service_worker_utils_unittest.cc | 
| +++ b/content/browser/service_worker/service_worker_utils_unittest.cc | 
| @@ -8,65 +8,169 @@ | 
| namespace content { | 
|  | 
| TEST(ServiceWorkerUtilsTest, ScopeMatches) { | 
| -  ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( | 
| -      GURL("http://www.example.com/*"), GURL("http://www.example.com/"))); | 
| -  ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( | 
| -      GURL("http://www.example.com/*"), | 
| -      GURL("http://www.example.com/page.html"))); | 
| - | 
| -  ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( | 
| -      GURL("http://www.example.com/*"), GURL("https://www.example.com/"))); | 
| -  ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( | 
| -      GURL("http://www.example.com/*"), | 
| -      GURL("https://www.example.com/page.html"))); | 
| - | 
| -  ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( | 
| -      GURL("http://www.example.com/*"), GURL("http://www.foo.com/"))); | 
| -  ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( | 
| -      GURL("http://www.example.com/*"), GURL("https://www.foo.com/page.html"))); | 
| - | 
| -  ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( | 
| -      GURL("http://www.example.com/"), GURL("http://www.example.com/"))); | 
| -  ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( | 
| -      GURL("http://www.example.com/"), GURL("http://www.example.com/x"))); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_WILDCARD_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/*"), | 
| +                GURL("http://www.example.com/"))); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_WILDCARD_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/*"), | 
| +                GURL("http://www.example.com/page.html"))); | 
| + | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_NO_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/*"), | 
| +                GURL("https://www.example.com/"))); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_NO_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/*"), | 
| +                GURL("https://www.example.com/page.html"))); | 
| + | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_NO_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/*"), | 
| +                GURL("http://www.foo.com/"))); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_NO_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/*"), | 
| +                GURL("https://www.foo.com/page.html"))); | 
| + | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_EXACT_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/"), | 
| +                GURL("http://www.example.com/"))); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_NO_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/"), | 
| +                GURL("http://www.example.com/x"))); | 
|  | 
| // '?' is not a wildcard. | 
| -  ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( | 
| -      GURL("http://www.example.com/?"), GURL("http://www.example.com/x"))); | 
| -  ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( | 
| -      GURL("http://www.example.com/?"), GURL("http://www.example.com/"))); | 
| -  ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( | 
| -      GURL("http://www.example.com/?"), GURL("http://www.example.com/xx"))); | 
| -  ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( | 
| -      GURL("http://www.example.com/?"), GURL("http://www.example.com/?"))); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_NO_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/?"), | 
| +                GURL("http://www.example.com/x"))); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_NO_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/?"), | 
| +                GURL("http://www.example.com/"))); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_NO_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/?"), | 
| +                GURL("http://www.example.com/xx"))); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_EXACT_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/?"), | 
| +                GURL("http://www.example.com/?"))); | 
|  | 
| // Query string is part of the resource. | 
| -  ASSERT_TRUE( | 
| -      ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/?a=b"), | 
| -                                       GURL("http://www.example.com/?a=b"))); | 
| -  ASSERT_TRUE( | 
| -      ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/?a=*"), | 
| -                                       GURL("http://www.example.com/?a=b"))); | 
| -  ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( | 
| -      GURL("http://www.example.com/*"), GURL("http://www.example.com/?a=b"))); | 
| -  ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( | 
| -      GURL("http://www.example.com/"), GURL("http://www.example.com/?a=b"))); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_EXACT_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/?a=b"), | 
| +                GURL("http://www.example.com/?a=b"))); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_WILDCARD_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/?a=*"), | 
| +                GURL("http://www.example.com/?a=b"))); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_WILDCARD_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/*"), | 
| +                GURL("http://www.example.com/?a=b"))); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_NO_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/"), | 
| +                GURL("http://www.example.com/?a=b"))); | 
|  | 
| // '*' only has special meaning in terminal position. | 
| -  ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( | 
| -      GURL("http://www.example.com/*/x"), GURL("http://www.example.com/*/x"))); | 
| -  ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( | 
| -      GURL("http://www.example.com/*/x"), GURL("http://www.example.com/a/x"))); | 
| -  ASSERT_FALSE( | 
| -      ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/*/x/*"), | 
| -                                       GURL("http://www.example.com/a/x/b"))); | 
| -  ASSERT_TRUE( | 
| -      ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/*/x/*"), | 
| -                                       GURL("http://www.example.com/*/x/b"))); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_EXACT_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/*/x"), | 
| +                GURL("http://www.example.com/*/x"))); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_NO_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/*/x"), | 
| +                GURL("http://www.example.com/a/x"))); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_NO_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/*/x/*"), | 
| +                GURL("http://www.example.com/a/x/b"))); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_WILDCARD_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/*/x/*"), | 
| +                GURL("http://www.example.com/*/x/b"))); | 
|  | 
| // URLs canonicalize \ to / so this is equivalent to  "...//*" and "...//x" | 
| -  ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( | 
| -      GURL("http://www.example.com/\\*"), GURL("http://www.example.com/\\x"))); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_WILDCARD_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches( | 
| +                GURL("http://www.example.com/\\*"), | 
| +                GURL("http://www.example.com/\\x"))); | 
| +} | 
| + | 
| +TEST(ServiceWorkerUtilsTest, CompareScopePriorities) { | 
| +  GURL url("http://www.example.com/xxx"); | 
| + | 
| +  GURL scope1("http://www.example.com/x*"); | 
| +  GURL scope2("http://www.example.com/xxx"); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_WILDCARD_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches(scope1, url)); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_EXACT_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches(scope2, url)); | 
| +  ASSERT_GT(0, ServiceWorkerUtils::CompareScopePriorities(scope1, scope2)); | 
| + | 
| +  scope1 = GURL("http://www.example.com/xxx"); | 
| +  scope2 = GURL("http://www.example.com/x*"); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_EXACT_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches(scope1, url)); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_WILDCARD_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches(scope2, url)); | 
| +  ASSERT_LT(0, ServiceWorkerUtils::CompareScopePriorities(scope1, scope2)); | 
| + | 
| +  scope1 = GURL("http://www.example.com/xxx*"); | 
| +  scope2 = GURL("http://www.example.com/xxx"); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_WILDCARD_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches(scope1, url)); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_EXACT_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches(scope2, url)); | 
| +  ASSERT_GT(0, ServiceWorkerUtils::CompareScopePriorities(scope1, scope2)); | 
| + | 
| +  scope1 = GURL("http://www.example.com/xxx"); | 
| +  scope2 = GURL("http://www.example.com/xxx*"); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_EXACT_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches(scope1, url)); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_WILDCARD_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches(scope2, url)); | 
| +  ASSERT_LT(0, ServiceWorkerUtils::CompareScopePriorities(scope1, scope2)); | 
| + | 
| +  scope1 = GURL("http://www.example.com/xxx"); | 
| +  scope2 = GURL("http://www.example.com/xxx"); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_EXACT_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches(scope1, url)); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_EXACT_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches(scope2, url)); | 
| +  ASSERT_EQ(0, ServiceWorkerUtils::CompareScopePriorities(scope1, scope2)); | 
| + | 
| +  scope1 = GURL("http://www.example.com/x*"); | 
| +  scope2 = GURL("http://www.example.com/x*"); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_WILDCARD_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches(scope1, url)); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_WILDCARD_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches(scope2, url)); | 
| +  ASSERT_EQ(0, ServiceWorkerUtils::CompareScopePriorities(scope1, scope2)); | 
| + | 
| +  scope1 = GURL("http://www.example.com/*"); | 
| +  scope2 = GURL("http://www.example.com/xx*"); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_WILDCARD_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches(scope1, url)); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_WILDCARD_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches(scope2, url)); | 
| +  ASSERT_GT(0, ServiceWorkerUtils::CompareScopePriorities(scope1, scope2)); | 
| + | 
| +  scope1 = GURL("http://www.example.com/xx*"); | 
| +  scope2 = GURL("http://www.example.com/*"); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_WILDCARD_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches(scope1, url)); | 
| +  ASSERT_EQ(ServiceWorkerUtils::SCOPE_WILDCARD_MATCH, | 
| +            ServiceWorkerUtils::ScopeMatches(scope2, url)); | 
| +  ASSERT_LT(0, ServiceWorkerUtils::CompareScopePriorities(scope1, scope2)); | 
| } | 
|  | 
| }  // namespace content | 
|  |