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/browser_test_utils.h" | 5 #include "content/public/test/browser_test_utils.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 modifiers &= ~blink::WebInputEvent::MetaKey; | 533 modifiers &= ~blink::WebInputEvent::MetaKey; |
534 InjectRawKeyEvent( | 534 InjectRawKeyEvent( |
535 web_contents, blink::WebInputEvent::KeyUp, ui::VKEY_COMMAND, | 535 web_contents, blink::WebInputEvent::KeyUp, ui::VKEY_COMMAND, |
536 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::OS_LEFT), | 536 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::OS_LEFT), |
537 modifiers); | 537 modifiers); |
538 } | 538 } |
539 | 539 |
540 ASSERT_EQ(modifiers, 0); | 540 ASSERT_EQ(modifiers, 0); |
541 } | 541 } |
542 | 542 |
543 namespace internal { | |
544 | |
545 ToRenderFrameHost::ToRenderFrameHost(WebContents* web_contents) | 543 ToRenderFrameHost::ToRenderFrameHost(WebContents* web_contents) |
546 : render_frame_host_(web_contents->GetMainFrame()) { | 544 : render_frame_host_(web_contents->GetMainFrame()) { |
547 } | 545 } |
548 | 546 |
549 ToRenderFrameHost::ToRenderFrameHost(RenderViewHost* render_view_host) | 547 ToRenderFrameHost::ToRenderFrameHost(RenderViewHost* render_view_host) |
550 : render_frame_host_(render_view_host->GetMainFrame()) { | 548 : render_frame_host_(render_view_host->GetMainFrame()) { |
551 } | 549 } |
552 | 550 |
553 ToRenderFrameHost::ToRenderFrameHost(RenderFrameHost* render_frame_host) | 551 ToRenderFrameHost::ToRenderFrameHost(RenderFrameHost* render_frame_host) |
554 : render_frame_host_(render_frame_host) { | 552 : render_frame_host_(render_frame_host) { |
555 } | 553 } |
556 | 554 |
557 } // namespace internal | 555 bool ExecuteScript(const ToRenderFrameHost& adapter, |
558 | |
559 bool ExecuteScript(const internal::ToRenderFrameHost& adapter, | |
560 const std::string& script) { | 556 const std::string& script) { |
561 std::string new_script = | 557 std::string new_script = |
562 script + ";window.domAutomationController.send(0);"; | 558 script + ";window.domAutomationController.send(0);"; |
563 return ExecuteScriptHelper(adapter.render_frame_host(), new_script, NULL); | 559 return ExecuteScriptHelper(adapter.render_frame_host(), new_script, NULL); |
564 } | 560 } |
565 | 561 |
566 bool ExecuteScriptAndExtractInt(const internal::ToRenderFrameHost& adapter, | 562 bool ExecuteScriptAndExtractInt(const ToRenderFrameHost& adapter, |
567 const std::string& script, int* result) { | 563 const std::string& script, int* result) { |
568 DCHECK(result); | 564 DCHECK(result); |
569 scoped_ptr<base::Value> value; | 565 scoped_ptr<base::Value> value; |
570 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || | 566 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || |
571 !value.get()) { | 567 !value.get()) { |
572 return false; | 568 return false; |
573 } | 569 } |
574 | 570 |
575 return value->GetAsInteger(result); | 571 return value->GetAsInteger(result); |
576 } | 572 } |
577 | 573 |
578 bool ExecuteScriptAndExtractBool(const internal::ToRenderFrameHost& adapter, | 574 bool ExecuteScriptAndExtractBool(const ToRenderFrameHost& adapter, |
579 const std::string& script, bool* result) { | 575 const std::string& script, bool* result) { |
580 DCHECK(result); | 576 DCHECK(result); |
581 scoped_ptr<base::Value> value; | 577 scoped_ptr<base::Value> value; |
582 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || | 578 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || |
583 !value.get()) { | 579 !value.get()) { |
584 return false; | 580 return false; |
585 } | 581 } |
586 | 582 |
587 return value->GetAsBoolean(result); | 583 return value->GetAsBoolean(result); |
588 } | 584 } |
589 | 585 |
590 bool ExecuteScriptAndExtractString(const internal::ToRenderFrameHost& adapter, | 586 bool ExecuteScriptAndExtractString(const ToRenderFrameHost& adapter, |
591 const std::string& script, | 587 const std::string& script, |
592 std::string* result) { | 588 std::string* result) { |
593 DCHECK(result); | 589 DCHECK(result); |
594 scoped_ptr<base::Value> value; | 590 scoped_ptr<base::Value> value; |
595 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || | 591 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, &value) || |
596 !value.get()) { | 592 !value.get()) { |
597 return false; | 593 return false; |
598 } | 594 } |
599 | 595 |
600 return value->GetAsString(result); | 596 return value->GetAsString(result); |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 void FrameWatcher::WaitFrames(int frames_to_wait) { | 1003 void FrameWatcher::WaitFrames(int frames_to_wait) { |
1008 if (frames_to_wait <= 0) | 1004 if (frames_to_wait <= 0) |
1009 return; | 1005 return; |
1010 base::RunLoop run_loop; | 1006 base::RunLoop run_loop; |
1011 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); | 1007 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); |
1012 base::AutoReset<int> reset_frames_to_wait(&frames_to_wait_, frames_to_wait); | 1008 base::AutoReset<int> reset_frames_to_wait(&frames_to_wait_, frames_to_wait); |
1013 run_loop.Run(); | 1009 run_loop.Run(); |
1014 } | 1010 } |
1015 | 1011 |
1016 } // namespace content | 1012 } // namespace content |
OLD | NEW |