AuthWebUtilsTests.swift 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License")
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import Foundation
  15. import XCTest
  16. @testable import FirebaseAuth
  17. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  18. class AuthWebUtilsTests: XCTestCase {
  19. /** @fn testExtractDomainWithHTTP
  20. @brief Test case for extracting the domain from a URL with "http://" scheme.
  21. */
  22. func testExtractDomainWithHTTP() {
  23. let urlString = "http://www.example.com/path/to/resource"
  24. let domain = AuthWebUtils.extractDomain(urlString: urlString)
  25. XCTAssertEqual(domain, "www.example.com")
  26. }
  27. /** @fn testExtractDomainWithHTTPS
  28. @brief Test case for extracting the domain from a URL with "https://" scheme.
  29. */
  30. func testExtractDomainWithHTTPS() {
  31. let urlString = "https://www.example.com/path/to/resource/"
  32. let domain = AuthWebUtils.extractDomain(urlString: urlString)
  33. XCTAssertEqual(domain, "www.example.com")
  34. }
  35. /** @fn testExtractDomainWithoutScheme
  36. @brief Test case for extracting the domain from a URL without a scheme (assumes HTTP by default).
  37. */
  38. func testExtractDomainWithoutScheme() {
  39. let urlString = "www.example.com/path/to/resource"
  40. let domain = AuthWebUtils.extractDomain(urlString: urlString)
  41. XCTAssertEqual(domain, "www.example.com")
  42. }
  43. /** @fn testExtractDomainWithTrailingSlashes
  44. @brief Test case for extracting the domain from a URL with trailing slashes.
  45. */
  46. func testExtractDomainWithTrailingSlashes() {
  47. let urlString = "http://www.example.com//////"
  48. let domain = AuthWebUtils.extractDomain(urlString: urlString)
  49. XCTAssertEqual(domain, "www.example.com")
  50. }
  51. /** @fn testExtractDomainWithStringDomain
  52. @brief Test case for extracting the domain from a string that represents just the domain itself.
  53. */
  54. func testExtractDomainWithStringDomain() {
  55. let urlString = "example.com"
  56. let domain = AuthWebUtils.extractDomain(urlString: urlString)
  57. XCTAssertEqual(domain, "example.com")
  58. }
  59. }