OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_WEBDRIVER_UTIL_H_ | 5 #ifndef CHROME_TEST_WEBDRIVER_WEBDRIVER_UTIL_H_ |
6 #define CHROME_TEST_WEBDRIVER_WEBDRIVER_UTIL_H_ | 6 #define CHROME_TEST_WEBDRIVER_WEBDRIVER_UTIL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/test/automation/value_conversion_traits.h" | 15 #include "chrome/test/automation/value_conversion_traits.h" |
16 #include "chrome/test/webdriver/webdriver_error.h" | 16 #include "chrome/test/webdriver/webdriver_error.h" |
17 | 17 |
18 class AutomationId; | 18 class AutomationId; |
19 class FilePath; | 19 class FilePath; |
20 class WebViewId; | 20 class WebViewId; |
21 | 21 |
22 namespace webdriver { | 22 namespace webdriver { |
23 | 23 |
24 // Generates a random, 32-character hexidecimal ID. | 24 // Generates a random, 32-character hexidecimal ID. |
25 std::string GenerateRandomID(); | 25 std::string GenerateRandomID(); |
26 | 26 |
| 27 // Decodes the given base64-encoded string, after removing any newlines, |
| 28 // which are required in some base64 standards. |
| 29 // Returns true on success. |
| 30 bool Base64Decode(const std::string& base64, std::string* bytes); |
| 31 |
| 32 // Unzip the given zip archive, after base64 decoding, into the given directory. |
| 33 // Returns true on success. |
| 34 bool Base64DecodeAndUnzip(const FilePath& unzip_dir, |
| 35 const std::string& base64, |
| 36 std::string* error_msg); |
| 37 |
| 38 // Unzips the sole file contained in the given zip data |bytes| into |
| 39 // |unzip_dir|. The zip data may be a normal zip archive or a single zip file |
| 40 // entry. If the unzip successfully produced one file, returns true and sets |
| 41 // |file| to the unzipped file. |
| 42 // TODO(kkania): Remove the ability to parse single zip file entries when |
| 43 // the current versions of all WebDriver clients send actual zip files. |
| 44 bool UnzipSoleFile(const FilePath& unzip_dir, |
| 45 const std::string& bytes, |
| 46 FilePath* file, |
| 47 std::string* error_msg); |
| 48 |
27 // Returns the equivalent JSON string for the given value. | 49 // Returns the equivalent JSON string for the given value. |
28 std::string JsonStringify(const base::Value* value); | 50 std::string JsonStringify(const base::Value* value); |
29 | 51 |
30 // Returns the JSON string for the given value, with the exception that | 52 // Returns the JSON string for the given value, with the exception that |
31 // long strings are shortened for easier display. | 53 // long strings are shortened for easier display. |
32 std::string JsonStringifyForDisplay(const base::Value* value); | 54 std::string JsonStringifyForDisplay(const base::Value* value); |
33 | 55 |
34 // Returns the string representation of the given type, for display purposes. | 56 // Returns the string representation of the given type, for display purposes. |
35 const char* GetJsonTypeName(base::Value::Type type); | 57 const char* GetJsonTypeName(base::Value::Type type); |
36 | 58 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 123 |
102 // Value conversion traits for SkipParsing, which just return true. | 124 // Value conversion traits for SkipParsing, which just return true. |
103 template <> | 125 template <> |
104 struct ValueConversionTraits<webdriver::SkipParsing> { | 126 struct ValueConversionTraits<webdriver::SkipParsing> { |
105 static bool SetFromValue(const base::Value* value, | 127 static bool SetFromValue(const base::Value* value, |
106 const webdriver::SkipParsing* t); | 128 const webdriver::SkipParsing* t); |
107 static bool CanConvert(const base::Value* value); | 129 static bool CanConvert(const base::Value* value); |
108 }; | 130 }; |
109 | 131 |
110 #endif // CHROME_TEST_WEBDRIVER_WEBDRIVER_UTIL_H_ | 132 #endif // CHROME_TEST_WEBDRIVER_WEBDRIVER_UTIL_H_ |
OLD | NEW |