OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_TEST_WEBDRIVER_WEBDRIVER_UTIL_H_ |
| 6 #define CHROME_TEST_WEBDRIVER_WEBDRIVER_UTIL_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" |
| 14 #include "chrome/test/automation/value_conversion_traits.h" |
| 15 |
| 16 class FilePath; |
| 17 |
| 18 namespace base { |
| 19 class Value; |
| 20 } |
| 21 |
| 22 namespace webdriver { |
| 23 |
| 24 // Generates a random, 32-character hexidecimal ID. |
| 25 std::string GenerateRandomID(); |
| 26 |
| 27 // Returns the equivalent JSON string for the given value. |
| 28 std::string JsonStringify(const base::Value* value); |
| 29 |
| 30 #if defined(OS_MACOSX) |
| 31 // Gets the paths to the user and local application directory. |
| 32 void GetApplicationDirs(std::vector<FilePath>* app_dirs); |
| 33 #endif |
| 34 |
| 35 // Parses a given value. |
| 36 class ValueParser { |
| 37 public: |
| 38 virtual ~ValueParser(); |
| 39 virtual bool Parse(base::Value* value) const = 0; |
| 40 |
| 41 protected: |
| 42 ValueParser(); |
| 43 |
| 44 private: |
| 45 DISALLOW_COPY_AND_ASSIGN(ValueParser); |
| 46 }; |
| 47 |
| 48 // Define a special type and constant that allows users to skip parsing a value. |
| 49 // Useful when wanting to skip parsing for one value out of many in a list. |
| 50 enum SkipParsing { }; |
| 51 extern SkipParsing* kSkipParsing; |
| 52 |
| 53 // Parses a given value using the |ValueConversionTraits| to the appropriate |
| 54 // type. This assumes that a direct conversion can be performed without |
| 55 // pulling the value out of a dictionary or list. |
| 56 template <typename T> |
| 57 class DirectValueParser : public ValueParser { |
| 58 public: |
| 59 explicit DirectValueParser(T* t) : t_(t) { } |
| 60 |
| 61 virtual ~DirectValueParser() { } |
| 62 |
| 63 virtual bool Parse(base::Value* value) const OVERRIDE { |
| 64 return ValueConversionTraits<T>::SetFromValue(value, t_); |
| 65 } |
| 66 |
| 67 private: |
| 68 T* t_; |
| 69 DISALLOW_COPY_AND_ASSIGN(DirectValueParser); |
| 70 }; |
| 71 |
| 72 // Convenience function for creating a DirectValueParser. |
| 73 template <typename T> |
| 74 DirectValueParser<T>* CreateDirectValueParser(T* t) { |
| 75 return new DirectValueParser<T>(t); |
| 76 } |
| 77 |
| 78 } // namespace webdriver |
| 79 |
| 80 // Value conversion traits for SkipParsing, which just return true. |
| 81 template <> |
| 82 struct ValueConversionTraits<webdriver::SkipParsing> { |
| 83 static bool SetFromValue(const base::Value* value, |
| 84 const webdriver::SkipParsing* t); |
| 85 static bool CanConvert(const base::Value* value); |
| 86 }; |
| 87 |
| 88 #endif // CHROME_TEST_WEBDRIVER_WEBDRIVER_UTIL_H_ |
OLD | NEW |