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

Unified Diff: chrome/test/webdriver/webdriver_util.h

Issue 7522024: Refactor chromedriver's script execution to reduce amount of custom Value parsing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/webdriver/webdriver_basic_types.cc ('k') | chrome/test/webdriver/webdriver_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/webdriver/webdriver_util.h
diff --git a/chrome/test/webdriver/webdriver_util.h b/chrome/test/webdriver/webdriver_util.h
new file mode 100644
index 0000000000000000000000000000000000000000..e36bdb733da438e92afdf4bb7e48472670397895
--- /dev/null
+++ b/chrome/test/webdriver/webdriver_util.h
@@ -0,0 +1,88 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_TEST_WEBDRIVER_WEBDRIVER_UTIL_H_
+#define CHROME_TEST_WEBDRIVER_WEBDRIVER_UTIL_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "chrome/test/automation/value_conversion_traits.h"
+
+class FilePath;
+
+namespace base {
+class Value;
+}
+
+namespace webdriver {
+
+// Generates a random, 32-character hexidecimal ID.
+std::string GenerateRandomID();
+
+// Returns the equivalent JSON string for the given value.
+std::string JsonStringify(const base::Value* value);
+
+#if defined(OS_MACOSX)
+// Gets the paths to the user and local application directory.
+void GetApplicationDirs(std::vector<FilePath>* app_dirs);
+#endif
+
+// Parses a given value.
+class ValueParser {
+ public:
+ virtual ~ValueParser();
+ virtual bool Parse(base::Value* value) const = 0;
+
+ protected:
+ ValueParser();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ValueParser);
+};
+
+// Define a special type and constant that allows users to skip parsing a value.
+// Useful when wanting to skip parsing for one value out of many in a list.
+enum SkipParsing { };
+extern SkipParsing* kSkipParsing;
+
+// Parses a given value using the |ValueConversionTraits| to the appropriate
+// type. This assumes that a direct conversion can be performed without
+// pulling the value out of a dictionary or list.
+template <typename T>
+class DirectValueParser : public ValueParser {
+ public:
+ explicit DirectValueParser(T* t) : t_(t) { }
+
+ virtual ~DirectValueParser() { }
+
+ virtual bool Parse(base::Value* value) const OVERRIDE {
+ return ValueConversionTraits<T>::SetFromValue(value, t_);
+ }
+
+ private:
+ T* t_;
+ DISALLOW_COPY_AND_ASSIGN(DirectValueParser);
+};
+
+// Convenience function for creating a DirectValueParser.
+template <typename T>
+DirectValueParser<T>* CreateDirectValueParser(T* t) {
+ return new DirectValueParser<T>(t);
+}
+
+} // namespace webdriver
+
+// Value conversion traits for SkipParsing, which just return true.
+template <>
+struct ValueConversionTraits<webdriver::SkipParsing> {
+ static bool SetFromValue(const base::Value* value,
+ const webdriver::SkipParsing* t);
+ static bool CanConvert(const base::Value* value);
+};
+
+#endif // CHROME_TEST_WEBDRIVER_WEBDRIVER_UTIL_H_
« no previous file with comments | « chrome/test/webdriver/webdriver_basic_types.cc ('k') | chrome/test/webdriver/webdriver_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698