#include "chrome/test/chromedriver/commands.h"
#include <stddef.h>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/location.h"
#include "base/run_loop.h"
#include "base/synchronization/lock.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "base/values.h"
#include "chrome/test/chromedriver/chrome/status.h"
#include "chrome/test/chromedriver/chrome/stub_chrome.h"
#include "chrome/test/chromedriver/chrome/stub_web_view.h"
#include "chrome/test/chromedriver/chrome/web_view.h"
#include "chrome/test/chromedriver/command_listener_proxy.h"
#include "chrome/test/chromedriver/element_commands.h"
#include "chrome/test/chromedriver/session.h"
#include "chrome/test/chromedriver/session_commands.h"
#include "chrome/test/chromedriver/window_commands.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/selenium-atoms/atoms.h"
ContainsRegex;
Eq;
HasSubstr;
Optional;
Pointee;
namespace {
template <int Code>
testing::AssertionResult StatusCodeIs(const Status& status) { … }
testing::AssertionResult StatusOk(const Status& status) { … }
void AssertGetStatusExtendedData(base::Value::Dict* dict) { … }
void OnGetStatus(const Status& status,
std::unique_ptr<base::Value> value,
const std::string& session_id,
bool w3c_compliant) { … }
}
TEST(CommandsTest, GetStatus) { … }
namespace {
void OnBidiSessionStatusNoSession(const Status& status,
std::unique_ptr<base::Value> value,
const std::string& session_id,
bool w3c_compliant) { … }
}
TEST(CommandsTest, BidiSessionStatusNoSession) { … }
namespace {
void OnBidiSessionStatusWithSession(const Status& status,
std::unique_ptr<base::Value> value,
const std::string& session_id,
bool w3c_compliant) { … }
}
TEST(CommandsTest, BidiSessionStatusWithSession) { … }
namespace {
void ExecuteStubGetSession(int* count,
const base::Value::Dict& params,
const std::string& session_id,
const CommandCallback& callback) { … }
void OnGetSessions(const Status& status,
std::unique_ptr<base::Value> value,
const std::string& session_id,
bool w3c_compliant) { … }
}
TEST(CommandsTest, GetSessions) { … }
namespace {
void ExecuteStubQuit(int* count,
const base::Value::Dict& params,
const std::string& session_id,
const CommandCallback& callback) { … }
void OnQuitAll(const Status& status,
std::unique_ptr<base::Value> value,
const std::string& session_id,
bool w3c_compliant) { … }
}
TEST(CommandsTest, QuitAll) { … }
namespace {
Status ExecuteSimpleCommand(const std::string& expected_id,
base::Value::Dict* expected_params,
base::Value* value,
Session* session,
const base::Value::Dict& params,
std::unique_ptr<base::Value>* return_value) { … }
void OnSimpleCommand(base::RunLoop* run_loop,
const std::string& expected_session_id,
base::Value* expected_value,
const Status& status,
std::unique_ptr<base::Value> value,
const std::string& session_id,
bool w3c_compliant) { … }
}
TEST(CommandsTest, ExecuteSessionCommand) { … }
namespace {
Status ShouldNotBeCalled(Session* session,
const base::Value::Dict& params,
std::unique_ptr<base::Value>* value) { … }
void OnNoSuchSession(const Status& status,
std::unique_ptr<base::Value> value,
const std::string& session_id,
bool w3c_compliant) { … }
void OnNoSuchSessionIsOk(const Status& status,
std::unique_ptr<base::Value> value,
const std::string& session_id,
bool w3c_compliant) { … }
}
TEST(CommandsTest, ExecuteSessionCommandOnNoSuchSession) { … }
TEST(CommandsTest, ExecuteSessionCommandOnNoSuchSessionWhenItExpectsOk) { … }
namespace {
void OnNoSuchSessionAndQuit(base::RunLoop* run_loop,
const Status& status,
std::unique_ptr<base::Value> value,
const std::string& session_id,
bool w3c_compliant) { … }
}
TEST(CommandsTest, ExecuteSessionCommandOnJustDeletedSession) { … }
namespace {
enum TestScenario { … };
class FindElementWebView : public StubWebView { … };
}
TEST(CommandsTest, SuccessfulFindElement) { … }
TEST(CommandsTest, FailedFindElement) { … }
TEST(CommandsTest, SuccessfulFindElements) { … }
TEST(CommandsTest, FailedFindElements) { … }
TEST(CommandsTest, SuccessfulFindChildElement) { … }
TEST(CommandsTest, FailedFindChildElement) { … }
TEST(CommandsTest, SuccessfulFindChildElements) { … }
TEST(CommandsTest, FailedFindChildElements) { … }
TEST(CommandsTest, TimeoutInFindElement) { … }
namespace {
class NavigatingWebView : public StubWebView { … };
#if defined(MEMORY_SANITIZER)
base::TimeDelta kImplicitWait = base::Seconds(100);
#elif defined(NDEBUG)
base::TimeDelta kImplicitWait = base::Seconds(3);
#else
base::TimeDelta kImplicitWait = …;
#endif
}
TEST(CommandsTest, FindElementWhileNavigating) { … }
TEST(CommandsTest, FindElementWhileNavigatingTooLong) { … }
TEST(CommandsTest, FindElementsWhileNavigating) { … }
TEST(CommandsTest, FindElementsWhileNavigatingTooLong) { … }
namespace {
class ErrorCallFunctionWebView : public StubWebView { … };
}
TEST(CommandsTest, ErrorFindElement) { … }
TEST(CommandsTest, ErrorFindChildElement) { … }
namespace {
class MockCommandListener : public CommandListener { … };
Status ExecuteQuitSessionCommand(Session* session,
const base::Value::Dict& params,
std::unique_ptr<base::Value>* return_value) { … }
void OnSessionCommand(base::RunLoop* run_loop,
const Status& status,
std::unique_ptr<base::Value> value,
const std::string& session_id,
bool w3c_compliant) { … }
}
TEST(CommandsTest, SuccessNotifyingCommandListeners) { … }
namespace {
class FailingCommandListener : public CommandListener { … };
void AddListenerToSessionIfSessionExists(
std::unique_ptr<CommandListener> listener) { … }
void OnFailBecauseErrorNotifyingListeners(base::RunLoop* run_loop,
const Status& status,
std::unique_ptr<base::Value> value,
const std::string& session_id,
bool w3c_compliant) { … }
void VerifySessionWasDeleted() { … }
}
TEST(CommandsTest, ErrorNotifyingCommandListeners) { … }