Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: content/shell/renderer/webkit_test_runner.cc

Issue 595943002: WebTestInterfaces class to chromium c++ style. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: resolved comments Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/shell/renderer/test_runner/web_test_proxy.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/shell/renderer/webkit_test_runner.h" 5 #include "content/shell/renderer/webkit_test_runner.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <clocale> 8 #include <clocale>
9 #include <cmath> 9 #include <cmath>
10 10
(...skipping 16 matching lines...) Expand all
27 #include "content/public/renderer/render_view.h" 27 #include "content/public/renderer/render_view.h"
28 #include "content/public/renderer/render_view_visitor.h" 28 #include "content/public/renderer/render_view_visitor.h"
29 #include "content/public/renderer/renderer_gamepad_provider.h" 29 #include "content/public/renderer/renderer_gamepad_provider.h"
30 #include "content/public/test/layouttest_support.h" 30 #include "content/public/test/layouttest_support.h"
31 #include "content/shell/common/shell_messages.h" 31 #include "content/shell/common/shell_messages.h"
32 #include "content/shell/common/shell_switches.h" 32 #include "content/shell/common/shell_switches.h"
33 #include "content/shell/common/webkit_test_helpers.h" 33 #include "content/shell/common/webkit_test_helpers.h"
34 #include "content/shell/renderer/gc_controller.h" 34 #include "content/shell/renderer/gc_controller.h"
35 #include "content/shell/renderer/leak_detector.h" 35 #include "content/shell/renderer/leak_detector.h"
36 #include "content/shell/renderer/shell_render_process_observer.h" 36 #include "content/shell/renderer/shell_render_process_observer.h"
37 #include "content/shell/renderer/test_runner/WebTestInterfaces.h"
38 #include "content/shell/renderer/test_runner/mock_screen_orientation_client.h" 37 #include "content/shell/renderer/test_runner/mock_screen_orientation_client.h"
39 #include "content/shell/renderer/test_runner/web_task.h" 38 #include "content/shell/renderer/test_runner/web_task.h"
39 #include "content/shell/renderer/test_runner/web_test_interfaces.h"
40 #include "content/shell/renderer/test_runner/web_test_proxy.h" 40 #include "content/shell/renderer/test_runner/web_test_proxy.h"
41 #include "content/shell/renderer/test_runner/web_test_runner.h" 41 #include "content/shell/renderer/test_runner/web_test_runner.h"
42 #include "net/base/filename_util.h" 42 #include "net/base/filename_util.h"
43 #include "net/base/net_errors.h" 43 #include "net/base/net_errors.h"
44 #include "skia/ext/platform_canvas.h" 44 #include "skia/ext/platform_canvas.h"
45 #include "third_party/WebKit/public/platform/Platform.h" 45 #include "third_party/WebKit/public/platform/Platform.h"
46 #include "third_party/WebKit/public/platform/WebCString.h" 46 #include "third_party/WebKit/public/platform/WebCString.h"
47 #include "third_party/WebKit/public/platform/WebPoint.h" 47 #include "third_party/WebKit/public/platform/WebPoint.h"
48 #include "third_party/WebKit/public/platform/WebRect.h" 48 #include "third_party/WebKit/public/platform/WebRect.h"
49 #include "third_party/WebKit/public/platform/WebSize.h" 49 #include "third_party/WebKit/public/platform/WebSize.h"
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 setlocale(LC_ALL, locale.c_str()); 493 setlocale(LC_ALL, locale.c_str());
494 } 494 }
495 495
496 void WebKitTestRunner::TestFinished() { 496 void WebKitTestRunner::TestFinished() {
497 if (!is_main_window_) { 497 if (!is_main_window_) {
498 Send(new ShellViewHostMsg_TestFinishedInSecondaryWindow(routing_id())); 498 Send(new ShellViewHostMsg_TestFinishedInSecondaryWindow(routing_id()));
499 return; 499 return;
500 } 500 }
501 WebTestInterfaces* interfaces = 501 WebTestInterfaces* interfaces =
502 ShellRenderProcessObserver::GetInstance()->test_interfaces(); 502 ShellRenderProcessObserver::GetInstance()->test_interfaces();
503 interfaces->setTestIsRunning(false); 503 interfaces->SetTestIsRunning(false);
504 if (interfaces->testRunner()->ShouldDumpBackForwardList()) { 504 if (interfaces->TestRunner()->ShouldDumpBackForwardList()) {
505 SyncNavigationStateVisitor visitor; 505 SyncNavigationStateVisitor visitor;
506 RenderView::ForEach(&visitor); 506 RenderView::ForEach(&visitor);
507 Send(new ShellViewHostMsg_CaptureSessionHistory(routing_id())); 507 Send(new ShellViewHostMsg_CaptureSessionHistory(routing_id()));
508 } else { 508 } else {
509 CaptureDump(); 509 CaptureDump();
510 } 510 }
511 } 511 }
512 512
513 void WebKitTestRunner::CloseRemainingWindows() { 513 void WebKitTestRunner::CloseRemainingWindows() {
514 NavigateAwayVisitor visitor(render_view()); 514 NavigateAwayVisitor visitor(render_view());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 return std::string(); 560 return std::string();
561 } 561 }
562 return DumpBackForwardList(session_histories_[pos], 562 return DumpBackForwardList(session_histories_[pos],
563 current_entry_indexes_[pos]); 563 current_entry_indexes_[pos]);
564 } 564 }
565 565
566 // RenderViewObserver -------------------------------------------------------- 566 // RenderViewObserver --------------------------------------------------------
567 567
568 void WebKitTestRunner::DidClearWindowObject(WebLocalFrame* frame) { 568 void WebKitTestRunner::DidClearWindowObject(WebLocalFrame* frame) {
569 WebTestingSupport::injectInternalsObject(frame); 569 WebTestingSupport::injectInternalsObject(frame);
570 ShellRenderProcessObserver::GetInstance()->test_interfaces()->bindTo(frame); 570 ShellRenderProcessObserver::GetInstance()->test_interfaces()->BindTo(frame);
571 GCController::Install(frame); 571 GCController::Install(frame);
572 } 572 }
573 573
574 bool WebKitTestRunner::OnMessageReceived(const IPC::Message& message) { 574 bool WebKitTestRunner::OnMessageReceived(const IPC::Message& message) {
575 bool handled = true; 575 bool handled = true;
576 IPC_BEGIN_MESSAGE_MAP(WebKitTestRunner, message) 576 IPC_BEGIN_MESSAGE_MAP(WebKitTestRunner, message)
577 IPC_MESSAGE_HANDLER(ShellViewMsg_SetTestConfiguration, 577 IPC_MESSAGE_HANDLER(ShellViewMsg_SetTestConfiguration,
578 OnSetTestConfiguration) 578 OnSetTestConfiguration)
579 IPC_MESSAGE_HANDLER(ShellViewMsg_SessionHistory, OnSessionHistory) 579 IPC_MESSAGE_HANDLER(ShellViewMsg_SessionHistory, OnSessionHistory)
580 IPC_MESSAGE_HANDLER(ShellViewMsg_Reset, OnReset) 580 IPC_MESSAGE_HANDLER(ShellViewMsg_Reset, OnReset)
581 IPC_MESSAGE_HANDLER(ShellViewMsg_NotifyDone, OnNotifyDone) 581 IPC_MESSAGE_HANDLER(ShellViewMsg_NotifyDone, OnNotifyDone)
582 IPC_MESSAGE_HANDLER(ShellViewMsg_TryLeakDetection, OnTryLeakDetection) 582 IPC_MESSAGE_HANDLER(ShellViewMsg_TryLeakDetection, OnTryLeakDetection)
583 IPC_MESSAGE_UNHANDLED(handled = false) 583 IPC_MESSAGE_UNHANDLED(handled = false)
584 IPC_END_MESSAGE_MAP() 584 IPC_END_MESSAGE_MAP()
585 585
586 return handled; 586 return handled;
587 } 587 }
588 588
589 void WebKitTestRunner::Navigate(const GURL& url) { 589 void WebKitTestRunner::Navigate(const GURL& url) {
590 focus_on_next_commit_ = true; 590 focus_on_next_commit_ = true;
591 if (!is_main_window_ && 591 if (!is_main_window_ &&
592 ShellRenderProcessObserver::GetInstance()->main_test_runner() == this) { 592 ShellRenderProcessObserver::GetInstance()->main_test_runner() == this) {
593 WebTestInterfaces* interfaces = 593 WebTestInterfaces* interfaces =
594 ShellRenderProcessObserver::GetInstance()->test_interfaces(); 594 ShellRenderProcessObserver::GetInstance()->test_interfaces();
595 interfaces->setTestIsRunning(true); 595 interfaces->SetTestIsRunning(true);
596 interfaces->configureForTestWithURL(GURL(), false); 596 interfaces->ConfigureForTestWithURL(GURL(), false);
597 ForceResizeRenderView(render_view(), WebSize(800, 600)); 597 ForceResizeRenderView(render_view(), WebSize(800, 600));
598 } 598 }
599 } 599 }
600 600
601 void WebKitTestRunner::DidCommitProvisionalLoad(WebLocalFrame* frame, 601 void WebKitTestRunner::DidCommitProvisionalLoad(WebLocalFrame* frame,
602 bool is_new_navigation) { 602 bool is_new_navigation) {
603 if (!focus_on_next_commit_) 603 if (!focus_on_next_commit_)
604 return; 604 return;
605 focus_on_next_commit_ = false; 605 focus_on_next_commit_ = false;
606 render_view()->GetWebView()->setFocusedFrame(frame); 606 render_view()->GetWebView()->setFocusedFrame(frame);
(...skipping 28 matching lines...) Expand all
635 render_view()->SetWebkitPreferences(render_view()->GetWebkitPreferences()); 635 render_view()->SetWebkitPreferences(render_view()->GetWebkitPreferences());
636 } 636 }
637 637
638 // Private methods ----------------------------------------------------------- 638 // Private methods -----------------------------------------------------------
639 639
640 void WebKitTestRunner::CaptureDump() { 640 void WebKitTestRunner::CaptureDump() {
641 WebTestInterfaces* interfaces = 641 WebTestInterfaces* interfaces =
642 ShellRenderProcessObserver::GetInstance()->test_interfaces(); 642 ShellRenderProcessObserver::GetInstance()->test_interfaces();
643 TRACE_EVENT0("shell", "WebKitTestRunner::CaptureDump"); 643 TRACE_EVENT0("shell", "WebKitTestRunner::CaptureDump");
644 644
645 if (interfaces->testRunner()->ShouldDumpAsAudio()) { 645 if (interfaces->TestRunner()->ShouldDumpAsAudio()) {
646 std::vector<unsigned char> vector_data; 646 std::vector<unsigned char> vector_data;
647 interfaces->testRunner()->GetAudioData(&vector_data); 647 interfaces->TestRunner()->GetAudioData(&vector_data);
648 Send(new ShellViewHostMsg_AudioDump(routing_id(), vector_data)); 648 Send(new ShellViewHostMsg_AudioDump(routing_id(), vector_data));
649 } else { 649 } else {
650 Send(new ShellViewHostMsg_TextDump(routing_id(), 650 Send(new ShellViewHostMsg_TextDump(routing_id(),
651 proxy()->CaptureTree(false))); 651 proxy()->CaptureTree(false)));
652 652
653 if (test_config_.enable_pixel_dumping && 653 if (test_config_.enable_pixel_dumping &&
654 interfaces->testRunner()->ShouldGeneratePixelResults()) { 654 interfaces->TestRunner()->ShouldGeneratePixelResults()) {
655 CHECK(render_view()->GetWebView()->isAcceleratedCompositingActive()); 655 CHECK(render_view()->GetWebView()->isAcceleratedCompositingActive());
656 proxy()->CapturePixelsAsync(base::Bind( 656 proxy()->CapturePixelsAsync(base::Bind(
657 &WebKitTestRunner::CaptureDumpPixels, base::Unretained(this))); 657 &WebKitTestRunner::CaptureDumpPixels, base::Unretained(this)));
658 return; 658 return;
659 } 659 }
660 } 660 }
661 661
662 CaptureDumpComplete(); 662 CaptureDumpComplete();
663 } 663 }
664 664
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 test_config_ = params; 702 test_config_ = params;
703 is_main_window_ = true; 703 is_main_window_ = true;
704 704
705 ForceResizeRenderView( 705 ForceResizeRenderView(
706 render_view(), 706 render_view(),
707 WebSize(params.initial_size.width(), params.initial_size.height())); 707 WebSize(params.initial_size.width(), params.initial_size.height()));
708 SetFocus(proxy_, true); 708 SetFocus(proxy_, true);
709 709
710 WebTestInterfaces* interfaces = 710 WebTestInterfaces* interfaces =
711 ShellRenderProcessObserver::GetInstance()->test_interfaces(); 711 ShellRenderProcessObserver::GetInstance()->test_interfaces();
712 interfaces->setTestIsRunning(true); 712 interfaces->SetTestIsRunning(true);
713 interfaces->configureForTestWithURL(params.test_url, 713 interfaces->ConfigureForTestWithURL(params.test_url,
714 params.enable_pixel_dumping); 714 params.enable_pixel_dumping);
715 } 715 }
716 716
717 void WebKitTestRunner::OnSessionHistory( 717 void WebKitTestRunner::OnSessionHistory(
718 const std::vector<int>& routing_ids, 718 const std::vector<int>& routing_ids,
719 const std::vector<std::vector<PageState> >& session_histories, 719 const std::vector<std::vector<PageState> >& session_histories,
720 const std::vector<unsigned>& current_entry_indexes) { 720 const std::vector<unsigned>& current_entry_indexes) {
721 routing_ids_ = routing_ids; 721 routing_ids_ = routing_ids;
722 session_histories_ = session_histories; 722 session_histories_ = session_histories;
723 current_entry_indexes_ = current_entry_indexes; 723 current_entry_indexes_ = current_entry_indexes;
724 CaptureDump(); 724 CaptureDump();
725 } 725 }
726 726
727 void WebKitTestRunner::OnReset() { 727 void WebKitTestRunner::OnReset() {
728 ShellRenderProcessObserver::GetInstance()->test_interfaces()->resetAll(); 728 ShellRenderProcessObserver::GetInstance()->test_interfaces()->ResetAll();
729 Reset(); 729 Reset();
730 // Navigating to about:blank will make sure that no new loads are initiated 730 // Navigating to about:blank will make sure that no new loads are initiated
731 // by the renderer. 731 // by the renderer.
732 render_view()->GetWebView()->mainFrame()->loadRequest( 732 render_view()->GetWebView()->mainFrame()->loadRequest(
733 WebURLRequest(GURL(url::kAboutBlankURL))); 733 WebURLRequest(GURL(url::kAboutBlankURL)));
734 Send(new ShellViewHostMsg_ResetDone(routing_id())); 734 Send(new ShellViewHostMsg_ResetDone(routing_id()));
735 } 735 }
736 736
737 void WebKitTestRunner::OnNotifyDone() { 737 void WebKitTestRunner::OnNotifyDone() {
738 render_view()->GetWebView()->mainFrame()->executeScript( 738 render_view()->GetWebView()->mainFrame()->executeScript(
739 WebScriptSource(WebString::fromUTF8("testRunner.notifyDone();"))); 739 WebScriptSource(WebString::fromUTF8("testRunner.notifyDone();")));
740 } 740 }
741 741
742 void WebKitTestRunner::OnTryLeakDetection() { 742 void WebKitTestRunner::OnTryLeakDetection() {
743 WebLocalFrame* main_frame = 743 WebLocalFrame* main_frame =
744 render_view()->GetWebView()->mainFrame()->toWebLocalFrame(); 744 render_view()->GetWebView()->mainFrame()->toWebLocalFrame();
745 DCHECK_EQ(GURL(url::kAboutBlankURL), GURL(main_frame->document().url())); 745 DCHECK_EQ(GURL(url::kAboutBlankURL), GURL(main_frame->document().url()));
746 DCHECK(!main_frame->isLoading()); 746 DCHECK(!main_frame->isLoading());
747 747
748 leak_detector_->TryLeakDetection(main_frame); 748 leak_detector_->TryLeakDetection(main_frame);
749 } 749 }
750 750
751 void WebKitTestRunner::ReportLeakDetectionResult( 751 void WebKitTestRunner::ReportLeakDetectionResult(
752 const LeakDetectionResult& report) { 752 const LeakDetectionResult& report) {
753 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report)); 753 Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report));
754 } 754 }
755 755
756 } // namespace content 756 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/renderer/test_runner/web_test_proxy.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698