Unreviewed. Fix WebDriver tests after r233077.
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Jun 2018 06:31:15 +0000 (06:31 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Jun 2018 06:31:15 +0000 (06:31 +0000)
WebDriver process is crashing because GVariant doesn't allow to pass a nullptr array when using @ modifier.

* SessionHost.h:
* glib/SessionHostGlib.cpp:
(WebDriver::SessionHost::buildSessionCapabilities const): Receive a GVariantBuilder and return true if there are
session capabilities.
(WebDriver::SessionHost::startAutomationSession): Remove the @ modifier and use a GVariantBuilder instead, or
nullptr if there aren't session capabilities.

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

Source/WebDriver/ChangeLog
Source/WebDriver/SessionHost.h
Source/WebDriver/glib/SessionHostGlib.cpp

index ebc22f6..3e154c9 100644 (file)
@@ -1,3 +1,16 @@
+2018-06-24  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        Unreviewed. Fix WebDriver tests after r233077.
+
+        WebDriver process is crashing because GVariant doesn't allow to pass a nullptr array when using @ modifier.
+
+        * SessionHost.h:
+        * glib/SessionHostGlib.cpp:
+        (WebDriver::SessionHost::buildSessionCapabilities const): Receive a GVariantBuilder and return true if there are
+        session capabilities.
+        (WebDriver::SessionHost::startAutomationSession): Remove the @ modifier and use a GVariantBuilder instead, or
+        nullptr if there aren't session capabilities.
+
 2018-06-21  Brian Burg  <bburg@apple.com>
 
         Web Automation: key actions should support multiple pressed virtual keys
index 8c47676..97b525e 100644 (file)
@@ -80,7 +80,7 @@ private:
     void launchBrowser(Function<void (std::optional<String> error)>&&);
     void connectToBrowser(std::unique_ptr<ConnectToBrowserAsyncData>&&);
     bool matchCapabilities(GVariant*);
-    GVariant* buildSessionCapabilities() const;
+    bool buildSessionCapabilities(GVariantBuilder*) const;
     void setupConnection(GRefPtr<GDBusConnection>&&);
     void setTargetList(uint64_t connectionID, Vector<Target>&&);
     void sendMessageToFrontend(uint64_t connectionID, uint64_t targetID, const char* message);
index 91b0c53..941381f 100644 (file)
@@ -261,15 +261,14 @@ bool SessionHost::matchCapabilities(GVariant* capabilities)
     return didMatch;
 }
 
-GVariant* SessionHost::buildSessionCapabilities() const
+bool SessionHost::buildSessionCapabilities(GVariantBuilder* builder) const
 {
     if (!m_capabilities.acceptInsecureCerts && !m_capabilities.certificates)
-        return nullptr;
+        return false;
 
-    GVariantBuilder builder;
-    g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}"));
+    g_variant_builder_init(builder, G_VARIANT_TYPE("a{sv}"));
     if (m_capabilities.acceptInsecureCerts)
-        g_variant_builder_add(&builder, "{sv}", "acceptInsecureCerts", g_variant_new_boolean(m_capabilities.acceptInsecureCerts.value()));
+        g_variant_builder_add(builder, "{sv}", "acceptInsecureCerts", g_variant_new_boolean(m_capabilities.acceptInsecureCerts.value()));
 
     if (m_capabilities.certificates) {
         GVariantBuilder arrayBuilder;
@@ -278,10 +277,10 @@ GVariant* SessionHost::buildSessionCapabilities() const
             g_variant_builder_add_value(&arrayBuilder, g_variant_new("(ss)",
                 certificate.first.utf8().data(), certificate.second.utf8().data()));
         }
-        g_variant_builder_add(&builder, "{sv}", "certificates", g_variant_builder_end(&arrayBuilder));
+        g_variant_builder_add(builder, "{sv}", "certificates", g_variant_builder_end(&arrayBuilder));
     }
 
-    return g_variant_builder_end(&builder);
+    return true;
 }
 
 void SessionHost::startAutomationSession(Function<void (bool, std::optional<String>)>&& completionHandler)
@@ -290,11 +289,12 @@ void SessionHost::startAutomationSession(Function<void (bool, std::optional<Stri
     ASSERT(!m_startSessionCompletionHandler);
     m_startSessionCompletionHandler = WTFMove(completionHandler);
     m_sessionID = createCanonicalUUIDString();
+    GVariantBuilder builder;
     g_dbus_connection_call(m_dbusConnection.get(), nullptr,
         INSPECTOR_DBUS_OBJECT_PATH,
         INSPECTOR_DBUS_INTERFACE,
         "StartAutomationSession",
-        g_variant_new("(s@a{sv})", m_sessionID.utf8().data(), buildSessionCapabilities()),
+        g_variant_new("(sa{sv})", m_sessionID.utf8().data(), buildSessionCapabilities(&builder) ? &builder : nullptr),
         nullptr, G_DBUS_CALL_FLAGS_NO_AUTO_START,
         -1, m_cancellable.get(), [](GObject* source, GAsyncResult* result, gpointer userData) {
             GUniqueOutPtr<GError> error;