web_client_unittest.mm 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #import "ios/web/public/web_client.h"
  5. #import <Foundation/Foundation.h>
  6. #include "net/ssl/ssl_info.h"
  7. #include "testing/gtest_mac.h"
  8. #include "testing/platform_test.h"
  9. #include "url/gurl.h"
  10. #if !defined(__has_feature) || !__has_feature(objc_arc)
  11. #error "This file requires ARC support."
  12. #endif
  13. using WebClientTest = PlatformTest;
  14. // Tests WebClient::PrepareErrorPage method.
  15. TEST_F(WebClientTest, PrepareErrorPage) {
  16. web::WebClient web_client;
  17. NSString* const description = @"a pretty bad error";
  18. NSError* error =
  19. [NSError errorWithDomain:NSURLErrorDomain
  20. code:NSURLErrorNotConnectedToInternet
  21. userInfo:@{NSLocalizedDescriptionKey : description}];
  22. absl::optional<net::SSLInfo> info = absl::nullopt;
  23. __block bool callback_called = false;
  24. __block NSString* html = nil;
  25. web_client.PrepareErrorPage(/*web_state*/ nullptr, GURL::EmptyGURL(), error,
  26. /*is_post=*/false,
  27. /*is_off_the_record=*/false,
  28. /*info=*/info,
  29. /*navigation_id=*/0,
  30. base::BindOnce(^(NSString* error_html) {
  31. html = error_html;
  32. callback_called = true;
  33. }));
  34. EXPECT_TRUE(callback_called);
  35. EXPECT_NSEQ(description, html);
  36. }