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/commands/screenshot_command.h" | 5 #include "chrome/test/webdriver/commands/screenshot_command.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/test/webdriver/commands/response.h" | 12 #include "chrome/test/webdriver/commands/response.h" |
13 #include "chrome/test/webdriver/webdriver_error.h" | 13 #include "chrome/test/webdriver/webdriver_error.h" |
14 #include "chrome/test/webdriver/webdriver_session.h" | 14 #include "chrome/test/webdriver/webdriver_session.h" |
15 | 15 |
16 namespace webdriver { | 16 namespace webdriver { |
17 | 17 |
18 ScreenshotCommand::ScreenshotCommand(const std::vector<std::string>& ps, | 18 ScreenshotCommand::ScreenshotCommand(const std::vector<std::string>& ps, |
19 const DictionaryValue* const parameters) | 19 DictionaryValue* const parameters) |
20 : WebDriverCommand(ps, parameters) {} | 20 : WebDriverCommand(ps, parameters) {} |
21 | 21 |
22 ScreenshotCommand::~ScreenshotCommand() {} | 22 ScreenshotCommand::~ScreenshotCommand() {} |
23 | 23 |
24 bool ScreenshotCommand::DoesGet() { | 24 bool ScreenshotCommand::DoesGet() { |
25 return true; | 25 return true; |
26 } | 26 } |
27 | 27 |
28 void ScreenshotCommand::ExecuteGet(Response* const response) { | 28 void ScreenshotCommand::ExecuteGet(Response* const response) { |
29 std::string raw_bytes; | 29 std::string raw_bytes; |
30 Error* error = session_->GetScreenShot(&raw_bytes); | 30 Error* error = session_->GetScreenShot(&raw_bytes); |
31 if (error) { | 31 if (error) { |
32 response->SetError(error); | 32 response->SetError(error); |
33 return; | 33 return; |
34 } | 34 } |
35 | 35 |
36 // Convert the raw binary data to base 64 encoding for webdriver. | 36 // Convert the raw binary data to base 64 encoding for webdriver. |
37 std::string base64_screenshot; | 37 std::string base64_screenshot; |
38 if (!base::Base64Encode(raw_bytes, &base64_screenshot)) { | 38 if (!base::Base64Encode(raw_bytes, &base64_screenshot)) { |
39 response->SetError(new Error( | 39 response->SetError(new Error( |
40 kUnknownError, "Encoding the PNG to base64 format failed")); | 40 kUnknownError, "Encoding the PNG to base64 format failed")); |
41 return; | 41 return; |
42 } | 42 } |
43 | 43 |
44 response->SetValue(new StringValue(base64_screenshot)); | 44 response->SetValue(new StringValue(base64_screenshot)); |
45 } | 45 } |
46 | 46 |
47 } // namespace webdriver | 47 } // namespace webdriver |
OLD | NEW |