| Index: chrome/test/webdriver/session.cc
|
| diff --git a/chrome/test/webdriver/session.cc b/chrome/test/webdriver/session.cc
|
| index 400c7eb42915ce74bb5d74ceabe435380e71bfb0..5d6ba6dd4ffceebd3ff6a229eb2e69b359d59917 100644
|
| --- a/chrome/test/webdriver/session.cc
|
| +++ b/chrome/test/webdriver/session.cc
|
| @@ -7,6 +7,7 @@
|
| #include <sstream>
|
| #include <vector>
|
|
|
| +#include "base/base64.h"
|
| #include "base/command_line.h"
|
| #include "base/file_path.h"
|
| #include "base/file_util.h"
|
| @@ -17,6 +18,7 @@
|
| #include "base/process.h"
|
| #include "base/process_util.h"
|
| #include "base/scoped_ptr.h"
|
| +#include "base/scoped_temp_dir.h"
|
| #include "base/stringprintf.h"
|
| #include "base/string_number_conversions.h"
|
| #include "base/string_split.h"
|
| @@ -65,8 +67,10 @@ bool Session::Init(const FilePath& browser_dir) {
|
| } else {
|
| LOG(ERROR) << "Cannot start session thread";
|
| }
|
| +
|
| if (!success)
|
| delete this;
|
| +
|
| return success;
|
| }
|
|
|
| @@ -355,6 +359,56 @@ bool Session::GetWindowIds(std::vector<int>* window_ids) {
|
| return success;
|
| }
|
|
|
| +bool Session::CaptureEntirePageAsPNG(const FilePath& path) {
|
| + bool success = false;
|
| + RunSessionTask(NewRunnableMethod(
|
| + automation_.get(),
|
| + &Automation::CaptureEntirePageAsPNG,
|
| + current_window_id_,
|
| + path,
|
| + &success));
|
| + return success;
|
| +}
|
| +
|
| +bool Session::ScreenshotAsBase64(std::string* screenshot) {
|
| + ScopedTempDir screenshots_dir;
|
| +
|
| + // Create a temp directory for screenshots.
|
| + if (!screenshots_dir.CreateUniqueTempDir()) {
|
| + LOG(ERROR) << "Could not make a temp directory for screenshots";
|
| + return false;
|
| + }
|
| +
|
| + // Generate a temp file name for the screenshot
|
| + std::string file = screenshots_dir.path().value() + "screen";
|
| +
|
| +#ifdef OS_POSIX
|
| + FilePath path = FilePath(file.c_str());
|
| +#elif OS_WIN
|
| + FilePath path = FilePath(ASCIIToWide(file.s_ctr()));
|
| +#endif
|
| +
|
| + // Capture the current tab as a PNG file.
|
| + if (!CaptureEntirePageAsPNG(path)) {
|
| + LOG(ERROR) << "Capturing tab page as PNG failed";
|
| + return false;
|
| + }
|
| +
|
| + std::string raw_bytes;
|
| + if (!file_util::ReadFileToString(path, &raw_bytes)) {
|
| + LOG(ERROR) << "Opening PNG file failed";
|
| + return false;
|
| + }
|
| +
|
| + // Make a base64 encoded string for the raw PNG data
|
| + if (!base::Base64Encode(raw_bytes, screenshot)) {
|
| + LOG(ERROR) << "Encoding the PNG to base64 format failed";
|
| + return false;
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| ErrorCode Session::SwitchToWindow(const std::string& name) {
|
| int switch_to_id = 0;
|
| int name_no = 0;
|
| @@ -560,6 +614,38 @@ bool Session::WaitForAllTabsToStopLoading() {
|
| return success;
|
| }
|
|
|
| +std::string Session::Id() const {
|
| + return id_;
|
| +}
|
| +
|
| +int Session::ImplicitWait() const {
|
| + return implicit_wait_;
|
| +}
|
| +
|
| +void Session::SetImplicitWait(const int& timeout) {
|
| + implicit_wait_ = timeout > 0 ? timeout : 0;
|
| +}
|
| +
|
| +Session::InputSpeed Session::Speed() const {
|
| + return speed_;
|
| +}
|
| +
|
| +void Session::SetSpeed(const InputSpeed& speed) {
|
| + speed_ = speed;
|
| +}
|
| +
|
| +std::string Session::CurrentFrameXPath() const {
|
| + return current_frame_xpath_;
|
| +}
|
| +
|
| +void Session::SetCurrentFrameXPath(const std::string& xpath) {
|
| + current_frame_xpath_ = xpath;
|
| +}
|
| +
|
| +int Session::CurrentWindowId() const {
|
| + return current_window_id_;
|
| +}
|
| +
|
| void Session::RunSessionTask(Task* task) {
|
| base::WaitableEvent done_event(false, false);
|
| thread_.message_loop_proxy()->PostTask(FROM_HERE, NewRunnableMethod(
|
|
|