#include "chrome/test/chromedriver/chrome/web_view_impl.h"
#include <memory>
#include <optional>
#include <queue>
#include <string>
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "base/values.h"
#include "chrome/test/chromedriver/chrome/browser_info.h"
#include "chrome/test/chromedriver/chrome/devtools_client_impl.h"
#include "chrome/test/chromedriver/chrome/frame_tracker.h"
#include "chrome/test/chromedriver/chrome/page_load_strategy.h"
#include "chrome/test/chromedriver/chrome/status.h"
#include "chrome/test/chromedriver/chrome/stub_devtools_client.h"
#include "chrome/test/chromedriver/net/stub_sync_websocket.h"
#include "chrome/test/chromedriver/net/sync_websocket.h"
#include "chrome/test/chromedriver/net/timeout.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const char kElementKey[] = …;
const char kElementKeyW3C[] = …;
const char kShadowRootKey[] = …;
const int kNonExistingBackendNodeId = …;
Eq;
Optional;
Pointee;
std::string ElementReference(const char* frame_id,
const char* loader_id,
int backend_node_id) { … }
std::string ElementReference(const char* frame_id,
const char* loader_id,
const char* backend_node_id) { … }
template <int Code>
testing::AssertionResult StatusCodeIs(const Status& status) { … }
testing::AssertionResult StatusOk(const Status& status) { … }
base::Value::Dict CreateElementPlaceholder(
int index,
std::string element_key = kElementKeyW3C) { … }
base::Value::Dict CreateWeakNodeReference(int weak_local_object_reference) { … }
base::Value::Dict CreateNode(int backend_node_id,
int weak_local_object_reference = -1) { … }
std::string WrapToJson(base::Value value, int status = 0) { … }
base::Value::Dict GenerateResponse(int backend_node_id) { … }
base::Value::Dict GenerateResponseWithScriptArguments(
base::Value::List args,
const std::string& element_key) { … }
class FakeDevToolsClient : public StubDevToolsClient { … };
void AssertEvalFails(const base::Value::Dict& command_result) { … }
class SyncWebSocketWrapper : public SyncWebSocket { … };
template <typename TSocket>
class SocketHolder { … };
}
TEST(EvaluateScript, CommandError) { … }
TEST(EvaluateScript, MissingResult) { … }
TEST(EvaluateScript, Throws) { … }
TEST(EvaluateScript, Ok) { … }
TEST(EvaluateScriptAndGetValue, MissingType) { … }
TEST(EvaluateScriptAndGetValue, Undefined) { … }
TEST(EvaluateScriptAndGetValue, Ok) { … }
TEST(ParseCallFunctionResult, NotDict) { … }
TEST(ParseCallFunctionResult, Ok) { … }
TEST(ParseCallFunctionResult, ScriptError) { … }
namespace {
class MockSyncWebSocket : public SyncWebSocket { … };
}
TEST(CreateChild, MultiLevel) { … }
TEST(CreateChild, IsNonBlocking_NoErrors) { … }
TEST(CreateChild, Load_NoErrors) { … }
TEST(CreateChild, WaitForPendingNavigations_NoErrors) { … }
TEST(CreateChild, IsPendingNavigation_NoErrors) { … }
TEST(ManageCookies, AddCookie_SameSiteTrue) { … }
TEST(GetBackendNodeId, ElementW3C) { … }
TEST(GetBackendNodeId, ShadowRootW3C) { … }
TEST(GetBackendNodeId, NonW3C) { … }
TEST(CallUserSyncScript, ElementIdAsResultRootFrame) { … }
TEST(CallUserSyncScript, ElementIdAsResultChildFrame) { … }
TEST(CallUserSyncScript, ElementIdAsResultChildFrameErrors) { … }
TEST(GetFedCmTracker, OK) { … }
class CallUserSyncScriptArgs
: public testing::TestWithParam<std::pair<std::string, bool>> { … };
TEST_P(CallUserSyncScriptArgs, Root) { … }
TEST_P(CallUserSyncScriptArgs, GoodChild) { … }
TEST_P(CallUserSyncScriptArgs, DeepElement) { … }
TEST_P(CallUserSyncScriptArgs, FrameAndLoaderMismatch) { … }
TEST_P(CallUserSyncScriptArgs, NoSuchFrame) { … }
TEST_P(CallUserSyncScriptArgs, NoSuchLoader) { … }
TEST_P(CallUserSyncScriptArgs, NoSuchBackendNodeId) { … }
TEST_P(CallUserSyncScriptArgs, MalformedReference) { … }
TEST_P(CallUserSyncScriptArgs, NoBackendNodeId) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST(CallUserSyncScript, WeakReference) { … }
TEST(CallUserSyncScript, WeakReferenceOrderInsensitive) { … }
TEST(CallUserSyncScript, WeakReferenceNotResolved) { … }
namespace {
bool ReturnError(int code,
const std::string& message,
int cmd_id,
const base::Value::Dict& params,
base::Value::Dict& response) { … }
}
class WaitForPendingNavigations : public testing::TestWithParam<std::string> { … };
TEST_P(WaitForPendingNavigations, NavigationDetection) { … }
INSTANTIATE_TEST_SUITE_P(…);
namespace {
#if defined(MEMORY_SANITIZER)
base::TimeDelta kErrorWaitDuration = base::Seconds(100);
#elif defined(NDEBUG)
base::TimeDelta kErrorWaitDuration = base::Seconds(3);
#else
base::TimeDelta kErrorWaitDuration = …;
#endif
class BidiDevToolsClient : public StubDevToolsClient { … };
}
TEST(SendBidiCommandTest, Success) { … }
TEST(SendBidiCommandTest, MaxJsUintId) { … }
TEST(SendBidiCommandTest, NoId) { … }
class SendBidiCommandBadChannelTest
: public testing::TestWithParam<std::optional<std::string>> { … };
TEST_P(SendBidiCommandBadChannelTest, BadChannel) { … }
INSTANTIATE_TEST_SUITE_P(…);
class SendBidiCommandSpecialChannelTest
: public testing::TestWithParam<std::string> { … };
TEST_P(SendBidiCommandSpecialChannelTest, ChannelValues) { … }
INSTANTIATE_TEST_SUITE_P(…);
namespace {
class NeverReturningBidiDevToolsClient : public BidiDevToolsClient { … };
}
TEST(SendBidiCommandTest, NoResponse) { … }