@@ -26,6 +26,7 @@ class TestHTTPCookieStorage: XCTestCase {
2626 ( " test_cookiesForURLWithMainDocumentURL " , test_cookiesForURLWithMainDocumentURL) ,
2727 ( " test_cookieInXDGSpecPath " , test_cookieInXDGSpecPath) ,
2828 ( " test_descriptionCookie " , test_descriptionCookie) ,
29+ ( " test_cookieDomainMatching " , test_cookieDomainMatching) ,
2930 ]
3031 }
3132
@@ -89,6 +90,11 @@ class TestHTTPCookieStorage: XCTestCase {
8990 descriptionCookie ( with: . groupContainer( " test " ) )
9091 }
9192
93+ func test_cookieDomainMatching( ) {
94+ cookieDomainMatching ( with: . shared)
95+ cookieDomainMatching ( with: . groupContainer( " test " ) )
96+ }
97+
9298 func getStorage( for type: _StorageType ) -> HTTPCookieStorage {
9399 switch type {
94100 case . shared:
@@ -272,6 +278,49 @@ class TestHTTPCookieStorage: XCTestCase {
272278 XCTAssertEqual ( storage. description, " <NSHTTPCookieStorage cookies count: \( cookies1. count) > " )
273279 }
274280
281+ func cookieDomainMatching( with storageType: _StorageType ) {
282+ let storage = getStorage ( for: storageType)
283+
284+ let simpleCookie1 = HTTPCookie ( properties: [ // swift.org domain only
285+ . name: " TestCookie1 " ,
286+ . value: " TestValue1 " ,
287+ . path: " / " ,
288+ . domain: " swift.org " ,
289+ ] ) !
290+
291+ storage. setCookie ( simpleCookie1)
292+
293+ let simpleCookie2 = HTTPCookie ( properties: [ // *.swift.org
294+ . name: " TestCookie2 " ,
295+ . value: " TestValue2 " ,
296+ . path: " / " ,
297+ . domain: " .SWIFT.org " ,
298+ ] ) !
299+
300+ storage. setCookie ( simpleCookie2)
301+
302+ let simpleCookie3 = HTTPCookie ( properties: [ // bugs.swift.org
303+ . name: " TestCookie3 " ,
304+ . value: " TestValue3 " ,
305+ . path: " / " ,
306+ . domain: " bugs.swift.org " ,
307+ ] ) !
308+
309+ storage. setCookie ( simpleCookie3)
310+ XCTAssertEqual ( storage. cookies!. count, 3 )
311+
312+ let swiftOrgUrl = URL ( string: " https://swift.ORG " ) !
313+ let ciSwiftOrgUrl = URL ( string: " https://CI.swift.ORG " ) !
314+ let bugsSwiftOrgUrl = URL ( string: " https://BUGS.swift.org " ) !
315+ let exampleComUrl = URL ( string: " http://www.example.com " ) !
316+ let superSwiftOrgUrl = URL ( string: " https://superswift.org " ) !
317+ XCTAssertEqual ( Set ( storage. cookies ( for: swiftOrgUrl) !) , Set ( [ simpleCookie1, simpleCookie2] ) )
318+ XCTAssertEqual ( storage. cookies ( for: ciSwiftOrgUrl) !, [ simpleCookie2] )
319+ XCTAssertEqual ( Set ( storage. cookies ( for: bugsSwiftOrgUrl) !) , Set ( [ simpleCookie2, simpleCookie3] ) )
320+ XCTAssertEqual ( storage. cookies ( for: exampleComUrl) !, [ ] )
321+ XCTAssertEqual ( storage. cookies ( for: superSwiftOrgUrl) !, [ ] )
322+ }
323+
275324 func test_cookieInXDGSpecPath( ) {
276325#if !os(Android) && !DARWIN_COMPATIBILITY_TESTS
277326 //Test without setting the environment variable
0 commit comments