Chromium Code Reviews| Index: chrome/test/webdriver/session.cc |
| diff --git a/chrome/test/webdriver/session.cc b/chrome/test/webdriver/session.cc |
| index 400c7eb42915ce74bb5d74ceabe435380e71bfb0..19eff541ce1c3049dae5d4515754f521a31f0d1f 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"; |
|
kkania
2011/03/07 18:15:17
instead of all this code, you should be able to ju
Joe
2011/03/11 22:12:48
That would keep the file around until the session
|
| + |
| +#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) { |
|
kkania
2011/03/07 18:15:17
Why did you change these func names?
|
| + 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( |