FIRAuthWebUtilsTests.m 2.5 KB

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