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 #include "chrome/test/base/ui_test_utils.h" | 5 #include "chrome/test/base/ui_test_utils.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 239 |
240 // Nothing more to do for callers that ignore the returned JS value. | 240 // Nothing more to do for callers that ignore the returned JS value. |
241 if (!result) | 241 if (!result) |
242 return true; | 242 return true; |
243 | 243 |
244 // Wrap |json| in an array before deserializing because valid JSON has an | 244 // Wrap |json| in an array before deserializing because valid JSON has an |
245 // array or an object as the root. | 245 // array or an object as the root. |
246 json.insert(0, "["); | 246 json.insert(0, "["); |
247 json.append("]"); | 247 json.append("]"); |
248 | 248 |
249 scoped_ptr<Value> root_val(base::JSONReader::Read(json, true)); | 249 scoped_ptr<Value> root_val( |
| 250 base::JSONReader::Read(json, base::JSON_ALLOW_TRAILING_COMMAS)); |
250 if (!root_val->IsType(Value::TYPE_LIST)) { | 251 if (!root_val->IsType(Value::TYPE_LIST)) { |
251 DLOG(ERROR) << "JSON result is not a list."; | 252 DLOG(ERROR) << "JSON result is not a list."; |
252 return false; | 253 return false; |
253 } | 254 } |
254 | 255 |
255 ListValue* list = static_cast<ListValue*>(root_val.get()); | 256 ListValue* list = static_cast<ListValue*>(root_val.get()); |
256 Value* result_val; | 257 Value* result_val; |
257 if (!list || !list->GetSize() || | 258 if (!list || !list->GetSize() || |
258 // Remove gives us ownership of the value. | 259 // Remove gives us ownership of the value. |
259 !list->Remove(0, &result_val)) { | 260 !list->Remove(0, &result_val)) { |
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 const wchar_t* script = | 1099 const wchar_t* script = |
1099 L"window.domAutomationController.send(" | 1100 L"window.domAutomationController.send(" |
1100 L" JSON.stringify([document.width, document.height]))"; | 1101 L" JSON.stringify([document.width, document.height]))"; |
1101 std::string json; | 1102 std::string json; |
1102 if (!ui_test_utils::ExecuteJavaScriptAndExtractString( | 1103 if (!ui_test_utils::ExecuteJavaScriptAndExtractString( |
1103 rvh, L"", script, &json)) | 1104 rvh, L"", script, &json)) |
1104 return false; | 1105 return false; |
1105 | 1106 |
1106 // Parse the JSON. | 1107 // Parse the JSON. |
1107 std::vector<int> dimensions; | 1108 std::vector<int> dimensions; |
1108 scoped_ptr<Value> value(base::JSONReader::Read(json, true)); | 1109 scoped_ptr<Value> value( |
| 1110 base::JSONReader::Read(json, base::JSON_ALLOW_TRAILING_COMMAS)); |
1109 if (!value->IsType(Value::TYPE_LIST)) | 1111 if (!value->IsType(Value::TYPE_LIST)) |
1110 return false; | 1112 return false; |
1111 ListValue* list = static_cast<ListValue*>(value.get()); | 1113 ListValue* list = static_cast<ListValue*>(value.get()); |
1112 int width, height; | 1114 int width, height; |
1113 if (!list->GetInteger(0, &width) || !list->GetInteger(1, &height)) | 1115 if (!list->GetInteger(0, &width) || !list->GetInteger(1, &height)) |
1114 return false; | 1116 return false; |
1115 | 1117 |
1116 // Take the snapshot. | 1118 // Take the snapshot. |
1117 gfx::Size page_size(width, height); | 1119 gfx::Size page_size(width, height); |
1118 return TakeRenderWidgetSnapshot(rvh, page_size, page_size, bitmap); | 1120 return TakeRenderWidgetSnapshot(rvh, page_size, page_size, bitmap); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1154 int state, | 1156 int state, |
1155 const base::Closure& followup) { | 1157 const base::Closure& followup) { |
1156 if (!followup.is_null()) | 1158 if (!followup.is_null()) |
1157 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); | 1159 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); |
1158 else | 1160 else |
1159 ui_controls::SendMouseEvents(button, state); | 1161 ui_controls::SendMouseEvents(button, state); |
1160 } | 1162 } |
1161 | 1163 |
1162 } // namespace internal | 1164 } // namespace internal |
1163 } // namespace ui_test_utils | 1165 } // namespace ui_test_utils |
OLD | NEW |