Skip to content

TestHTTPCookieStorage: Remove order dependancy of tests #1316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions TestFoundation/TestHTTPCookieStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ class TestHTTPCookieStorage: XCTestCase {
("test_BasicStorageAndRetrieval", test_BasicStorageAndRetrieval),
("test_deleteCookie", test_deleteCookie),
("test_removeCookies", test_removeCookies),
("test_setCookiesForURL", test_setCookiesForURL),
("test_getCookiesForURL", test_getCookiesForURL),
("test_setCookiesForURLWithMainDocumentURL", test_setCookiesForURLWithMainDocumentURL),
("test_cookiesForURL", test_cookiesForURL),
("test_cookiesForURLWithMainDocumentURL", test_cookiesForURLWithMainDocumentURL),
("test_cookieInXDGSpecPath", test_cookieInXDGSpecPath),
]
}

override func setUp() {
// Delete any cookies in the storage
getStorage(for: .shared).removeCookies(since: Date(timeIntervalSince1970: 0))
getStorage(for: .groupContainer("test")).removeCookies(since: Date(timeIntervalSince1970: 0))
}

func test_sharedCookieStorageAccessedFromMultipleThreads() {
let q = DispatchQueue.global()
let syncQ = DispatchQueue(label: "TestHTTPCookieStorage.syncQ")
Expand Down Expand Up @@ -72,17 +77,15 @@ class TestHTTPCookieStorage: XCTestCase {
removeCookies(with: .groupContainer("test"))
}

func test_setCookiesForURL() {
func test_cookiesForURL() {
setCookiesForURL(with: .shared)
setCookiesForURL(with: .groupContainer("test"))
}

func test_getCookiesForURL() {
getCookiesForURL(with: .shared)

setCookiesForURL(with: .groupContainer("test"))
getCookiesForURL(with: .groupContainer("test"))
}

func test_setCookiesForURLWithMainDocumentURL() {
func test_cookiesForURLWithMainDocumentURL() {
setCookiesForURLWithMainDocumentURL(with: .shared)
setCookiesForURLWithMainDocumentURL(with: .groupContainer("test"))
}
Expand Down Expand Up @@ -159,9 +162,11 @@ class TestHTTPCookieStorage: XCTestCase {
.expires: Date(timeIntervalSince1970: Date().timeIntervalSince1970 + 1000)
])!
storage.setCookie(simpleCookie)
storage.setCookie(simpleCookie2)
XCTAssertEqual(storage.cookies!.count, 2)

storage.deleteCookie(simpleCookie)
XCTAssertEqual(storage.cookies!.count, 1)
storage.deleteCookie(simpleCookie2)
XCTAssertEqual(storage.cookies!.count, 0)
}
Expand Down Expand Up @@ -225,7 +230,7 @@ class TestHTTPCookieStorage: XCTestCase {
.domain: "swift.org",
])!
storage.setCookies([simpleCookie], for: url, mainDocumentURL: mainUrl)
XCTAssertEqual(storage.cookies(for: url!)!.count, 2)
XCTAssertEqual(storage.cookies(for: url!)!.count, 1)

let url1 = URL(string: "https://dt.swift.org/downloads")
let simpleCookie1 = HTTPCookie(properties: [
Expand All @@ -249,7 +254,7 @@ class TestHTTPCookieStorage: XCTestCase {
])!
let storage = HTTPCookieStorage.shared
storage.setCookie(testCookie)
XCTAssertEqual(storage.cookies!.count, 3)
XCTAssertEqual(storage.cookies!.count, 1)
var destPath: String
let bundlePath = Bundle.main.bundlePath
var bundleName = "/" + bundlePath.components(separatedBy: "/").last!
Expand Down