[WPE] Add env var WPE_USE_HEADLESS_VIEW_BACKEND
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Nov 2017 09:47:56 +0000 (09:47 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Nov 2017 09:47:56 +0000 (09:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=173770

Reviewed by Michael Catanzaro.

Move HeadlessViewBackend implementation to a common place and build it as a private static library to be used by
WTR, GLib API tests and eventually C API tests too. WTR uses the HeadlessViewBackend unconditionally, but GLib
API tests use it only when WPE_USE_HEADLESS_VIEW_BACKEND environment variable is present and not "0".

* CMakeLists.txt: Include wpe/HeadlessViewBackend directory for developer builds.
* TestWebKitAPI/Tests/WebKitGLib/TestAutomationSession.cpp:
(testAutomationSessionRequestSession):
* TestWebKitAPI/Tests/WebKitGLib/TestCookieManager.cpp:
(testCookieManagerEphemeral):
* TestWebKitAPI/Tests/WebKitGLib/TestWebKitFaviconDatabase.cpp:
(testPrivateBrowsing):
* TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebContext.cpp:
(testWebContextProxySettings):
* TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp:
(testWebViewWebContext):
(testWebViewEphemeral):
* TestWebKitAPI/glib/PlatformWPE.cmake:
* TestWebKitAPI/glib/WebKitGLib/TestMain.h:
(Test::createWebViewBackend):
(Test::createWebView):
* TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp:
(WebViewTest::initializeWebView):
* WebKitTestRunner/PlatformWPE.cmake:
* wpe/HeadlessViewBackend/CMakeLists.txt: Added.
* wpe/HeadlessViewBackend/HeadlessViewBackend.cpp: Renamed from Tools/WebKitTestRunner/wpe/HeadlessViewBackend.cpp.
(HeadlessViewBackend::HeadlessViewBackend):
* wpe/HeadlessViewBackend/HeadlessViewBackend.h: Renamed from Tools/WebKitTestRunner/wpe/HeadlessViewBackend.h.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225045 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
Tools/CMakeLists.txt
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitGLib/TestAutomationSession.cpp
Tools/TestWebKitAPI/Tests/WebKitGLib/TestCookieManager.cpp
Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitFaviconDatabase.cpp
Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebContext.cpp
Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp
Tools/TestWebKitAPI/glib/PlatformWPE.cmake
Tools/TestWebKitAPI/glib/WebKitGLib/TestMain.h
Tools/TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp
Tools/WebKitTestRunner/PlatformWPE.cmake
Tools/wpe/HeadlessViewBackend/CMakeLists.txt [new file with mode: 0644]
Tools/wpe/HeadlessViewBackend/HeadlessViewBackend.cpp [moved from Tools/WebKitTestRunner/wpe/HeadlessViewBackend.cpp with 98% similarity]
Tools/wpe/HeadlessViewBackend/HeadlessViewBackend.h [moved from Tools/WebKitTestRunner/wpe/HeadlessViewBackend.h with 100% similarity]

index 6a8277f..d2bd952 100644 (file)
@@ -27,6 +27,7 @@ elseif ("${PORT}" STREQUAL "WPE")
     if (DEVELOPER_MODE)
         add_subdirectory(ImageDiff)
         add_subdirectory(WebKitTestRunner)
+        add_subdirectory(wpe/HeadlessViewBackend)
         if (ENABLE_API_TESTS)
             add_subdirectory(TestWebKitAPI/glib)
         endif ()
index 9622e3b..7784e79 100644 (file)
@@ -1,5 +1,40 @@
 2017-11-20  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [WPE] Add env var WPE_USE_HEADLESS_VIEW_BACKEND
+        https://bugs.webkit.org/show_bug.cgi?id=173770
+
+        Reviewed by Michael Catanzaro.
+
+        Move HeadlessViewBackend implementation to a common place and build it as a private static library to be used by
+        WTR, GLib API tests and eventually C API tests too. WTR uses the HeadlessViewBackend unconditionally, but GLib
+        API tests use it only when WPE_USE_HEADLESS_VIEW_BACKEND environment variable is present and not "0".
+
+        * CMakeLists.txt: Include wpe/HeadlessViewBackend directory for developer builds.
+        * TestWebKitAPI/Tests/WebKitGLib/TestAutomationSession.cpp:
+        (testAutomationSessionRequestSession):
+        * TestWebKitAPI/Tests/WebKitGLib/TestCookieManager.cpp:
+        (testCookieManagerEphemeral):
+        * TestWebKitAPI/Tests/WebKitGLib/TestWebKitFaviconDatabase.cpp:
+        (testPrivateBrowsing):
+        * TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebContext.cpp:
+        (testWebContextProxySettings):
+        * TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp:
+        (testWebViewWebContext):
+        (testWebViewEphemeral):
+        * TestWebKitAPI/glib/PlatformWPE.cmake:
+        * TestWebKitAPI/glib/WebKitGLib/TestMain.h:
+        (Test::createWebViewBackend):
+        (Test::createWebView):
+        * TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp:
+        (WebViewTest::initializeWebView):
+        * WebKitTestRunner/PlatformWPE.cmake:
+        * wpe/HeadlessViewBackend/CMakeLists.txt: Added.
+        * wpe/HeadlessViewBackend/HeadlessViewBackend.cpp: Renamed from Tools/WebKitTestRunner/wpe/HeadlessViewBackend.cpp.
+        (HeadlessViewBackend::HeadlessViewBackend):
+        * wpe/HeadlessViewBackend/HeadlessViewBackend.h: Renamed from Tools/WebKitTestRunner/wpe/HeadlessViewBackend.h.
+
+2017-11-20  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         [WPE] webkit_web_view_new() should enable specifying wpe_view_backend object
         https://bugs.webkit.org/show_bug.cgi?id=178655
 
index 427304f..26c374e 100644 (file)
@@ -313,7 +313,13 @@ static void testAutomationSessionRequestSession(AutomationTest* test, gconstpoin
     g_assert(!test->createTopLevelBrowsingContext(webView.get()));
 
     // And will work with a proper web view.
-    webView = Test::adoptView(g_object_new(WEBKIT_TYPE_WEB_VIEW, "web-context", test->m_webContext.get(), "is-controlled-by-automation", TRUE, nullptr));
+    webView = Test::adoptView(g_object_new(WEBKIT_TYPE_WEB_VIEW,
+#if PLATFORM(WPE)
+        "backend", Test::createWebViewBackend(),
+#endif
+        "web-context", test->m_webContext.get(),
+        "is-controlled-by-automation", TRUE,
+        nullptr));
     g_assert(webkit_web_view_is_controlled_by_automation(webView.get()));
     g_assert(test->createTopLevelBrowsingContext(webView.get()));
 
index 911a624..1d7fa73 100644 (file)
@@ -340,6 +340,9 @@ static void testCookieManagerEphemeral(CookieManagerTest* test, gconstpointer)
     g_assert_cmpint(g_strv_length(domains), ==, 0);
 
     auto webView = Test::adoptView(g_object_new(WEBKIT_TYPE_WEB_VIEW,
+#if PLATFORM(WPE)
+        "backend", Test::createWebViewBackend(),
+#endif
         "web-context", webkit_web_view_get_context(test->m_webView),
         "is-ephemeral", TRUE,
         nullptr));
index 8f4148c..c10ff6d 100644 (file)
@@ -184,6 +184,9 @@ static void ephemeralViewLoadChanged(WebKitWebView* webView, WebKitLoadEvent loa
 static void testPrivateBrowsing(FaviconDatabaseTest* test)
 {
     auto webView = Test::adoptView(g_object_new(WEBKIT_TYPE_WEB_VIEW,
+#if PLATFORM(WPE)
+        "backend", Test::createWebViewBackend(),
+#endif
         "web-context", test->m_webContext.get(),
         "is-ephemeral", TRUE,
         nullptr));
index 006fc26..79b7d6c 100644 (file)
@@ -708,6 +708,9 @@ static void testWebContextProxySettings(ProxyTest* test, gconstpointer)
 
     // Proxy settings also affect ephemeral web views.
     auto webView = Test::adoptView(g_object_new(WEBKIT_TYPE_WEB_VIEW,
+#if PLATFORM(WPE)
+        "backend", Test::createWebViewBackend(),
+#endif
         "web-context", test->m_webContext.get(),
         "is-ephemeral", TRUE,
         nullptr));
index 9402f01..f5efd74 100644 (file)
@@ -51,7 +51,11 @@ static void testWebViewWebContext(WebViewTest* test, gconstpointer)
     g_assert(webkit_web_context_get_default() != test->m_webContext.get());
 
     // Check that a web view created with g_object_new has the default context.
-    auto webView = Test::adoptView(g_object_new(WEBKIT_TYPE_WEB_VIEW, nullptr));
+    auto webView = Test::adoptView(g_object_new(WEBKIT_TYPE_WEB_VIEW,
+#if PLATFORM(WPE)
+        "backend", Test::createWebViewBackend(),
+#endif
+        nullptr));
     g_assert(webkit_web_view_get_context(webView.get()) == webkit_web_context_get_default());
 
     // Check that a web view created with a related view has the related view context.
@@ -60,7 +64,12 @@ static void testWebViewWebContext(WebViewTest* test, gconstpointer)
 
     // Check that a web context given as construct parameter is ignored if a related view is also provided.
     webView = Test::adoptView(g_object_new(WEBKIT_TYPE_WEB_VIEW,
-        "web-context", webkit_web_context_get_default(), "related-view", test->m_webView, nullptr));
+#if PLATFORM(WPE)
+        "backend", Test::createWebViewBackend(),
+#endif
+        "web-context", webkit_web_context_get_default(),
+        "related-view", test->m_webView,
+        nullptr));
     g_assert(webkit_web_view_get_context(webView.get()) == test->m_webContext.get());
 }
 
@@ -182,6 +191,9 @@ static void testWebViewEphemeral(WebViewTest* test, gconstpointer)
 
     // A WebView on a non ephemeral context can be ephemeral.
     auto webView = Test::adoptView(g_object_new(WEBKIT_TYPE_WEB_VIEW,
+#if PLATFORM(WPE)
+        "backend", Test::createWebViewBackend(),
+#endif
         "web-context", webkit_web_view_get_context(test->m_webView),
         "is-ephemeral", TRUE,
         nullptr));
index 7f0db5a..b5d5bd3 100644 (file)
@@ -9,6 +9,7 @@ list(APPEND WebKitGLibAPITests_INCLUDE_DIRECTORIES
     ${DERIVED_SOURCES_WPE_API_DIR}
     ${FORWARDING_HEADERS_WPE_DIR}
     ${FORWARDING_HEADERS_WPE_EXTENSION_DIR}
+    ${TOOLS_DIR}/wpe/HeadlessViewBackend
 )
 
 list(APPEND WebKitGLibAPITests_SYSTEM_INCLUDE_DIRECTORIES
@@ -17,4 +18,5 @@ list(APPEND WebKitGLibAPITests_SYSTEM_INCLUDE_DIRECTORIES
 
 list(APPEND WebKitGLibAPITest_LIBRARIES
     ${WPE_LIBRARIES}
+    WPEHeadlessViewBackend
 )
index 8950f10..7db142c 100644 (file)
@@ -29,6 +29,7 @@
 #if PLATFORM(GTK)
 #include <webkit2/webkit2.h>
 #elif PLATFORM(WPE)
+#include "HeadlessViewBackend.h"
 #include <wpe/webkit.h>
 #endif
 
@@ -143,12 +144,25 @@ public:
         webkit_web_context_set_web_extensions_initialization_user_data(m_webContext.get(), g_variant_new_uint32(++s_webExtensionID));
     }
 
+#if PLATFORM(WPE)
+    static WebKitWebViewBackend* createWebViewBackend()
+    {
+        const char* useHeadlessViewBackend = g_getenv("WPE_USE_HEADLESS_VIEW_BACKEND");
+        if (!useHeadlessViewBackend || !strcmp(useHeadlessViewBackend, "0"))
+            return nullptr;
+        auto* headlessBackend = new HeadlessViewBackend;
+        return webkit_web_view_backend_new(headlessBackend->backend(), [](gpointer userData) {
+            delete static_cast<HeadlessViewBackend*>(userData);
+        }, headlessBackend);
+    }
+#endif
+
     static WebKitWebView* createWebView()
     {
 #if PLATFORM(GTK)
         return WEBKIT_WEB_VIEW(webkit_web_view_new());
 #elif PLATFORM(WPE)
-        return webkit_web_view_new(nullptr);
+        return webkit_web_view_new(createWebViewBackend());
 #endif
     }
 
@@ -157,7 +171,7 @@ public:
 #if PLATFORM(GTK)
         return WEBKIT_WEB_VIEW(webkit_web_view_new_with_context(context));
 #elif PLATFORM(WPE)
-        return webkit_web_view_new_with_context(nullptr, context);
+        return webkit_web_view_new_with_context(createWebViewBackend(), context);
 #endif
     }
 
@@ -166,7 +180,7 @@ public:
 #if PLATFORM(GTK)
         return WEBKIT_WEB_VIEW(webkit_web_view_new_with_related_view(relatedView));
 #elif PLATFORM(WPE)
-        return webkit_web_view_new_with_related_view(nullptr, relatedView);
+        return webkit_web_view_new_with_related_view(createWebViewBackend(), relatedView);
 #endif
     }
 
@@ -175,7 +189,7 @@ public:
 #if PLATFORM(GTK)
         return WEBKIT_WEB_VIEW(webkit_web_view_new_with_user_content_manager(contentManager));
 #elif PLATFORM(WPE)
-        return webkit_web_view_new_with_user_content_manager(nullptr, contentManager);
+        return webkit_web_view_new_with_user_content_manager(createWebViewBackend(), contentManager);
 #endif
     }
 
