web_view_inttest_base.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2017 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. #ifndef IOS_WEB_VIEW_TEST_WEB_VIEW_INTTEST_BASE_H_
  5. #define IOS_WEB_VIEW_TEST_WEB_VIEW_INTTEST_BASE_H_
  6. #import <Foundation/Foundation.h>
  7. #include <memory>
  8. #include <string>
  9. #include "components/variations/scoped_variations_ids_provider.h"
  10. #include "testing/platform_test.h"
  11. NS_ASSUME_NONNULL_BEGIN
  12. namespace net {
  13. namespace test_server {
  14. class EmbeddedTestServer;
  15. } // namespace test_server
  16. } // namespace net
  17. @class CWVWebView;
  18. class GURL;
  19. @class NSURL;
  20. namespace ios_web_view {
  21. // A test fixture for testing CWVWebView. A test server is also created to
  22. // support loading content. The server supports the urls returned by the GetUrl*
  23. // methods below.
  24. class WebViewInttestBase : public PlatformTest {
  25. protected:
  26. WebViewInttestBase();
  27. ~WebViewInttestBase() override;
  28. // Returns URL to an html page with title set to |title|.
  29. //
  30. // Call ASSERT_TRUE(test_server_->Start()) before accessing the returned URL.
  31. GURL GetUrlForPageWithTitle(const std::string& title);
  32. // Returns URL to an html page with |html| within page's body tags.
  33. //
  34. // Call ASSERT_TRUE(test_server_->Start()) before accessing the returned URL.
  35. GURL GetUrlForPageWithHtmlBody(const std::string& html);
  36. // Returns URL to an html page with title set to |title| and |body| within
  37. // the page's body tags.
  38. //
  39. // Call ASSERT_TRUE(test_server_->Start()) before accessing the returned URL.
  40. GURL GetUrlForPageWithTitleAndBody(const std::string& title,
  41. const std::string& body);
  42. // Returns URL to an html page with |html|. |html| contains entire html of the
  43. // page.
  44. //
  45. // Call ASSERT_TRUE(test_server_->Start()) before accessing the returned URL.
  46. GURL GetUrlForPageWithHtml(const std::string& html);
  47. variations::ScopedVariationsIdsProvider scoped_variations_ids_provider_{
  48. variations::VariationsIdsProvider::Mode::kUseSignedInState};
  49. // CWVWebView created with default configuration and frame equal to screen
  50. // bounds.
  51. CWVWebView* web_view_;
  52. // Embedded server for handling requests sent to the URLs returned by the
  53. // GetURL* methods.
  54. std::unique_ptr<net::test_server::EmbeddedTestServer> test_server_;
  55. };
  56. } // namespace ios_web_view
  57. NS_ASSUME_NONNULL_END
  58. #endif // IOS_WEB_VIEW_TEST_WEB_VIEW_INTTEST_BASE_H_