| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/test/webdriver/session.h" | 5 #include "chrome/test/webdriver/session.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
| 14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/memory/scoped_temp_dir.h" |
| 17 #include "base/message_loop_proxy.h" | 18 #include "base/message_loop_proxy.h" |
| 18 #include "base/process.h" | 19 #include "base/process.h" |
| 19 #include "base/process_util.h" | 20 #include "base/process_util.h" |
| 20 #include "base/stringprintf.h" | 21 #include "base/stringprintf.h" |
| 21 #include "base/string_number_conversions.h" | 22 #include "base/string_number_conversions.h" |
| 22 #include "base/string_split.h" | 23 #include "base/string_split.h" |
| 23 #include "base/string_util.h" | 24 #include "base/string_util.h" |
| 24 #include "base/synchronization/waitable_event.h" | 25 #include "base/synchronization/waitable_event.h" |
| 25 #include "base/test/test_timeouts.h" | 26 #include "base/test/test_timeouts.h" |
| 26 #include "base/threading/platform_thread.h" | 27 #include "base/threading/platform_thread.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 52 FrameId& FrameId::operator=(const FrameId& other) { | 53 FrameId& FrameId::operator=(const FrameId& other) { |
| 53 window_id = other.window_id; | 54 window_id = other.window_id; |
| 54 frame_path = other.frame_path; | 55 frame_path = other.frame_path; |
| 55 return *this; | 56 return *this; |
| 56 } | 57 } |
| 57 | 58 |
| 58 Session::Session() | 59 Session::Session() |
| 59 : id_(GenerateRandomID()), | 60 : id_(GenerateRandomID()), |
| 60 thread_(id_.c_str()), | 61 thread_(id_.c_str()), |
| 61 implicit_wait_(0), | 62 implicit_wait_(0), |
| 63 screenshot_on_error_(false), |
| 62 current_target_(FrameId(0, FramePath())) { | 64 current_target_(FrameId(0, FramePath())) { |
| 63 SessionManager::GetInstance()->Add(this); | 65 SessionManager::GetInstance()->Add(this); |
| 64 } | 66 } |
| 65 | 67 |
| 66 Session::~Session() { | 68 Session::~Session() { |
| 67 SessionManager::GetInstance()->Remove(id_); | 69 SessionManager::GetInstance()->Remove(id_); |
| 68 } | 70 } |
| 69 | 71 |
| 70 bool Session::Init(const FilePath& browser_dir) { | 72 bool Session::Init(const FilePath& browser_dir) { |
| 71 bool success = false; | 73 bool success = false; |
| (...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 int x = 0, y = 0; | 976 int x = 0, y = 0; |
| 975 if (!loc_dict->GetInteger("x", &x) || | 977 if (!loc_dict->GetInteger("x", &x) || |
| 976 !loc_dict->GetInteger("y", &y)) { | 978 !loc_dict->GetInteger("y", &y)) { |
| 977 LOG(ERROR) << "Location atom returned bad coordinate dictionary"; | 979 LOG(ERROR) << "Location atom returned bad coordinate dictionary"; |
| 978 code = kUnknownError; | 980 code = kUnknownError; |
| 979 } | 981 } |
| 980 *location = gfx::Point(x, y); | 982 *location = gfx::Point(x, y); |
| 981 return kSuccess; | 983 return kSuccess; |
| 982 } | 984 } |
| 983 | 985 |
| 986 bool Session::GetScreenShot(std::string* png) { |
| 987 bool success = false; |
| 988 ScopedTempDir screenshots_dir; |
| 989 |
| 990 // Create a temp directory for screenshots. |
| 991 if (!screenshots_dir.CreateUniqueTempDir()) { |
| 992 return false; |
| 993 } |
| 994 |
| 995 FilePath path = screenshots_dir.path().AppendASCII("screen"); |
| 996 |
| 997 RunSessionTask(NewRunnableMethod( |
| 998 automation_.get(), |
| 999 &Automation::CaptureEntirePageAsPNG, |
| 1000 current_target_.window_id, |
| 1001 path, |
| 1002 &success)); |
| 1003 |
| 1004 if (success) { |
| 1005 success = file_util::ReadFileToString(path, png); |
| 1006 } |
| 1007 return success; |
| 1008 } |
| 1009 |
| 1010 void Session::set_screenshot_on_error(bool error) { |
| 1011 screenshot_on_error_ = error; |
| 1012 } |
| 1013 |
| 1014 bool Session::screenshot_on_error() const { |
| 1015 return screenshot_on_error_; |
| 1016 } |
| 1017 |
| 1018 const std::string& Session::id() const { |
| 1019 return id_; |
| 1020 } |
| 1021 |
| 1022 int Session::implicit_wait() const { |
| 1023 return implicit_wait_; |
| 1024 } |
| 1025 |
| 1026 void Session::set_implicit_wait(const int& timeout) { |
| 1027 implicit_wait_ = timeout > 0 ? timeout : 0; |
| 1028 } |
| 1029 |
| 1030 Session::Speed Session::speed() const { |
| 1031 return speed_; |
| 1032 } |
| 1033 |
| 1034 void Session::set_speed(Speed speed) { |
| 1035 speed_ = speed; |
| 1036 } |
| 1037 |
| 984 } // namespace webdriver | 1038 } // namespace webdriver |
| OLD | NEW |