| 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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/test/automation/value_conversion_traits.h" | 14 #include "chrome/test/automation/value_conversion_traits.h" |
| 15 #include "chrome/test/webdriver/webdriver_error.h" | 15 #include "chrome/test/webdriver/webdriver_error.h" |
| 16 | 16 |
| 17 class AutomationId; | 17 class AutomationId; |
| 18 class WebViewId; |
| 19 |
| 20 namespace base { |
| 18 class FilePath; | 21 class FilePath; |
| 19 class WebViewId; | 22 } |
| 20 | 23 |
| 21 namespace webdriver { | 24 namespace webdriver { |
| 22 | 25 |
| 23 // Generates a random, 32-character hexidecimal ID. | 26 // Generates a random, 32-character hexidecimal ID. |
| 24 std::string GenerateRandomID(); | 27 std::string GenerateRandomID(); |
| 25 | 28 |
| 26 // Decodes the given base64-encoded string, after removing any newlines, | 29 // Decodes the given base64-encoded string, after removing any newlines, |
| 27 // which are required in some base64 standards. | 30 // which are required in some base64 standards. |
| 28 // Returns true on success. | 31 // Returns true on success. |
| 29 bool Base64Decode(const std::string& base64, std::string* bytes); | 32 bool Base64Decode(const std::string& base64, std::string* bytes); |
| 30 | 33 |
| 31 // Unzip the given zip archive, after base64 decoding, into the given directory. | 34 // Unzip the given zip archive, after base64 decoding, into the given directory. |
| 32 // Returns true on success. | 35 // Returns true on success. |
| 33 bool Base64DecodeAndUnzip(const FilePath& unzip_dir, | 36 bool Base64DecodeAndUnzip(const base::FilePath& unzip_dir, |
| 34 const std::string& base64, | 37 const std::string& base64, |
| 35 std::string* error_msg); | 38 std::string* error_msg); |
| 36 | 39 |
| 37 // Unzips the sole file contained in the given zip data |bytes| into | 40 // Unzips the sole file contained in the given zip data |bytes| into |
| 38 // |unzip_dir|. The zip data may be a normal zip archive or a single zip file | 41 // |unzip_dir|. The zip data may be a normal zip archive or a single zip file |
| 39 // entry. If the unzip successfully produced one file, returns true and sets | 42 // entry. If the unzip successfully produced one file, returns true and sets |
| 40 // |file| to the unzipped file. | 43 // |file| to the unzipped file. |
| 41 // TODO(kkania): Remove the ability to parse single zip file entries when | 44 // TODO(kkania): Remove the ability to parse single zip file entries when |
| 42 // the current versions of all WebDriver clients send actual zip files. | 45 // the current versions of all WebDriver clients send actual zip files. |
| 43 bool UnzipSoleFile(const FilePath& unzip_dir, | 46 bool UnzipSoleFile(const base::FilePath& unzip_dir, |
| 44 const std::string& bytes, | 47 const std::string& bytes, |
| 45 FilePath* file, | 48 base::FilePath* file, |
| 46 std::string* error_msg); | 49 std::string* error_msg); |
| 47 | 50 |
| 48 // Returns the equivalent JSON string for the given value. | 51 // Returns the equivalent JSON string for the given value. |
| 49 std::string JsonStringify(const base::Value* value); | 52 std::string JsonStringify(const base::Value* value); |
| 50 | 53 |
| 51 // Returns the JSON string for the given value, with the exception that | 54 // Returns the JSON string for the given value, with the exception that |
| 52 // long strings are shortened for easier display. | 55 // long strings are shortened for easier display. |
| 53 std::string JsonStringifyForDisplay(const base::Value* value); | 56 std::string JsonStringifyForDisplay(const base::Value* value); |
| 54 | 57 |
| 55 // Returns the string representation of the given type, for display purposes. | 58 // Returns the string representation of the given type, for display purposes. |
| 56 const char* GetJsonTypeName(base::Value::Type type); | 59 const char* GetJsonTypeName(base::Value::Type type); |
| 57 | 60 |
| 58 // Converts the automation ID to a string. | 61 // Converts the automation ID to a string. |
| 59 std::string AutomationIdToString(const AutomationId& id); | 62 std::string AutomationIdToString(const AutomationId& id); |
| 60 | 63 |
| 61 // Converts the string to an automation ID and returns true on success. | 64 // Converts the string to an automation ID and returns true on success. |
| 62 bool StringToAutomationId(const std::string& string_id, AutomationId* id); | 65 bool StringToAutomationId(const std::string& string_id, AutomationId* id); |
| 63 | 66 |
| 64 // Converts the web view ID to a string. | 67 // Converts the web view ID to a string. |
| 65 std::string WebViewIdToString(const WebViewId& view_id); | 68 std::string WebViewIdToString(const WebViewId& view_id); |
| 66 | 69 |
| 67 // Converts the string to a web view ID and returns true on success. | 70 // Converts the string to a web view ID and returns true on success. |
| 68 bool StringToWebViewId(const std::string& string_id, WebViewId* view_id); | 71 bool StringToWebViewId(const std::string& string_id, WebViewId* view_id); |
| 69 | 72 |
| 70 // Flattens the given list of strings into one. | 73 // Flattens the given list of strings into one. |
| 71 Error* FlattenStringArray(const ListValue* src, string16* dest); | 74 Error* FlattenStringArray(const ListValue* src, string16* dest); |
| 72 | 75 |
| 73 #if defined(OS_MACOSX) | 76 #if defined(OS_MACOSX) |
| 74 // Gets the paths to the user and local application directory. | 77 // Gets the paths to the user and local application directory. |
| 75 void GetApplicationDirs(std::vector<FilePath>* app_dirs); | 78 void GetApplicationDirs(std::vector<base::FilePath>* app_dirs); |
| 76 #endif | 79 #endif |
| 77 | 80 |
| 78 // Parses a given value. | 81 // Parses a given value. |
| 79 class ValueParser { | 82 class ValueParser { |
| 80 public: | 83 public: |
| 81 virtual ~ValueParser(); | 84 virtual ~ValueParser(); |
| 82 virtual bool Parse(base::Value* value) const = 0; | 85 virtual bool Parse(base::Value* value) const = 0; |
| 83 | 86 |
| 84 protected: | 87 protected: |
| 85 ValueParser(); | 88 ValueParser(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 | 125 |
| 123 // Value conversion traits for SkipParsing, which just return true. | 126 // Value conversion traits for SkipParsing, which just return true. |
| 124 template <> | 127 template <> |
| 125 struct ValueConversionTraits<webdriver::SkipParsing> { | 128 struct ValueConversionTraits<webdriver::SkipParsing> { |
| 126 static bool SetFromValue(const base::Value* value, | 129 static bool SetFromValue(const base::Value* value, |
| 127 const webdriver::SkipParsing* t); | 130 const webdriver::SkipParsing* t); |
| 128 static bool CanConvert(const base::Value* value); | 131 static bool CanConvert(const base::Value* value); |
| 129 }; | 132 }; |
| 130 | 133 |
| 131 #endif // CHROME_TEST_WEBDRIVER_WEBDRIVER_UTIL_H_ | 134 #endif // CHROME_TEST_WEBDRIVER_WEBDRIVER_UTIL_H_ |
| OLD | NEW |