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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 std::string json; | 234 std::string json; |
235 if (!dom_op_observer.GetResponse(&json)) { | 235 if (!dom_op_observer.GetResponse(&json)) { |
236 DLOG(ERROR) << "Cannot communicate with DOMOperationObserver."; | 236 DLOG(ERROR) << "Cannot communicate with DOMOperationObserver."; |
237 return false; | 237 return false; |
238 } | 238 } |
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 base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS); |
245 // array or an object as the root. | 245 result->reset(reader.ReadToValue(json)); |
246 json.insert(0, "["); | 246 if (!result->get()) { |
247 json.append("]"); | 247 DLOG(ERROR) << reader.GetErrorMessage(); |
248 | |
249 scoped_ptr<Value> root_val( | |
250 base::JSONReader::Read(json, base::JSON_ALLOW_TRAILING_COMMAS)); | |
251 if (!root_val->IsType(Value::TYPE_LIST)) { | |
252 DLOG(ERROR) << "JSON result is not a list."; | |
253 return false; | 248 return false; |
254 } | 249 } |
255 | 250 |
256 ListValue* list = static_cast<ListValue*>(root_val.get()); | |
257 Value* result_val; | |
258 if (!list || !list->GetSize() || | |
259 // Remove gives us ownership of the value. | |
260 !list->Remove(0, &result_val)) { | |
261 DLOG(ERROR) << "JSON result list is empty."; | |
262 return false; | |
263 } | |
264 | |
265 result->reset(result_val); | |
266 return true; | 251 return true; |
267 } | 252 } |
268 | 253 |
269 void RunAllPendingMessageAndSendQuit(content::BrowserThread::ID thread_id) { | 254 void RunAllPendingMessageAndSendQuit(content::BrowserThread::ID thread_id) { |
270 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 255 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
271 RunMessageLoop(); | 256 RunMessageLoop(); |
272 content::BrowserThread::PostTask(thread_id, FROM_HERE, | 257 content::BrowserThread::PostTask(thread_id, FROM_HERE, |
273 MessageLoop::QuitClosure()); | 258 MessageLoop::QuitClosure()); |
274 } | 259 } |
275 | 260 |
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 int state, | 1166 int state, |
1182 const base::Closure& followup) { | 1167 const base::Closure& followup) { |
1183 if (!followup.is_null()) | 1168 if (!followup.is_null()) |
1184 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); | 1169 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); |
1185 else | 1170 else |
1186 ui_controls::SendMouseEvents(button, state); | 1171 ui_controls::SendMouseEvents(button, state); |
1187 } | 1172 } |
1188 | 1173 |
1189 } // namespace internal | 1174 } // namespace internal |
1190 } // namespace ui_test_utils | 1175 } // namespace ui_test_utils |
OLD | NEW |