Skip to content

Add a testcase for HTTPCookieStorage.description #1359

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
Dec 27, 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
39 changes: 36 additions & 3 deletions TestFoundation/TestHTTPCookieStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class TestHTTPCookieStorage: XCTestCase {
("test_cookiesForURL", test_cookiesForURL),
("test_cookiesForURLWithMainDocumentURL", test_cookiesForURLWithMainDocumentURL),
("test_cookieInXDGSpecPath", test_cookieInXDGSpecPath),
("test_descriptionCookie", test_descriptionCookie),
]
}

Expand Down Expand Up @@ -90,6 +91,11 @@ class TestHTTPCookieStorage: XCTestCase {
setCookiesForURLWithMainDocumentURL(with: .groupContainer("test"))
}

func test_descriptionCookie() {
descriptionCookie(with: .shared)
descriptionCookie(with: .groupContainer("test"))
}

func getStorage(for type: _StorageType) -> HTTPCookieStorage {
switch type {
case .shared:
Expand All @@ -112,7 +118,6 @@ class TestHTTPCookieStorage: XCTestCase {

storage.setCookie(simpleCookie)
XCTAssertEqual(storage.cookies!.count, 0)
XCTAssertEqual(storage.description, "<NSHTTPCookieStorage cookies count:0>")

let simpleCookie0 = HTTPCookie(properties: [ //no expiry date
.name: "TestCookie1",
Expand All @@ -123,7 +128,6 @@ class TestHTTPCookieStorage: XCTestCase {

storage.setCookie(simpleCookie0)
XCTAssertEqual(storage.cookies!.count, 1)
XCTAssertEqual(storage.description, "<NSHTTPCookieStorage cookies count:1>")

let simpleCookie1 = HTTPCookie(properties: [
.name: "TestCookie1",
Expand All @@ -144,7 +148,6 @@ class TestHTTPCookieStorage: XCTestCase {

storage.setCookie(simpleCookie2)
XCTAssertEqual(storage.cookies!.count, 2)
XCTAssertEqual(storage.description, "<NSHTTPCookieStorage cookies count:2>")
}

func deleteCookie(with storageType: _StorageType) {
Expand Down Expand Up @@ -246,6 +249,36 @@ class TestHTTPCookieStorage: XCTestCase {
XCTAssertEqual(storage.cookies(for: url1!)!.count, 0)
}

func descriptionCookie(with storageType: _StorageType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this function is only used inside test_descriptionCookie() why not make it a nested function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ianpartridge I see that this pattern (calling a function XXX two times from test_XXX) is used in all the tests in TestHTTPCookieStorage. Do you think doing this as a separate PR will make more sense?

let storage = getStorage(for: storageType)
guard let cookies = storage.cookies else {
XCTFail("No cookies")
return
}
XCTAssertEqual(storage.description, "<NSHTTPCookieStorage cookies count:\(cookies.count)>")

let simpleCookie = HTTPCookie(properties: [
.name: "TestCookie1",
.value: "Test value @#$%^$&*99",
.path: "/",
.domain: "swift.org",
.expires: Date(timeIntervalSince1970: Date().timeIntervalSince1970 + 1000)
])!
storage.setCookie(simpleCookie)
guard let cookies0 = storage.cookies else {
XCTFail("No cookies")
return
}
XCTAssertEqual(storage.description, "<NSHTTPCookieStorage cookies count:\(cookies0.count)>")

storage.deleteCookie(simpleCookie)
guard let cookies1 = storage.cookies else {
XCTFail("No cookies")
return
}
XCTAssertEqual(storage.description, "<NSHTTPCookieStorage cookies count:\(cookies1.count)>")
}

func test_cookieInXDGSpecPath() {
#if !os(Android) && !DARWIN_COMPATIBILITY_TESTS
//Test without setting the environment variable
Expand Down