| 1 | /* |
| 2 | * Copyright (C) 2011, 2017 Igalia S.L. |
| 3 | * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Library General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Library General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Library General Public License |
| 16 | * along with this library; see the file COPYING.LIB. If not, write to |
| 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | * Boston, MA 02110-1301, USA. |
| 19 | */ |
| 20 | |
| 21 | #pragma once |
| 22 | |
| 23 | #include "TestMain.h" |
| 24 | #include <wtf/text/CString.h> |
| 25 | |
| 26 | class WebViewTest: public Test { |
| 27 | public: |
| 28 | MAKE_GLIB_TEST_FIXTURE(WebViewTest); |
| 29 | WebViewTest(); |
| 30 | virtual ~WebViewTest(); |
| 31 | |
| 32 | static bool shouldInitializeWebViewInConstructor; |
| 33 | void initializeWebView(); |
| 34 | |
| 35 | void platformInitializeWebView(); |
| 36 | void platformDestroy(); |
| 37 | |
| 38 | virtual void loadURI(const char* uri); |
| 39 | virtual void loadHtml(const char* html, const char* baseURI); |
| 40 | virtual void loadPlainText(const char* plainText); |
| 41 | virtual void loadRequest(WebKitURIRequest*); |
| 42 | virtual void loadBytes(GBytes*, const char* mimeType, const char* encoding, const char* baseURI); |
| 43 | void loadAlternateHTML(const char* html, const char* contentURI, const char* baseURI); |
| 44 | void goBack(); |
| 45 | void goForward(); |
| 46 | void goToBackForwardListItem(WebKitBackForwardListItem*); |
| 47 | |
| 48 | void quitMainLoop(); |
| 49 | void quitMainLoopAfterProcessingPendingEvents(); |
| 50 | void wait(double seconds); |
| 51 | void waitUntilLoadFinished(); |
| 52 | void waitUntilTitleChangedTo(const char* expectedTitle); |
| 53 | void waitUntilTitleChanged(); |
| 54 | void resizeView(int width, int height); |
| 55 | void hideView(); |
| 56 | void selectAll(); |
| 57 | const char* mainResourceData(size_t& mainResourceDataSize); |
| 58 | |
| 59 | bool isEditable(); |
| 60 | void setEditable(bool); |
| 61 | |
| 62 | void mouseMoveTo(int x, int y, unsigned mouseModifiers = 0); |
| 63 | void clickMouseButton(int x, int y, unsigned button = 1, unsigned mouseModifiers = 0); |
| 64 | void keyStroke(unsigned keyVal, unsigned keyModifiers = 0); |
| 65 | |
| 66 | #if PLATFORM(GTK) |
| 67 | void showInWindow(GtkWindowType = GTK_WINDOW_POPUP); |
| 68 | void showInWindowAndWaitUntilMapped(GtkWindowType = GTK_WINDOW_POPUP, int width = 0, int height = 0); |
| 69 | void (); |
| 70 | #endif |
| 71 | |
| 72 | #if PLATFORM(WPE) |
| 73 | void showInWindow(); |
| 74 | #endif |
| 75 | |
| 76 | WebKitJavascriptResult* runJavaScriptAndWaitUntilFinished(const char* javascript, GError**); |
| 77 | WebKitJavascriptResult* runJavaScriptFromGResourceAndWaitUntilFinished(const char* resource, GError**); |
| 78 | WebKitJavascriptResult* runJavaScriptInWorldAndWaitUntilFinished(const char* javascript, const char* world, GError**); |
| 79 | |
| 80 | // Javascript result helpers. |
| 81 | static char* javascriptResultToCString(WebKitJavascriptResult*); |
| 82 | static double javascriptResultToNumber(WebKitJavascriptResult*); |
| 83 | static bool javascriptResultToBoolean(WebKitJavascriptResult*); |
| 84 | static bool javascriptResultIsNull(WebKitJavascriptResult*); |
| 85 | static bool javascriptResultIsUndefined(WebKitJavascriptResult*); |
| 86 | |
| 87 | #if PLATFORM(GTK) |
| 88 | cairo_surface_t* getSnapshotAndWaitUntilReady(WebKitSnapshotRegion, WebKitSnapshotOptions); |
| 89 | #endif |
| 90 | |
| 91 | bool runWebProcessTest(const char* suiteName, const char* testName, const char* contents = nullptr, const char* contentType = nullptr); |
| 92 | |
| 93 | // Prohibit overrides because this is called when the web view is created |
| 94 | // in our constructor, before a derived class's vtable is ready. |
| 95 | void initializeWebExtensions() final { Test::initializeWebExtensions(); } |
| 96 | |
| 97 | static gboolean webProcessTerminated(WebKitWebView*, WebKitWebProcessTerminationReason, WebViewTest*); |
| 98 | |
| 99 | GRefPtr<WebKitUserContentManager> m_userContentManager; |
| 100 | WebKitWebView* m_webView { nullptr }; |
| 101 | GMainLoop* m_mainLoop; |
| 102 | CString m_activeURI; |
| 103 | CString m_expectedTitle; |
| 104 | WebKitJavascriptResult* m_javascriptResult { nullptr }; |
| 105 | GError** m_javascriptError { nullptr }; |
| 106 | GUniquePtr<char> m_resourceData { nullptr }; |
| 107 | size_t m_resourceDataSize { 0 }; |
| 108 | cairo_surface_t* m_surface { nullptr }; |
| 109 | bool m_expectedWebProcessCrash { false }; |
| 110 | |
| 111 | #if PLATFORM(GTK) |
| 112 | GtkWidget* m_parentWindow { nullptr }; |
| 113 | #endif |
| 114 | |
| 115 | private: |
| 116 | #if PLATFORM(GTK) |
| 117 | void doMouseButtonEvent(GdkEventType, int, int, unsigned, unsigned); |
| 118 | #endif |
| 119 | }; |
| 120 | |