@@ -184,7 +198,7 @@ public:
 #if PLATFORM(GTK)
         return WEBKIT_WEB_VIEW(webkit_web_view_new_with_settings(settings));
 #elif PLATFORM(WPE)
-        return webkit_web_view_new_with_settings(nullptr, settings);
+        return webkit_web_view_new_with_settings(createWebViewBackend(), settings);
 #endif
     }
 
index 56704b3..de29640 100644 (file)
@@ -48,7 +48,13 @@ WebViewTest::~WebViewTest()
 void WebViewTest::initializeWebView()
 {
     g_assert(!m_webView);
-    m_webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW, "web-context", m_webContext.get(), "user-content-manager", m_userContentManager.get(), nullptr));
+    m_webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW,
+#if PLATFORM(WPE)
+        "backend", Test::createWebViewBackend(),
+#endif
+        "web-context", m_webContext.get(),
+        "user-content-manager", m_userContentManager.get(),
+        nullptr));
     platformInitializeWebView();
     assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_webView));
 
index 64a3d17..8d2805c 100644 (file)
@@ -1,5 +1,3 @@
-find_package(LibGBM REQUIRED)
-find_package(WPEBackend-mesa REQUIRED)
 find_package(Libxkbcommon 0.4.0 REQUIRED)
 
 add_custom_target(WebKitTestRunner-forwarding-headers
@@ -12,7 +10,6 @@ list(APPEND WebKitTestRunner_SOURCES
     ${WEBKIT_TESTRUNNER_DIR}/cairo/TestInvocationCairo.cpp
 
     ${WEBKIT_TESTRUNNER_DIR}/wpe/EventSenderProxyWPE.cpp
-    ${WEBKIT_TESTRUNNER_DIR}/wpe/HeadlessViewBackend.cpp
     ${WEBKIT_TESTRUNNER_DIR}/wpe/PlatformWebViewWPE.cpp
     ${WEBKIT_TESTRUNNER_DIR}/wpe/TestControllerWPE.cpp
     ${WEBKIT_TESTRUNNER_DIR}/wpe/main.cpp
@@ -21,22 +18,20 @@ list(APPEND WebKitTestRunner_SOURCES
 list(APPEND WebKitTestRunner_INCLUDE_DIRECTORIES
     ${WEBKIT_TESTRUNNER_DIR}/InjectedBundle/wpe
     ${FORWARDING_HEADERS_DIR}
+    ${TOOLS_DIR}/wpe/HeadlessViewBackend
 )
 
 list(APPEND WebKitTestRunner_SYSTEM_INCLUDE_DIRECTORIES
     ${CAIRO_INCLUDE_DIRS}
     ${GLIB_INCLUDE_DIRS}
-    ${LIBGBM_INCLUDE_DIRS}
     ${LIBXKBCOMMON_INCLUDE_DIRS}
-    ${WPE_MESA_INCLUDE_DIRS}
 )
 
 list(APPEND WebKitTestRunner_LIBRARIES
     ${CAIRO_LIBRARIES}
     ${GLIB_LIBRARIES}
-    ${LIBGBM_LIBRARIES}
     ${LIBXKBCOMMON_LIBRARIES}
-    ${WPE_MESA_LIBRARIES}
+    WPEHeadlessViewBackend
 )
 
 list(APPEND WebKitTestRunnerInjectedBundle_SOURCES
diff --git a/Tools/wpe/HeadlessViewBackend/CMakeLists.txt b/Tools/wpe/HeadlessViewBackend/CMakeLists.txt
new file mode 100644 (file)
index 0000000..724c6d9
--- /dev/null
@@ -0,0 +1,24 @@
+find_package(LibGBM REQUIRED)
+find_package(WPEBackend-mesa REQUIRED)
+
+set(WPEHeadlessViewBackend_SOURCES
+    ${TOOLS_DIR}/wpe/HeadlessViewBackend/HeadlessViewBackend.cpp
+)
+
+set(WPEHeadlessViewBackend_SYSTEM_INCLUDE_DIRECTORIES
+    ${CAIRO_INCLUDE_DIRS}
+    ${GLIB_INCLUDE_DIRS}
+    ${LIBGBM_INCLUDE_DIRS}
+    ${WPE_MESA_INCLUDE_DIRS}
+)
+
+set(WPEHeadlessViewBackend_LIBRARIES
+    ${CAIRO_LIBRARIES}
+    ${GLIB_LIBRARIES}
+    ${LIBGBM_LIBRARIES}
+    ${WPE_MESA_LIBRARIES}
+)
+
+add_library(WPEHeadlessViewBackend ${WPEHeadlessViewBackend_SOURCES})
+include_directories(SYSTEM ${WPEHeadlessViewBackend_SYSTEM_INCLUDE_DIRECTORIES})
+target_link_libraries(WPEHeadlessViewBackend ${WPEHeadlessViewBackend_LIBRARIES})
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "config.h"
 #include "HeadlessViewBackend.h"
 
 #include <cassert>
 #include <fcntl.h>
 #include <unistd.h>
-#include <wtf/glib/RunLoopSourcePriority.h>
 
 // Manually provide the EGL_CAST C++ definition in case eglplatform.h doesn't provide it.
 #ifndef EGL_CAST
 #define EGL_CAST(type, value) (static_cast<type>(value))
 #endif
 
+// Keep this in sync with wtf/glib/RunLoopSourcePriority.h.
+static int kRunLoopSourcePriorityDispatcher = -70;
+
 // FIXME: Deploy good practices and clean up GBM resources at process exit.
 static EGLDisplay getEGLDisplay()
 {
@@ -109,7 +110,7 @@ HeadlessViewBackend::HeadlessViewBackend()
             backend.performUpdate();
             return TRUE;
         }, this, nullptr);
-    g_source_set_priority(m_updateSource, RunLoopSourcePriority::RunLoopDispatcher);
+    g_source_set_priority(m_updateSource, kRunLoopSourcePriorityDispatcher);
     g_source_attach(m_updateSource, g_main_context_default());
 }