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 "content/public/test/render_view_test.h" | 5 #include "content/public/test/render_view_test.h" |
6 | 6 |
7 #include <cctype> | 7 #include <cctype> |
8 | 8 |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "components/scheduler/renderer/renderer_scheduler.h" | 10 #include "components/scheduler/renderer/renderer_scheduler.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 136 } |
137 | 137 |
138 void RenderViewTest::ExecuteJavaScript(const char* js) { | 138 void RenderViewTest::ExecuteJavaScript(const char* js) { |
139 GetMainFrame()->executeScript(WebScriptSource(WebString::fromUTF8(js))); | 139 GetMainFrame()->executeScript(WebScriptSource(WebString::fromUTF8(js))); |
140 } | 140 } |
141 | 141 |
142 bool RenderViewTest::ExecuteJavaScriptAndReturnIntValue( | 142 bool RenderViewTest::ExecuteJavaScriptAndReturnIntValue( |
143 const base::string16& script, | 143 const base::string16& script, |
144 int* int_result) { | 144 int* int_result) { |
145 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 145 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
146 v8::Handle<v8::Value> result = | 146 v8::Local<v8::Value> result = |
147 GetMainFrame()->executeScriptAndReturnValue(WebScriptSource(script)); | 147 GetMainFrame()->executeScriptAndReturnValue(WebScriptSource(script)); |
148 if (result.IsEmpty() || !result->IsInt32()) | 148 if (result.IsEmpty() || !result->IsInt32()) |
149 return false; | 149 return false; |
150 | 150 |
151 if (int_result) | 151 if (int_result) |
152 *int_result = result->Int32Value(); | 152 *int_result = result->Int32Value(); |
153 | 153 |
154 return true; | 154 return true; |
155 } | 155 } |
156 | 156 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 " return bounds;" | 328 " return bounds;" |
329 "})();"; | 329 "})();"; |
330 gfx::Rect RenderViewTest::GetElementBounds(const std::string& element_id) { | 330 gfx::Rect RenderViewTest::GetElementBounds(const std::string& element_id) { |
331 std::vector<std::string> params; | 331 std::vector<std::string> params; |
332 params.push_back(element_id); | 332 params.push_back(element_id); |
333 std::string script = | 333 std::string script = |
334 ReplaceStringPlaceholders(kGetCoordinatesScript, params, NULL); | 334 ReplaceStringPlaceholders(kGetCoordinatesScript, params, NULL); |
335 | 335 |
336 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 336 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
337 v8::HandleScope handle_scope(isolate); | 337 v8::HandleScope handle_scope(isolate); |
338 v8::Handle<v8::Value> value = GetMainFrame()->executeScriptAndReturnValue( | 338 v8::Local<v8::Value> value = GetMainFrame()->executeScriptAndReturnValue( |
339 WebScriptSource(WebString::fromUTF8(script))); | 339 WebScriptSource(WebString::fromUTF8(script))); |
340 if (value.IsEmpty() || !value->IsArray()) | 340 if (value.IsEmpty() || !value->IsArray()) |
341 return gfx::Rect(); | 341 return gfx::Rect(); |
342 | 342 |
343 v8::Handle<v8::Array> array = value.As<v8::Array>(); | 343 v8::Local<v8::Array> array = value.As<v8::Array>(); |
344 if (array->Length() != 4) | 344 if (array->Length() != 4) |
345 return gfx::Rect(); | 345 return gfx::Rect(); |
346 std::vector<int> coords; | 346 std::vector<int> coords; |
347 for (int i = 0; i < 4; ++i) { | 347 for (int i = 0; i < 4; ++i) { |
348 v8::Handle<v8::Number> index = v8::Number::New(isolate, i); | 348 v8::Local<v8::Number> index = v8::Number::New(isolate, i); |
349 v8::Local<v8::Value> value = array->Get(index); | 349 v8::Local<v8::Value> value = array->Get(index); |
350 if (value.IsEmpty() || !value->IsInt32()) | 350 if (value.IsEmpty() || !value->IsInt32()) |
351 return gfx::Rect(); | 351 return gfx::Rect(); |
352 coords.push_back(value->Int32Value()); | 352 coords.push_back(value->Int32Value()); |
353 } | 353 } |
354 return gfx::Rect(coords[0], coords[1], coords[2], coords[3]); | 354 return gfx::Rect(coords[0], coords[1], coords[2], coords[3]); |
355 } | 355 } |
356 | 356 |
357 bool RenderViewTest::SimulateElementClick(const std::string& element_id) { | 357 bool RenderViewTest::SimulateElementClick(const std::string& element_id) { |
358 gfx::Rect bounds = GetElementBounds(element_id); | 358 gfx::Rect bounds = GetElementBounds(element_id); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 | 540 |
541 impl->GetMainRenderFrame()->OnNavigate(common_params, StartNavigationParams(), | 541 impl->GetMainRenderFrame()->OnNavigate(common_params, StartNavigationParams(), |
542 request_params); | 542 request_params); |
543 | 543 |
544 // The load actually happens asynchronously, so we pump messages to process | 544 // The load actually happens asynchronously, so we pump messages to process |
545 // the pending continuation. | 545 // the pending continuation. |
546 FrameLoadWaiter(view_->GetMainRenderFrame()).Wait(); | 546 FrameLoadWaiter(view_->GetMainRenderFrame()).Wait(); |
547 } | 547 } |
548 | 548 |
549 } // namespace content | 549 } // namespace content |
OLD | NEW |