OLD | NEW |
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 namespace { | 10 namespace { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 LongestScopeMatcher matcher(GURL("http://www.example.com/xxx")); | 95 LongestScopeMatcher matcher(GURL("http://www.example.com/xxx")); |
96 | 96 |
97 // "/xx" should be matched longest. | 97 // "/xx" should be matched longest. |
98 ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/x"))); | 98 ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/x"))); |
99 ASSERT_FALSE(matcher.MatchLongest(GURL("http://www.example.com/"))); | 99 ASSERT_FALSE(matcher.MatchLongest(GURL("http://www.example.com/"))); |
100 ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/xx"))); | 100 ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/xx"))); |
101 | 101 |
102 // "/xxx" should be matched longer than "/xx". | 102 // "/xxx" should be matched longer than "/xx". |
103 ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/xxx"))); | 103 ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/xxx"))); |
104 | 104 |
| 105 // The second call with the same URL should return false. |
| 106 ASSERT_FALSE(matcher.MatchLongest(GURL("http://www.example.com/xxx"))); |
| 107 |
105 ASSERT_FALSE(matcher.MatchLongest(GURL("http://www.example.com/xxxx"))); | 108 ASSERT_FALSE(matcher.MatchLongest(GURL("http://www.example.com/xxxx"))); |
106 } | 109 } |
107 | 110 |
108 TEST(ServiceWorkerUtilsTest, PathRestriction_Basic) { | 111 TEST(ServiceWorkerUtilsTest, PathRestriction_Basic) { |
109 EXPECT_TRUE(IsPathRestrictionSatisfied( | 112 EXPECT_TRUE(IsPathRestrictionSatisfied( |
110 GURL("http://example.com/"), | 113 GURL("http://example.com/"), |
111 GURL("http://example.com/sw.js"))); | 114 GURL("http://example.com/sw.js"))); |
112 EXPECT_TRUE(IsPathRestrictionSatisfied( | 115 EXPECT_TRUE(IsPathRestrictionSatisfied( |
113 GURL("http://example.com/foo/"), | 116 GURL("http://example.com/foo/"), |
114 GURL("http://example.com/sw.js"))); | 117 GURL("http://example.com/sw.js"))); |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 | 405 |
403 // Empty string resolves to max scope of "http://www.example.com/sw.js". | 406 // Empty string resolves to max scope of "http://www.example.com/sw.js". |
404 EXPECT_FALSE(IsPathRestrictionSatisfiedWithServiceWorkerAllowedHeader( | 407 EXPECT_FALSE(IsPathRestrictionSatisfiedWithServiceWorkerAllowedHeader( |
405 GURL("http://example.com/"), GURL("http://example.com/sw.js"), "")); | 408 GURL("http://example.com/"), GURL("http://example.com/sw.js"), "")); |
406 EXPECT_TRUE(IsPathRestrictionSatisfiedWithServiceWorkerAllowedHeader( | 409 EXPECT_TRUE(IsPathRestrictionSatisfiedWithServiceWorkerAllowedHeader( |
407 GURL("http://example.com/sw.js/hi"), GURL("http://example.com/sw.js"), | 410 GURL("http://example.com/sw.js/hi"), GURL("http://example.com/sw.js"), |
408 "")); | 411 "")); |
409 } | 412 } |
410 | 413 |
411 } // namespace content | 414 } // namespace content |
OLD | NEW |