Revision control
Copy as Markdown
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
import XCTest
@testable import WebEngine
final class URLFormatterTests: XCTestCase {
// MARK: - Valid cases
func testGetURLGivenInternalURLThenValidURL() {
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertEqual(result?.absoluteString, initialUrl)
}
func testGetURLGivenStandardURLThenValidInitialURL() {
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertEqual(result?.absoluteString, initialUrl)
}
func testGetURLGivenAboutConfigURLThenValidInitialURL() {
let initialUrl = "about:config"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertEqual(result?.absoluteString, initialUrl)
}
func testGetURLGivenAboutConfigSpaceURLThenValidEscapedURL() {
let initialUrl = "about: config"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertEqual(result?.absoluteString, "about:%20config")
}
func testGetURLGivenFileURLThenValidInitialURL() {
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertEqual(result?.absoluteString, initialUrl)
}
func testGetURLGivenFtpURLThenValidInitialURL() {
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertEqual(result?.absoluteString, initialUrl)
}
func testGetURLGivenNoHttpsURLThenValidURL() {
let initialUrl = "foo.bar"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
}
func testGetURLGivenNoHttpsURLWithCapitalLetterThenValidURL() {
let initialUrl = "foo.Bar"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
}
func testGetURLGivenNoHttpsWithSpaceURLThenValidURL() {
let initialUrl = "foo.bar"
let givenURL = " \(initialUrl)"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: givenURL)
}
func testGetURLGivenDotURLThenValidURL() {
let initialUrl = "1.2.3"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
}
func testGetURLGivenIconicSydneyThenValidURL() {
let initialUrl = "iconic.sydney"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
}
func testGetURLGivenLocalHostHtmlThenValidURL() {
let initialUrl = "localhost:4242/test-fixture/test-example.html"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
}
func testGetURLGivenLocalHostOnlyThenValidURL() {
let initialUrl = "localhost"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
}
func testGetURLGivenLocalHostWithPathAndCapitalLettersThenValidURL() {
let initialUrl = "LoCalhOsT/foo"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
}
func testGetURLGivenMailtoSchemeURLThenValidURL() {
let initialUrl = "mailto:jsmith@example.com"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertEqual(result?.absoluteString, initialUrl)
}
func testGetURLGivenDNSSchemeURLThenValidURL() {
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertEqual(result?.absoluteString, initialUrl)
}
// MARK: - Invalid cases
func testGetURLGivenEmptyURLThenInvalidURL() {
let initialUrl = ""
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenFooBarURLThenInvalidURL() {
let initialUrl = "foobar"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenFooSpaceBarURLThenInvalidURL() {
let initialUrl = "foo bar"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenURLWithSpaceBeforeTLDThenInvalidURL() {
let initialUrl = "mozilla. org"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenNumbersThenInvalidURL() {
let initialUrl = "123"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenPathThenInvalidURL() {
let initialUrl = "a/b"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenChineseCharactersThenInvalidURL() {
let initialUrl = "创业咖啡"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenChineseCharactersWithSpaceThenInvalidURL() {
let initialUrl = "创业咖啡 ä¸å›½"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenChineseCharactersWithDotAndSpaceThenInvalidURL() {
let initialUrl = "创业咖啡. ä¸å›½"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenAboutSchemeThenInvalidURL() {
let initialUrl = "about:"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenJavascriptSchemeThenInvalidURL() {
let initialUrl = "javascript:"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenJavascriptAlertThenInvalidURL() {
let initialUrl = "javascript:alert(%22hi%22)"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenFtpSchemeThenInvalidURL() {
let initialUrl = "ftp:"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenNumberWithDotNumberThenInvalidURL() {
let initialUrl = "127.1"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenNumberEndingWithDotThenInvalidURL() {
let initialUrl = "999."
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenNegativeDecimalNumberThenInvalidURL() {
let initialUrl = "-.05"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenPositiveDotsNumbersThenInvalidURL() {
let initialUrl = "+2.1.0"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenSuffixNotPublicSuffixThenInvalidURL() {
let initialUrl = "apple.iphone"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenUrlWithSpaceThenInvalidURL() {
let initialUrl = "http:// shouldfail.com"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenURLWithNumbersNoTLDThenInvalidURL() {
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenSpaceInDomainThenInvalidURL() {
let initialUrl = "mo zilla.com"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenSpaceBeforeTLDThenInvalidURL() {
let initialUrl = "www.firefox .com"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenHTTPURLWithSpaceInDomainThenInvalidURL() {
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenWordThenInvalidURL() {
let initialUrl = "mozilla"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenAddressWithBracketsThenInvalidURL() {
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenSpecialCharsThenInvalidURL() {
let initialUrl = ":/#?&@%+~"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenFirefoxSchemeThenInvalidURL() {
let initialUrl = "firefox://"
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenFeedSchemeURLThenInvalidURL() {
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenGitSchemeURLThenInvalidURL() {
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenSmbSchemeURLThenInvalidURL() {
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenViewSourceSchemeURLThenInvalidURL() {
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
func testGetURLGivenNoTLDThenInvalidURL() {
let subject = DefaultURLFormatter()
let result = subject.getURL(entry: initialUrl)
XCTAssertNil(result)
}
}