2017-07-18 07:20:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Igalia S.L.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Capabilities.h"
|
|
|
|
#include <wtf/HashMap.h>
|
2017-11-28 19:58:16 +00:00
|
|
|
#include <wtf/JSONValues.h>
|
2017-07-18 07:20:33 +00:00
|
|
|
|
|
|
|
#if USE(GLIB)
|
|
|
|
#include <wtf/glib/GRefPtr.h>
|
2019-11-22 14:22:34 +00:00
|
|
|
#include <wtf/glib/SocketConnection.h>
|
2017-07-18 07:20:33 +00:00
|
|
|
typedef struct _GSubprocess GSubprocess;
|
2020-09-30 21:22:57 +00:00
|
|
|
#elif USE(INSPECTOR_SOCKET_SERVER)
|
|
|
|
#include <JavaScriptCore/RemoteInspectorConnectionClient.h>
|
|
|
|
#include <wtf/RefCounted.h>
|
|
|
|
#include <wtf/RefPtr.h>
|
2017-07-18 07:20:33 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace WebDriver {
|
|
|
|
|
|
|
|
struct ConnectToBrowserAsyncData;
|
|
|
|
|
2020-09-30 21:22:57 +00:00
|
|
|
class SessionHost
|
|
|
|
#if USE(INSPECTOR_SOCKET_SERVER)
|
|
|
|
: public Inspector::RemoteInspectorConnectionClient
|
|
|
|
#endif
|
|
|
|
{
|
2017-07-18 07:20:33 +00:00
|
|
|
WTF_MAKE_FAST_ALLOCATED(SessionHost);
|
|
|
|
public:
|
|
|
|
explicit SessionHost(Capabilities&& capabilities)
|
|
|
|
: m_capabilities(WTFMove(capabilities))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
~SessionHost();
|
|
|
|
|
2020-09-30 21:22:57 +00:00
|
|
|
#if USE(INSPECTOR_SOCKET_SERVER)
|
|
|
|
void setHostAddress(const String& ip, uint16_t port) { m_targetIp = ip; m_targetPort = port; }
|
|
|
|
#endif
|
2017-08-16 11:38:22 +00:00
|
|
|
bool isConnected() const;
|
|
|
|
|
WebDriver: test imported/w3c/webdriver/tests/sessions/new_session/merge.py::test_merge_browserName fails
https://bugs.webkit.org/show_bug.cgi?id=181985
Reviewed by Carlos Alberto Lopez Perez.
Source/WebDriver:
The problem is that we are considering a failure when the browser name doesn't match the capabilities, instead
of trying with the next merged capabilities. This is happening because when processing capabilities, we only
match the ones that we know without having to launch the browser. Browser name and version are provided by the
browser during the session initialization. This patch reworks the session creation to make it possible to try
with the next merged capabilities when matching fails after the browser is launched.
* Session.cpp:
(WebDriver::Session::Session): Initialize timeouts from capabilities, because now we have the final capabilities here.
(WebDriver::Session::id const): Return the session ID from the SessionHost, since it's now created there.
(WebDriver::Session::createTopLevelBrowsingContext): Do not start the session, it has already been started a
this point.
(WebDriver::Session::createElement): Use id() instead of m_id.
* Session.h:
* SessionHost.h:
(WebDriver::SessionHost::sessionID const): Return the session ID.
* WebDriverService.cpp:
(WebDriver::WebDriverService::matchCapabilities const): Remove the error handling, and return a boolean instead,
since not mathing is not an error.
(WebDriver::WebDriverService::processCapabilities const): Return a list of matched capabilities, instead of the
JSON object corresponding to the first match.
(WebDriver::WebDriverService::newSession): Use helper connectToBrowser().
(WebDriver::WebDriverService::connectToBrowser): Create a session host for the next merged capabilities and
connect to the browser.
(WebDriver::WebDriverService::createSession): Start a new automation session. If capabilities didn't match,
start the process again calling connectToBrowser(), otherwise create the new session and top level.
* WebDriverService.h:
* glib/SessionHostGlib.cpp:
(WebDriver::matchBrowserOptions): Helper to check browser options.
(WebDriver::SessionHost::matchCapabilities): Use matchBrowserOptions() and return true or false instead of an
optional error message.
(WebDriver::SessionHost::startAutomationSession): Create the session ID here and notify the caller in case
capabilities didn't match.
(WebDriver::SessionHost::setTargetList): Notify that capabilities did match.
* gtk/WebDriverServiceGtk.cpp:
(WebDriver::WebDriverService::platformMatchCapability const): Make it return bool.
* wpe/WebDriverServiceWPE.cpp:
(WebDriver::WebDriverService::platformMatchCapability const): Ditto.
WebDriverTests:
Remove expectations for imported/w3c/webdriver/tests/sessions/new_session/merge.py::test_merge_browserName.
* TestExpectations.json:
Canonical link: https://commits.webkit.org/197938@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227603 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-01-25 13:52:40 +00:00
|
|
|
const String& sessionID() const { return m_sessionID; }
|
2017-07-18 07:20:33 +00:00
|
|
|
const Capabilities& capabilities() const { return m_capabilities; }
|
|
|
|
|
2021-05-30 16:11:40 +00:00
|
|
|
void connectToBrowser(Function<void (std::optional<String> error)>&&);
|
|
|
|
void startAutomationSession(Function<void (bool, std::optional<String>)>&&);
|
2017-07-18 07:20:33 +00:00
|
|
|
|
|
|
|
struct CommandResponse {
|
2017-11-28 19:58:16 +00:00
|
|
|
RefPtr<JSON::Object> responseObject;
|
2017-07-18 07:20:33 +00:00
|
|
|
bool isError { false };
|
|
|
|
};
|
2017-11-28 19:58:16 +00:00
|
|
|
long sendCommandToBackend(const String&, RefPtr<JSON::Object>&& parameters, Function<void (CommandResponse&&)>&&);
|
2017-07-18 07:20:33 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct Target {
|
|
|
|
uint64_t id { 0 };
|
|
|
|
CString name;
|
|
|
|
bool paired { false };
|
|
|
|
};
|
|
|
|
|
|
|
|
void inspectorDisconnected();
|
2019-11-22 14:22:34 +00:00
|
|
|
void sendMessageToBackend(const String&);
|
2017-07-18 07:20:33 +00:00
|
|
|
void dispatchMessage(const String&);
|
|
|
|
|
|
|
|
#if USE(GLIB)
|
2019-12-13 16:23:29 +00:00
|
|
|
static const SocketConnection::MessageHandlers& messageHandlers();
|
2019-11-22 14:22:34 +00:00
|
|
|
void connectionDidClose();
|
2021-05-30 16:11:40 +00:00
|
|
|
void launchBrowser(Function<void (std::optional<String> error)>&&);
|
2017-07-18 07:20:33 +00:00
|
|
|
void connectToBrowser(std::unique_ptr<ConnectToBrowserAsyncData>&&);
|
WebDriver: test imported/w3c/webdriver/tests/sessions/new_session/merge.py::test_merge_browserName fails
https://bugs.webkit.org/show_bug.cgi?id=181985
Reviewed by Carlos Alberto Lopez Perez.
Source/WebDriver:
The problem is that we are considering a failure when the browser name doesn't match the capabilities, instead
of trying with the next merged capabilities. This is happening because when processing capabilities, we only
match the ones that we know without having to launch the browser. Browser name and version are provided by the
browser during the session initialization. This patch reworks the session creation to make it possible to try
with the next merged capabilities when matching fails after the browser is launched.
* Session.cpp:
(WebDriver::Session::Session): Initialize timeouts from capabilities, because now we have the final capabilities here.
(WebDriver::Session::id const): Return the session ID from the SessionHost, since it's now created there.
(WebDriver::Session::createTopLevelBrowsingContext): Do not start the session, it has already been started a
this point.
(WebDriver::Session::createElement): Use id() instead of m_id.
* Session.h:
* SessionHost.h:
(WebDriver::SessionHost::sessionID const): Return the session ID.
* WebDriverService.cpp:
(WebDriver::WebDriverService::matchCapabilities const): Remove the error handling, and return a boolean instead,
since not mathing is not an error.
(WebDriver::WebDriverService::processCapabilities const): Return a list of matched capabilities, instead of the
JSON object corresponding to the first match.
(WebDriver::WebDriverService::newSession): Use helper connectToBrowser().
(WebDriver::WebDriverService::connectToBrowser): Create a session host for the next merged capabilities and
connect to the browser.
(WebDriver::WebDriverService::createSession): Start a new automation session. If capabilities didn't match,
start the process again calling connectToBrowser(), otherwise create the new session and top level.
* WebDriverService.h:
* glib/SessionHostGlib.cpp:
(WebDriver::matchBrowserOptions): Helper to check browser options.
(WebDriver::SessionHost::matchCapabilities): Use matchBrowserOptions() and return true or false instead of an
optional error message.
(WebDriver::SessionHost::startAutomationSession): Create the session ID here and notify the caller in case
capabilities didn't match.
(WebDriver::SessionHost::setTargetList): Notify that capabilities did match.
* gtk/WebDriverServiceGtk.cpp:
(WebDriver::WebDriverService::platformMatchCapability const): Make it return bool.
* wpe/WebDriverServiceWPE.cpp:
(WebDriver::WebDriverService::platformMatchCapability const): Ditto.
WebDriverTests:
Remove expectations for imported/w3c/webdriver/tests/sessions/new_session/merge.py::test_merge_browserName.
* TestExpectations.json:
Canonical link: https://commits.webkit.org/197938@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227603 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-01-25 13:52:40 +00:00
|
|
|
bool matchCapabilities(GVariant*);
|
2018-06-25 06:31:15 +00:00
|
|
|
bool buildSessionCapabilities(GVariantBuilder*) const;
|
2019-11-22 14:22:34 +00:00
|
|
|
void setupConnection(Ref<SocketConnection>&&);
|
|
|
|
void didStartAutomationSession(GVariant*);
|
2017-07-18 07:20:33 +00:00
|
|
|
void setTargetList(uint64_t connectionID, Vector<Target>&&);
|
|
|
|
void sendMessageToFrontend(uint64_t connectionID, uint64_t targetID, const char* message);
|
2020-09-30 21:22:57 +00:00
|
|
|
#elif USE(INSPECTOR_SOCKET_SERVER)
|
|
|
|
HashMap<String, CallHandler>& dispatchMap() override;
|
|
|
|
void didClose(Inspector::RemoteInspectorSocketEndpoint&, Inspector::ConnectionID) final;
|
|
|
|
void sendWebInspectorEvent(const String&);
|
|
|
|
|
|
|
|
void receivedSetTargetList(const struct Event&);
|
|
|
|
void receivedSendMessageToFrontend(const struct Event&);
|
|
|
|
void receivedStartAutomationSessionReturn(const struct Event&);
|
|
|
|
|
2021-05-30 16:11:40 +00:00
|
|
|
std::optional<Vector<Target>> parseTargetList(const struct Event&);
|
2020-09-30 21:22:57 +00:00
|
|
|
void setTargetList(uint64_t connectionID, Vector<Target>&&);
|
2017-07-18 07:20:33 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
Capabilities m_capabilities;
|
|
|
|
|
WebDriver: test imported/w3c/webdriver/tests/sessions/new_session/merge.py::test_merge_browserName fails
https://bugs.webkit.org/show_bug.cgi?id=181985
Reviewed by Carlos Alberto Lopez Perez.
Source/WebDriver:
The problem is that we are considering a failure when the browser name doesn't match the capabilities, instead
of trying with the next merged capabilities. This is happening because when processing capabilities, we only
match the ones that we know without having to launch the browser. Browser name and version are provided by the
browser during the session initialization. This patch reworks the session creation to make it possible to try
with the next merged capabilities when matching fails after the browser is launched.
* Session.cpp:
(WebDriver::Session::Session): Initialize timeouts from capabilities, because now we have the final capabilities here.
(WebDriver::Session::id const): Return the session ID from the SessionHost, since it's now created there.
(WebDriver::Session::createTopLevelBrowsingContext): Do not start the session, it has already been started a
this point.
(WebDriver::Session::createElement): Use id() instead of m_id.
* Session.h:
* SessionHost.h:
(WebDriver::SessionHost::sessionID const): Return the session ID.
* WebDriverService.cpp:
(WebDriver::WebDriverService::matchCapabilities const): Remove the error handling, and return a boolean instead,
since not mathing is not an error.
(WebDriver::WebDriverService::processCapabilities const): Return a list of matched capabilities, instead of the
JSON object corresponding to the first match.
(WebDriver::WebDriverService::newSession): Use helper connectToBrowser().
(WebDriver::WebDriverService::connectToBrowser): Create a session host for the next merged capabilities and
connect to the browser.
(WebDriver::WebDriverService::createSession): Start a new automation session. If capabilities didn't match,
start the process again calling connectToBrowser(), otherwise create the new session and top level.
* WebDriverService.h:
* glib/SessionHostGlib.cpp:
(WebDriver::matchBrowserOptions): Helper to check browser options.
(WebDriver::SessionHost::matchCapabilities): Use matchBrowserOptions() and return true or false instead of an
optional error message.
(WebDriver::SessionHost::startAutomationSession): Create the session ID here and notify the caller in case
capabilities didn't match.
(WebDriver::SessionHost::setTargetList): Notify that capabilities did match.
* gtk/WebDriverServiceGtk.cpp:
(WebDriver::WebDriverService::platformMatchCapability const): Make it return bool.
* wpe/WebDriverServiceWPE.cpp:
(WebDriver::WebDriverService::platformMatchCapability const): Ditto.
WebDriverTests:
Remove expectations for imported/w3c/webdriver/tests/sessions/new_session/merge.py::test_merge_browserName.
* TestExpectations.json:
Canonical link: https://commits.webkit.org/197938@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227603 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-01-25 13:52:40 +00:00
|
|
|
String m_sessionID;
|
2017-07-18 07:20:33 +00:00
|
|
|
uint64_t m_connectionID { 0 };
|
|
|
|
Target m_target;
|
|
|
|
|
|
|
|
HashMap<long, Function<void (CommandResponse&&)>> m_commandRequests;
|
|
|
|
|
|
|
|
#if USE(GLIB)
|
2021-05-30 16:11:40 +00:00
|
|
|
Function<void (bool, std::optional<String>)> m_startSessionCompletionHandler;
|
2017-07-18 07:20:33 +00:00
|
|
|
GRefPtr<GSubprocess> m_browser;
|
2019-11-22 14:22:34 +00:00
|
|
|
RefPtr<SocketConnection> m_socketConnection;
|
2017-07-18 07:20:33 +00:00
|
|
|
GRefPtr<GCancellable> m_cancellable;
|
2020-09-30 21:22:57 +00:00
|
|
|
#elif USE(INSPECTOR_SOCKET_SERVER)
|
|
|
|
String m_targetIp;
|
|
|
|
uint16_t m_targetPort { 0 };
|
2021-05-30 16:11:40 +00:00
|
|
|
Function<void(bool, std::optional<String>)> m_startSessionCompletionHandler;
|
|
|
|
std::optional<Inspector::ConnectionID> m_clientID;
|
2017-07-18 07:20:33 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace WebDriver
|