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

Side by Side Diff: chrome/test/webdriver/commands/response.h

Issue 5572001: Send screenshots back to the client for debugging (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: for review Created 9 years, 10 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #ifndef CHROME_TEST_WEBDRIVER_COMMANDS_RESPONSE_H_ 5 #ifndef CHROME_TEST_WEBDRIVER_COMMANDS_RESPONSE_H_
6 #define CHROME_TEST_WEBDRIVER_COMMANDS_RESPONSE_H_ 6 #define CHROME_TEST_WEBDRIVER_COMMANDS_RESPONSE_H_
7 7
8 #include <sstream> 8 #include <sstream>
9 #include <string> 9 #include <string>
10 10
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/test/webdriver/error_codes.h" 12 #include "chrome/test/webdriver/error_codes.h"
13 13
14 namespace webdriver { 14 namespace webdriver {
15 15
16 // All errors in webdriver must use this macro in order to send back 16 // All errors in webdriver must use this macro in order to send back
17 // a proper stack trace to the client 17 // a proper stack trace to the client
18 #define SET_WEBDRIVER_ERROR(response, msg, err) \ 18 #define SET_WEBDRIVER_ERROR(response, msg, err) \
19 response->SetError(err, msg, __FILE__, __LINE__); \ 19 response->SetError(err, msg, __FILE__, __LINE__); \
20 LOG(ERROR) << msg 20 LOG(ERROR) << msg
21 21
22 // Use this macro for errors in which a screenshot can be taken and
23 // sent back to the client. A proper stack trace will also be included.
24 #define SET_WEBDRIVER_SCREENSHOT_ERROR(response, session, msg, err) { \
25 LOG(ERROR) << msg; \
26 std::string __screenshot__; \
27 session->ScreenshotAsBase64(&__screenshot__); \
28 response->SetError(err, msg, __FILE__, __LINE__); \
29 response->SetScreenshot(__screenshot__); \
30 }
31
22 // A simple class that encapsulates the information describing the response to 32 // A simple class that encapsulates the information describing the response to
23 // a |Command|. In Webdriver all responses must be sent back as a JSON value, 33 // a |Command|. In Webdriver all responses must be sent back as a JSON value,
24 // conforming to the spec found at: 34 // conforming to the spec found at:
25 // http://code.google.com/p/selenium/wiki/JsonWireProtocol#Messages 35 // http://code.google.com/p/selenium/wiki/JsonWireProtocol#Messages
26 class Response { 36 class Response {
27 public: 37 public:
28 // Creates a new |Response| with a default status of |kSuccess| and a 38 // Creates a new |Response| with a default status of |kSuccess| and a
29 // |NullValue|. 39 // |NullValue|.
30 Response(); 40 Response();
31 ~Response(); 41 ~Response();
(...skipping 13 matching lines...) Expand all
45 // set using the |SET_WEBDRIVER_ERROR| macro above. 55 // set using the |SET_WEBDRIVER_ERROR| macro above.
46 void SetError(ErrorCode error, const std::string& message, 56 void SetError(ErrorCode error, const std::string& message,
47 const std::string& file, int line); 57 const std::string& file, int line);
48 58
49 // Sets a JSON field in this response. The |key| may be a "." delimitted 59 // Sets a JSON field in this response. The |key| may be a "." delimitted
50 // string to indicate the value should be set in a nested object. Any 60 // string to indicate the value should be set in a nested object. Any
51 // previously set value for the |key| will be deleted. 61 // previously set value for the |key| will be deleted.
52 // This object assumes ownership of |value|. 62 // This object assumes ownership of |value|.
53 void SetField(const std::string& key, Value* value); 63 void SetField(const std::string& key, Value* value);
54 64
65 // Sets the screenshot to return to the client for debugging. The file must
66 // be a base64 encoded PNG file.
67 void SetScreenshot(const std::string& screenshot);
68
55 // Returns this response as a JSON string. 69 // Returns this response as a JSON string.
56 std::string ToJSON() const; 70 std::string ToJSON() const;
57 71
58 private: 72 private:
59 DictionaryValue data_; 73 DictionaryValue data_;
74 std::string screenshot_;
60 75
61 DISALLOW_COPY_AND_ASSIGN(Response); 76 DISALLOW_COPY_AND_ASSIGN(Response);
62 }; 77 };
63 78
64 } // namespace webdriver 79 } // namespace webdriver
65 80
66 #endif // CHROME_TEST_WEBDRIVER_COMMANDS_RESPONSE_H_ 81 #endif // CHROME_TEST_WEBDRIVER_COMMANDS_RESPONSE_H_
67 82
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698