OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/test/webdriver/utility_functions.h" | 5 #include "chrome/test/webdriver/utility_functions.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <wchar.h> | 8 #include <wchar.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <sstream> | 10 #include <sstream> |
11 | 11 |
12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
15 | 15 |
16 #include "third_party/webdriver/atoms.h" | 16 #include "third_party/webdriver/atoms.h" |
17 | 17 |
18 namespace webdriver { | 18 namespace webdriver { |
19 | 19 |
20 std::wstring build_atom(const wchar_t* const atom[], const size_t& size) { | 20 std::wstring build_atom(const wchar_t* const atom[], const size_t& size) { |
21 const size_t len = size / sizeof(atom[0]); | 21 const size_t len = size / sizeof(atom[0]); |
22 std::wstring ret = L""; | 22 std::wstring ret = L""; |
23 for (size_t i = 0; i < len; ++i) { | 23 for (size_t i = 0; i < len; ++i) { |
24 if (atom[i] != NULL) { | 24 if (atom[i] != NULL) |
25 ret.append(std::wstring(atom[i])); | 25 ret.append(std::wstring(atom[i])); |
26 } | |
27 } | 26 } |
28 return ret; | 27 return ret; |
29 } | 28 } |
30 | 29 |
31 std::wstring print_valuetype(Value::ValueType e) { | 30 std::wstring print_valuetype(Value::ValueType e) { |
32 switch (e) { | 31 switch (e) { |
33 case Value::TYPE_NULL: | 32 case Value::TYPE_NULL: |
34 return L"NULL "; | 33 return L"NULL "; |
35 case Value::TYPE_BOOLEAN: | 34 case Value::TYPE_BOOLEAN: |
36 return L"BOOL"; | 35 return L"BOOL"; |
(...skipping 21 matching lines...) Expand all Loading... |
58 << "Expected " << print_valuetype(expected) | 57 << "Expected " << print_valuetype(expected) |
59 << ", but was " << print_valuetype(actual->GetType()); | 58 << ", but was " << print_valuetype(actual->GetType()); |
60 } | 59 } |
61 | 60 |
62 bool ParseJSONDictionary(const std::string& json, DictionaryValue** dict, | 61 bool ParseJSONDictionary(const std::string& json, DictionaryValue** dict, |
63 std::string* error) { | 62 std::string* error) { |
64 int error_code = 0; | 63 int error_code = 0; |
65 Value* params = | 64 Value* params = |
66 base::JSONReader::ReadAndReturnError(json, true, &error_code, error); | 65 base::JSONReader::ReadAndReturnError(json, true, &error_code, error); |
67 if (error_code != 0) { | 66 if (error_code != 0) { |
68 LOG(INFO) << "Could not parse JSON object, " << *error << std::endl; | 67 VLOG(1) << "Could not parse JSON object, " << *error; |
69 if (params) { | 68 if (params) |
70 delete params; | 69 delete params; |
71 } | |
72 return false; | 70 return false; |
73 } | 71 } |
74 | 72 |
75 if (!params || params->GetType() != Value::TYPE_DICTIONARY) { | 73 if (!params || params->GetType() != Value::TYPE_DICTIONARY) { |
76 *error = "Data passed in URL must be of type dictionary."; | 74 *error = "Data passed in URL must be of type dictionary."; |
77 LOG(INFO) << "Invalid type to parse" << std::endl; | 75 VLOG(1) << "Invalid type to parse"; |
78 if (params) { | 76 if (params) |
79 delete params; | 77 delete params; |
80 } | |
81 return false; | 78 return false; |
82 } | 79 } |
83 | 80 |
84 *dict = static_cast<DictionaryValue*>(params); | 81 *dict = static_cast<DictionaryValue*>(params); |
85 return true; | 82 return true; |
86 } | 83 } |
87 | 84 |
88 } // namespace webdriver | 85 } // namespace webdriver |
89 | 86 |
OLD | NEW |