web_view_test_util.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_TEST_UTIL_H_
  5. #define IOS_WEB_VIEW_TEST_WEB_VIEW_TEST_UTIL_H_
  6. #import <Foundation/Foundation.h>
  7. NS_ASSUME_NONNULL_BEGIN
  8. @class CWVWebView;
  9. namespace ios_web_view {
  10. namespace test {
  11. // Creates web view with default configuration and frame equal to screen bounds.
  12. [[nodiscard]] CWVWebView* CreateWebView();
  13. // Loads |URL| in |web_view| and waits until the load completes. Asserts if
  14. // loading does not complete.
  15. [[nodiscard]] bool LoadUrl(CWVWebView* web_view, NSURL* url);
  16. // Returns whether the element with |element_id| in the passed |web_view| has
  17. // been tapped using a JavaScript click() event.
  18. [[nodiscard]] bool TapWebViewElementWithId(CWVWebView* web_view,
  19. NSString* element_id);
  20. // Waits until |script| is executed and synchronously returns the evaluation
  21. // result.
  22. id EvaluateJavaScript(CWVWebView* web_view,
  23. NSString* script,
  24. bool* success = nullptr);
  25. // Waits for |web_view| to contain |text|. Returns false if the condition is not
  26. // met within a timeout.
  27. [[nodiscard]] bool WaitForWebViewContainingTextOrTimeout(CWVWebView* web_view,
  28. NSString* text);
  29. // Waits until |web_view| stops loading. Returns false if the condition is not
  30. // met within a timeout.
  31. [[nodiscard]] bool WaitForWebViewLoadCompletionOrTimeout(CWVWebView* web_view);
  32. // Copies the state of |source_web_view| to |destination_web_view| using state
  33. // restoration.
  34. void CopyWebViewState(CWVWebView* source_web_view,
  35. CWVWebView* destination_web_view);
  36. } // namespace test
  37. } // namespace ios_web_view
  38. NS_ASSUME_NONNULL_END
  39. #endif // IOS_WEB_VIEW_TEST_WEB_VIEW_TEST_UTIL_H_