Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: chrome/test/webdriver/session.cc

Issue 5572001: Send screenshots back to the client for debugging (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: added tests which compare against a reference md5 hash Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_manager.h" 5 #include "chrome/test/webdriver/session_manager.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/message_loop_proxy.h" 16 #include "base/message_loop_proxy.h"
17 #include "base/process.h" 17 #include "base/process.h"
18 #include "base/process_util.h" 18 #include "base/process_util.h"
19 #include "base/scoped_ptr.h" 19 #include "base/scoped_ptr.h"
20 #include "base/scoped_temp_dir.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"
27 #include "base/time.h" 28 #include "base/time.h"
28 #include "base/utf_string_conversions.h" 29 #include "base/utf_string_conversions.h"
29 #include "base/values.h" 30 #include "base/values.h"
(...skipping 22 matching lines...) Expand all
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 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 int x = 0, y = 0; 863 int x = 0, y = 0;
862 if (!loc_dict->GetInteger("x", &x) || 864 if (!loc_dict->GetInteger("x", &x) ||
863 !loc_dict->GetInteger("y", &y)) { 865 !loc_dict->GetInteger("y", &y)) {
864 LOG(ERROR) << "Location atom returned bad coordinate dictionary"; 866 LOG(ERROR) << "Location atom returned bad coordinate dictionary";
865 code = kUnknownError; 867 code = kUnknownError;
866 } 868 }
867 *location = gfx::Point(x, y); 869 *location = gfx::Point(x, y);
868 return kSuccess; 870 return kSuccess;
869 } 871 }
870 872
873 bool Session::GetScreenShot(std::string* png) {
874 bool success = false;
875 ScopedTempDir screenshots_dir;
876
877 // Create a temp directory for screenshots.
878 if (!screenshots_dir.CreateUniqueTempDir()) {
879 return false;
880 }
881
882 FilePath path = screenshots_dir.path().AppendASCII("screen");
883
884 RunSessionTask(NewRunnableMethod(
885 automation_.get(),
886 &Automation::CaptureEntirePageAsPNG,
887 current_target_.window_id,
888 path,
889 &success));
890
891 if (success) {
892 success = file_util::ReadFileToString(path, png);
893 }
894 return success;
895 }
896
897 void Session::set_screenshot_on_error(bool error) {
898 screenshot_on_error_ = error;
899 }
900
901 bool Session::get_screenshot_on_error() const {
902 return screenshot_on_error_;
903 }
904
905 const std::string& Session::id() const {
906 return id_;
907 }
908
909 int Session::implicit_wait() const {
910 return implicit_wait_;
911 }
912
913 void Session::set_implicit_wait(const int& timeout) {
914 implicit_wait_ = timeout > 0 ? timeout : 0;
915 }
916
917 Session::Speed Session::speed() {
918 return speed_;
919 }
920
921 void Session::set_speed(Speed speed) {
922 speed_ = speed;
923 }
924
871 } // namespace webdriver 925 } // namespace webdriver
OLDNEW
« chrome/test/webdriver/session.h ('K') | « chrome/test/webdriver/session.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698