This source file includes following definitions.
- TEST
- Quit
- TEST
- TEST
- Quit
- TEST
- TEST
#include <string>
#include "base/bind.h"
#include "base/callback.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/threading/thread.h"
#include "base/values.h"
#include "chrome/test/chromedriver/chrome/status.h"
#include "chrome/test/chromedriver/chrome/stub_chrome.h"
#include "chrome/test/chromedriver/commands.h"
#include "chrome/test/chromedriver/session.h"
#include "chrome/test/chromedriver/session_commands.h"
#include "testing/gtest/include/gtest/gtest.h"
TEST(SessionCommandTest, FileUpload) {
Session session("id");
base::DictionaryValue params;
scoped_ptr<base::Value> value;
const char* kBase64ZipEntry =
"UEsDBBQAAAAAAMROi0K/wAzGBAAAAAQAAAADAAAAbW9vQ09XClBLAQIUAxQAAAAAAMROi0K/"
"wAzG\nBAAAAAQAAAADAAAAAAAAAAAAAACggQAAAABtb29QSwUGAAAAAAEAAQAxAAAAJQAAAA"
"AA\n";
params.SetString("file", kBase64ZipEntry);
Status status = ExecuteUploadFile(&session, params, &value);
ASSERT_EQ(kOk, status.code()) << status.message();
base::FilePath::StringType path;
ASSERT_TRUE(value->GetAsString(&path));
ASSERT_TRUE(base::PathExists(base::FilePath(path)));
std::string data;
ASSERT_TRUE(base::ReadFileToString(base::FilePath(path), &data));
ASSERT_STREQ("COW\n", data.c_str());
}
namespace {
class DetachChrome : public StubChrome {
public:
DetachChrome() : quit_called_(false) {}
virtual ~DetachChrome() {}
virtual Status Quit() OVERRIDE {
quit_called_ = true;
return Status(kOk);
}
bool quit_called_;
};
}
TEST(SessionCommandsTest, Quit) {
DetachChrome* chrome = new DetachChrome();
Session session("id", scoped_ptr<Chrome>(chrome));
base::DictionaryValue params;
scoped_ptr<base::Value> value;
ASSERT_EQ(kOk, ExecuteQuit(false, &session, params, &value).code());
ASSERT_TRUE(chrome->quit_called_);
chrome->quit_called_ = false;
ASSERT_EQ(kOk, ExecuteQuit(true, &session, params, &value).code());
ASSERT_TRUE(chrome->quit_called_);
}
TEST(SessionCommandsTest, QuitWithDetach) {
DetachChrome* chrome = new DetachChrome();
Session session("id", scoped_ptr<Chrome>(chrome));
session.detach = true;
base::DictionaryValue params;
scoped_ptr<base::Value> value;
ASSERT_EQ(kOk, ExecuteQuit(true, &session, params, &value).code());
ASSERT_FALSE(chrome->quit_called_);
ASSERT_EQ(kOk, ExecuteQuit(false, &session, params, &value).code());
ASSERT_TRUE(chrome->quit_called_);
}
namespace {
class FailsToQuitChrome : public StubChrome {
public:
FailsToQuitChrome() {}
virtual ~FailsToQuitChrome() {}
virtual Status Quit() OVERRIDE {
return Status(kUnknownError);
}
};
}
TEST(SessionCommandsTest, QuitFails) {
Session session("id", scoped_ptr<Chrome>(new FailsToQuitChrome()));
base::DictionaryValue params;
scoped_ptr<base::Value> value;
ASSERT_EQ(kUnknownError, ExecuteQuit(false, &session, params, &value).code());
}
TEST(SessionCommandsTest, AutoReporting) {
DetachChrome* chrome = new DetachChrome();
Session session("id", scoped_ptr<Chrome>(chrome));
base::DictionaryValue params;
scoped_ptr<base::Value> value;
StatusCode status_code;
bool enabled;
status_code = ExecuteIsAutoReporting(&session, params, &value).code();
ASSERT_EQ(kOk, status_code);
ASSERT_FALSE(session.auto_reporting_enabled);
ASSERT_TRUE(value.get()->GetAsBoolean(&enabled));
ASSERT_FALSE(enabled);
status_code = ExecuteSetAutoReporting(&session, params, &value).code();
ASSERT_EQ(kUnknownError, status_code);
params.SetBoolean("enabled", true);
status_code = ExecuteSetAutoReporting(&session, params, &value).code();
ASSERT_EQ(kOk, status_code);
ASSERT_TRUE(session.auto_reporting_enabled);
status_code = ExecuteIsAutoReporting(&session, params, &value).code();
ASSERT_EQ(kOk, status_code);
ASSERT_TRUE(value.get()->GetAsBoolean(&enabled));
ASSERT_TRUE(enabled);
params.SetBoolean("enabled", false);
status_code = ExecuteSetAutoReporting(&session, params, &value).code();
ASSERT_EQ(kOk, status_code);
ASSERT_FALSE(session.auto_reporting_enabled);
status_code = ExecuteIsAutoReporting(&session, params, &value).code();
ASSERT_EQ(kOk, status_code);
ASSERT_TRUE(value.get()->GetAsBoolean(&enabled));
ASSERT_FALSE(enabled);
}