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

Side by Side Diff: chrome/test/webdriver/utility_functions.cc

Issue 3064012: Base implementation of WebDriver for Chrome. This checkin includes... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/webdriver/utility_functions.h ('k') | chrome/test/webdriver/webdriver_tests.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 #include "chrome/test/webdriver/utility_functions.h"
6
7 #include <string.h>
8 #include <wchar.h>
9 #include <algorithm>
10 #include <sstream>
11
12 #include "base/json/json_reader.h"
13 #include "base/logging.h"
14 #include "base/scoped_ptr.h"
15
16 #include "third_party/webdriver/atoms.h"
17
18 namespace webdriver {
19
20 std::wstring build_atom(const wchar_t* const atom[], const size_t& size) {
21 const size_t len = size / sizeof(atom[0]);
22 std::wstring ret = L"";
23 for (size_t i = 0; i < len; ++i) {
24 if (atom[i] != NULL) {
25 ret.append(std::wstring(atom[i]));
26 }
27 }
28 return ret;
29 }
30
31 std::wstring print_valuetype(Value::ValueType e) {
32 switch (e) {
33 case Value::TYPE_NULL:
34 return L"NULL ";
35 case Value::TYPE_BOOLEAN:
36 return L"BOOL";
37 case Value::TYPE_INTEGER:
38 return L"INT";
39 case Value::TYPE_REAL:
40 return L"REAL";
41 case Value::TYPE_STRING:
42 return L"STRING";
43 case Value::TYPE_BINARY:
44 return L"BIN";
45 case Value::TYPE_DICTIONARY:
46 return L"DICT";
47 case Value::TYPE_LIST:
48 return L"LIST";
49 default:
50 return L"ERROR";
51 }
52 }
53
54 void CheckValueType(const Value::ValueType expected,
55 const Value* const actual) {
56 DCHECK(actual != NULL) << "Expected value to be non-NULL";
57 DCHECK(expected == actual->GetType())
58 << "Expected " << print_valuetype(expected)
59 << ", but was " << print_valuetype(actual->GetType());
60 }
61
62 bool ParseJSONDictionary(const std::string& json, DictionaryValue** dict,
63 std::string* error) {
64 int error_code = 0;
65 Value* params =
66 base::JSONReader::ReadAndReturnError(json, true, &error_code, error);
67 if (error_code != 0) {
68 LOG(INFO) << "Could not parse JSON object, " << *error << std::endl;
69 if (params) {
70 delete params;
71 }
72 return false;
73 }
74
75 if (!params || params->GetType() != Value::TYPE_DICTIONARY) {
76 *error = "Data passed in URL must be of type dictionary.";
77 LOG(INFO) << "Invalid type to parse" << std::endl;
78 if (params) {
79 delete params;
80 }
81 return false;
82 }
83
84 *dict = static_cast<DictionaryValue*>(params);
85 return true;
86 }
87 } // namespace webdriver
88
OLDNEW
« no previous file with comments | « chrome/test/webdriver/utility_functions.h ('k') | chrome/test/webdriver/webdriver_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698