| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 // Nothing more to do for callers that ignore the returned JS value. | 260 // Nothing more to do for callers that ignore the returned JS value. |
| 261 if (!result) | 261 if (!result) |
| 262 return true; | 262 return true; |
| 263 | 263 |
| 264 // Wrap |json| in an array before deserializing because valid JSON has an | 264 // Wrap |json| in an array before deserializing because valid JSON has an |
| 265 // array or an object as the root. | 265 // array or an object as the root. |
| 266 json.insert(0, "["); | 266 json.insert(0, "["); |
| 267 json.append("]"); | 267 json.append("]"); |
| 268 | 268 |
| 269 scoped_ptr<Value> root_val(base::JSONReader::Read(json, true)); | 269 scoped_ptr<Value> root_val(base::JSONReader::Read(json, true)); |
| 270 if (!root_val->IsType(Value::TYPE_LIST)) | 270 if (!root_val->IsList()) |
| 271 return false; | 271 return false; |
| 272 | 272 |
| 273 ListValue* list = static_cast<ListValue*>(root_val.get()); | 273 ListValue* list = static_cast<ListValue*>(root_val.get()); |
| 274 Value* result_val; | 274 Value* result_val; |
| 275 if (!list || !list->GetSize() || | 275 if (!list || !list->GetSize() || |
| 276 !list->Remove(0, &result_val)) // Remove gives us ownership of the value. | 276 !list->Remove(0, &result_val)) // Remove gives us ownership of the value. |
| 277 return false; | 277 return false; |
| 278 | 278 |
| 279 result->reset(result_val); | 279 result->reset(result_val); |
| 280 return true; | 280 return true; |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 L"window.domAutomationController.send(" | 1009 L"window.domAutomationController.send(" |
| 1010 L" JSON.stringify([document.width, document.height]))"; | 1010 L" JSON.stringify([document.width, document.height]))"; |
| 1011 std::string json; | 1011 std::string json; |
| 1012 if (!ui_test_utils::ExecuteJavaScriptAndExtractString( | 1012 if (!ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 1013 rvh, L"", script, &json)) | 1013 rvh, L"", script, &json)) |
| 1014 return false; | 1014 return false; |
| 1015 | 1015 |
| 1016 // Parse the JSON. | 1016 // Parse the JSON. |
| 1017 std::vector<int> dimensions; | 1017 std::vector<int> dimensions; |
| 1018 scoped_ptr<Value> value(base::JSONReader::Read(json, true)); | 1018 scoped_ptr<Value> value(base::JSONReader::Read(json, true)); |
| 1019 if (!value->IsType(Value::TYPE_LIST)) | 1019 if (!value->IsList()) |
| 1020 return false; | 1020 return false; |
| 1021 ListValue* list = static_cast<ListValue*>(value.get()); | 1021 ListValue* list = static_cast<ListValue*>(value.get()); |
| 1022 int width, height; | 1022 int width, height; |
| 1023 if (!list->GetInteger(0, &width) || !list->GetInteger(1, &height)) | 1023 if (!list->GetInteger(0, &width) || !list->GetInteger(1, &height)) |
| 1024 return false; | 1024 return false; |
| 1025 | 1025 |
| 1026 // Take the snapshot. | 1026 // Take the snapshot. |
| 1027 gfx::Size page_size(width, height); | 1027 gfx::Size page_size(width, height); |
| 1028 return TakeRenderWidgetSnapshot(rvh, page_size, page_size, bitmap); | 1028 return TakeRenderWidgetSnapshot(rvh, page_size, page_size, bitmap); |
| 1029 } | 1029 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1052 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); | 1052 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); |
| 1053 } | 1053 } |
| 1054 | 1054 |
| 1055 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { | 1055 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { |
| 1056 DCHECK(bitmap); | 1056 DCHECK(bitmap); |
| 1057 SnapshotTaker taker; | 1057 SnapshotTaker taker; |
| 1058 return taker.TakeEntirePageSnapshot(rvh, bitmap); | 1058 return taker.TakeEntirePageSnapshot(rvh, bitmap); |
| 1059 } | 1059 } |
| 1060 | 1060 |
| 1061 } // namespace ui_test_utils | 1061 } // namespace ui_test_utils |
| OLD | NEW |