| 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 // Nothing more to do for callers that ignore the returned JS value. | 199 // Nothing more to do for callers that ignore the returned JS value. |
| 200 if (!result) | 200 if (!result) |
| 201 return true; | 201 return true; |
| 202 | 202 |
| 203 // Wrap |json| in an array before deserializing because valid JSON has an | 203 // Wrap |json| in an array before deserializing because valid JSON has an |
| 204 // array or an object as the root. | 204 // array or an object as the root. |
| 205 json.insert(0, "["); | 205 json.insert(0, "["); |
| 206 json.append("]"); | 206 json.append("]"); |
| 207 | 207 |
| 208 scoped_ptr<Value> root_val(base::JSONReader::Read(json, true)); | 208 scoped_ptr<Value> root_val(base::JSONReader::Read(json, true)); |
| 209 ListValue* list = root_val->AsList(); | 209 if (!root_val->IsType(Value::TYPE_LIST)) |
| 210 if (!list) | |
| 211 return false; | 210 return false; |
| 212 | 211 |
| 212 ListValue* list = static_cast<ListValue*>(root_val.get()); |
| 213 Value* result_val; | 213 Value* result_val; |
| 214 if (!list || !list->GetSize() || | 214 if (!list || !list->GetSize() || |
| 215 !list->Remove(0, &result_val)) // Remove gives us ownership of the value. | 215 !list->Remove(0, &result_val)) // Remove gives us ownership of the value. |
| 216 return false; | 216 return false; |
| 217 | 217 |
| 218 result->reset(result_val); | 218 result->reset(result_val); |
| 219 return true; | 219 return true; |
| 220 } | 220 } |
| 221 | 221 |
| 222 } // namespace | 222 } // namespace |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 L"window.domAutomationController.send(" | 918 L"window.domAutomationController.send(" |
| 919 L" JSON.stringify([document.width, document.height]))"; | 919 L" JSON.stringify([document.width, document.height]))"; |
| 920 std::string json; | 920 std::string json; |
| 921 if (!ui_test_utils::ExecuteJavaScriptAndExtractString( | 921 if (!ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 922 rvh, L"", script, &json)) | 922 rvh, L"", script, &json)) |
| 923 return false; | 923 return false; |
| 924 | 924 |
| 925 // Parse the JSON. | 925 // Parse the JSON. |
| 926 std::vector<int> dimensions; | 926 std::vector<int> dimensions; |
| 927 scoped_ptr<Value> value(base::JSONReader::Read(json, true)); | 927 scoped_ptr<Value> value(base::JSONReader::Read(json, true)); |
| 928 ListValue* list = value->AsList(); | 928 if (!value->IsType(Value::TYPE_LIST)) |
| 929 if (!list) | |
| 930 return false; | 929 return false; |
| 930 ListValue* list = static_cast<ListValue*>(value.get()); |
| 931 int width, height; | 931 int width, height; |
| 932 if (!list->GetInteger(0, &width) || !list->GetInteger(1, &height)) | 932 if (!list->GetInteger(0, &width) || !list->GetInteger(1, &height)) |
| 933 return false; | 933 return false; |
| 934 | 934 |
| 935 // Take the snapshot. | 935 // Take the snapshot. |
| 936 gfx::Size page_size(width, height); | 936 gfx::Size page_size(width, height); |
| 937 return TakeRenderWidgetSnapshot(rvh, page_size, page_size, bitmap); | 937 return TakeRenderWidgetSnapshot(rvh, page_size, page_size, bitmap); |
| 938 } | 938 } |
| 939 | 939 |
| 940 private: | 940 private: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 961 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); | 961 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); |
| 962 } | 962 } |
| 963 | 963 |
| 964 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { | 964 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { |
| 965 DCHECK(bitmap); | 965 DCHECK(bitmap); |
| 966 SnapshotTaker taker; | 966 SnapshotTaker taker; |
| 967 return taker.TakeEntirePageSnapshot(rvh, bitmap); | 967 return taker.TakeEntirePageSnapshot(rvh, bitmap); |
| 968 } | 968 } |
| 969 | 969 |
| 970 } // namespace ui_test_utils | 970 } // namespace ui_test_utils |
| OLD | NEW |