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

Side by Side Diff: content/shell/browser/layout_test/blink_test_controller.cc

Issue 1750063002: Replicate static layout test configuration to all renderers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no-test-finished-in-secondary-frames-please
Patch Set: Rebasing... Created 4 years, 9 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/browser/layout_test/blink_test_controller.h" 5 #include "content/shell/browser/layout_test/blink_test_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <iostream> 9 #include <iostream>
10 #include <utility> 10 #include <utility>
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 const GURL& test_url, 258 const GURL& test_url,
259 const base::FilePath& current_working_directory, 259 const base::FilePath& current_working_directory,
260 bool enable_pixel_dumping, 260 bool enable_pixel_dumping,
261 const std::string& expected_pixel_hash) { 261 const std::string& expected_pixel_hash) {
262 DCHECK(CalledOnValidThread()); 262 DCHECK(CalledOnValidThread());
263 test_phase_ = DURING_TEST; 263 test_phase_ = DURING_TEST;
264 current_working_directory_ = current_working_directory; 264 current_working_directory_ = current_working_directory;
265 enable_pixel_dumping_ = enable_pixel_dumping; 265 enable_pixel_dumping_ = enable_pixel_dumping;
266 expected_pixel_hash_ = expected_pixel_hash; 266 expected_pixel_hash_ = expected_pixel_hash;
267 test_url_ = test_url; 267 test_url_ = test_url;
268 did_send_initial_test_configuration_ = false;
268 printer_->reset(); 269 printer_->reset();
269 frame_to_layout_dump_map_.clear(); 270 frame_to_layout_dump_map_.clear();
271 render_process_host_observer_.RemoveAll();
270 ShellBrowserContext* browser_context = 272 ShellBrowserContext* browser_context =
271 ShellContentBrowserClient::Get()->browser_context(); 273 ShellContentBrowserClient::Get()->browser_context();
272 if (test_url.spec().find("compositing/") != std::string::npos) 274 if (test_url.spec().find("compositing/") != std::string::npos)
273 is_compositing_test_ = true; 275 is_compositing_test_ = true;
274 initial_size_ = Shell::GetShellDefaultSize(); 276 initial_size_ = Shell::GetShellDefaultSize();
275 // The W3C SVG layout tests use a different size than the other layout tests. 277 // The W3C SVG layout tests use a different size than the other layout tests.
276 if (test_url.spec().find("W3C-SVG-1.1") != std::string::npos) 278 if (test_url.spec().find("W3C-SVG-1.1") != std::string::npos)
277 initial_size_ = gfx::Size(kTestSVGWindowWidthDip, kTestSVGWindowHeightDip); 279 initial_size_ = gfx::Size(kTestSVGWindowWidthDip, kTestSVGWindowHeightDip);
278 if (!main_window_) { 280 if (!main_window_) {
279 main_window_ = content::Shell::CreateNewWindow( 281 main_window_ = content::Shell::CreateNewWindow(
280 browser_context, 282 browser_context,
281 GURL(), 283 GURL(),
282 NULL, 284 NULL,
283 initial_size_); 285 initial_size_);
284 WebContentsObserver::Observe(main_window_->web_contents()); 286 WebContentsObserver::Observe(main_window_->web_contents());
285 send_configuration_to_next_host_ = true;
286 current_pid_ = base::kNullProcessId; 287 current_pid_ = base::kNullProcessId;
287 main_window_->LoadURL(test_url); 288 main_window_->LoadURL(test_url);
288 } else { 289 } else {
289 #if defined(OS_MACOSX) 290 #if defined(OS_MACOSX)
290 // Shell::SizeTo is not implemented on all platforms. 291 // Shell::SizeTo is not implemented on all platforms.
291 main_window_->SizeTo(initial_size_); 292 main_window_->SizeTo(initial_size_);
292 #endif 293 #endif
293 main_window_->web_contents() 294 main_window_->web_contents()
294 ->GetRenderViewHost() 295 ->GetRenderViewHost()
295 ->GetWidget() 296 ->GetWidget()
296 ->GetView() 297 ->GetView()
297 ->SetSize(initial_size_); 298 ->SetSize(initial_size_);
298 main_window_->web_contents() 299 main_window_->web_contents()
299 ->GetRenderViewHost() 300 ->GetRenderViewHost()
300 ->GetWidget() 301 ->GetWidget()
301 ->WasResized(); 302 ->WasResized();
302 RenderViewHost* render_view_host = 303 RenderViewHost* render_view_host =
303 main_window_->web_contents()->GetRenderViewHost(); 304 main_window_->web_contents()->GetRenderViewHost();
304 WebPreferences prefs = render_view_host->GetWebkitPreferences(); 305 WebPreferences prefs = render_view_host->GetWebkitPreferences();
305 OverrideWebkitPrefs(&prefs); 306 OverrideWebkitPrefs(&prefs);
306 render_view_host->UpdateWebkitPreferences(prefs); 307 render_view_host->UpdateWebkitPreferences(prefs);
307 SendTestConfiguration(); 308 HandleNewRenderFrameHost(render_view_host->GetMainFrame());
308 309
309 NavigationController::LoadURLParams params(test_url); 310 NavigationController::LoadURLParams params(test_url);
310 params.transition_type = ui::PageTransitionFromInt( 311 params.transition_type = ui::PageTransitionFromInt(
311 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); 312 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
312 params.should_clear_history_list = true; 313 params.should_clear_history_list = true;
313 main_window_->web_contents()->GetController().LoadURLWithParams(params); 314 main_window_->web_contents()->GetController().LoadURLWithParams(params);
314 main_window_->web_contents()->Focus(); 315 main_window_->web_contents()->Focus();
315 } 316 }
316 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->SetActive( 317 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->SetActive(
317 true); 318 true);
318 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus(); 319 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus();
319 return true; 320 return true;
320 } 321 }
321 322
322 bool BlinkTestController::ResetAfterLayoutTest() { 323 bool BlinkTestController::ResetAfterLayoutTest() {
323 DCHECK(CalledOnValidThread()); 324 DCHECK(CalledOnValidThread());
324 printer_->PrintTextFooter(); 325 printer_->PrintTextFooter();
325 printer_->PrintImageFooter(); 326 printer_->PrintImageFooter();
326 printer_->CloseStderr(); 327 printer_->CloseStderr();
327 send_configuration_to_next_host_ = false; 328 did_send_initial_test_configuration_ = false;
328 test_phase_ = BETWEEN_TESTS; 329 test_phase_ = BETWEEN_TESTS;
329 is_compositing_test_ = false; 330 is_compositing_test_ = false;
330 enable_pixel_dumping_ = false; 331 enable_pixel_dumping_ = false;
331 expected_pixel_hash_.clear(); 332 expected_pixel_hash_.clear();
332 test_url_ = GURL(); 333 test_url_ = GURL();
333 prefs_ = WebPreferences(); 334 prefs_ = WebPreferences();
334 should_override_prefs_ = false; 335 should_override_prefs_ = false;
335 336
336 #if defined(OS_ANDROID) 337 #if defined(OS_ANDROID)
337 // Re-using the shell's main window on Android causes issues with networking 338 // Re-using the shell's main window on Android causes issues with networking
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 base::StringPrintf("#CRASHED - plugin (pid %d)", plugin_pid)); 454 base::StringPrintf("#CRASHED - plugin (pid %d)", plugin_pid));
454 base::ThreadTaskRunnerHandle::Get()->PostTask( 455 base::ThreadTaskRunnerHandle::Get()->PostTask(
455 FROM_HERE, 456 FROM_HERE,
456 base::Bind(base::IgnoreResult(&BlinkTestController::DiscardMainWindow), 457 base::Bind(base::IgnoreResult(&BlinkTestController::DiscardMainWindow),
457 base::Unretained(this))); 458 base::Unretained(this)));
458 } 459 }
459 460
460 void BlinkTestController::RenderFrameCreated( 461 void BlinkTestController::RenderFrameCreated(
461 RenderFrameHost* render_frame_host) { 462 RenderFrameHost* render_frame_host) {
462 DCHECK(CalledOnValidThread()); 463 DCHECK(CalledOnValidThread());
463 464 HandleNewRenderFrameHost(render_frame_host);
464 // Monitor the new renderer process for crashes.
465 RenderProcessHost* render_process_host = render_frame_host->GetProcess();
466 if (!render_process_host_observer_.IsObserving(render_process_host))
467 render_process_host_observer_.Add(render_process_host);
468
469 // Ignore hosts created for frames other than the main / top-level frame.
470 if (render_frame_host->GetParent() != nullptr)
471 return;
472
473 // Might be kNullProcessHandle, in which case we will receive a notification
474 // later when the RenderProcessHost was created.
475 base::ProcessHandle handle = render_process_host->GetHandle();
476 if (handle != base::kNullProcessHandle)
477 current_pid_ = base::GetProcId(handle);
478
479 if (!send_configuration_to_next_host_)
480 return;
481 send_configuration_to_next_host_ = false;
482 SendTestConfiguration();
483 } 465 }
484 466
485 void BlinkTestController::RenderFrameHostChanged(RenderFrameHost* old_host, 467 void BlinkTestController::RenderFrameHostChanged(RenderFrameHost* old_host,
486 RenderFrameHost* new_host) { 468 RenderFrameHost* new_host) {
487 DCHECK(CalledOnValidThread()); 469 DCHECK(CalledOnValidThread());
488 470 HandleNewRenderFrameHost(new_host);
489 // Monitor the new renderer process for crashes.
490 RenderProcessHost* render_process_host = new_host->GetProcess();
491 if (!render_process_host_observer_.IsObserving(render_process_host))
492 render_process_host_observer_.Add(render_process_host);
493
494 // Ignore host changes for frames other than the main / top-level frame.
495 if (new_host->GetParent() != nullptr)
496 return;
497
498 base::ProcessHandle process_handle = render_process_host->GetHandle();
499 DCHECK(process_handle != base::kNullProcessHandle);
500 current_pid_ = base::GetProcId(process_handle);
501
502 SendTestConfiguration();
503 } 471 }
504 472
505 void BlinkTestController::DevToolsProcessCrashed() { 473 void BlinkTestController::DevToolsProcessCrashed() {
506 DCHECK(CalledOnValidThread()); 474 DCHECK(CalledOnValidThread());
507 printer_->AddErrorMessage("#CRASHED - devtools"); 475 printer_->AddErrorMessage("#CRASHED - devtools");
508 if (devtools_frontend_) 476 if (devtools_frontend_)
509 devtools_frontend_->Close(); 477 devtools_frontend_->Close();
510 devtools_frontend_ = NULL; 478 devtools_frontend_ = NULL;
511 } 479 }
512 480
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 base::ThreadTaskRunnerHandle::Get()->PostTask( 560 base::ThreadTaskRunnerHandle::Get()->PostTask(
593 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 561 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
594 test_phase_ = CLEAN_UP; 562 test_phase_ = CLEAN_UP;
595 } else if (main_window_) { 563 } else if (main_window_) {
596 main_window_->Close(); 564 main_window_->Close();
597 } 565 }
598 main_window_ = NULL; 566 main_window_ = NULL;
599 current_pid_ = base::kNullProcessId; 567 current_pid_ = base::kNullProcessId;
600 } 568 }
601 569
602 void BlinkTestController::SendTestConfiguration() { 570 void BlinkTestController::HandleNewRenderFrameHost(RenderFrameHost* frame) {
603 RenderViewHost* render_view_host = 571 RenderProcessHost* process = frame->GetProcess();
604 main_window_->web_contents()->GetRenderViewHost(); 572
573 // Track pid of the renderer handling the main frame.
574 if (frame->GetParent() == nullptr) {
575 base::ProcessHandle process_handle = process->GetHandle();
576 if (process_handle != base::kNullProcessHandle)
577 current_pid_ = base::GetProcId(process_handle);
578 }
579
580 // Does RenderFrameHost map to a RenderFrame in a previously unknown process?
581 if (render_process_host_observer_.IsObserving(process))
582 return; // No need to do anything more for an already known process.
583 render_process_host_observer_.Add(process);
584
585 // Make sure the new renderer process has a test configuration shared with
586 // other renderers.
605 ShellTestConfiguration params; 587 ShellTestConfiguration params;
606 params.current_working_directory = current_working_directory_; 588 params.current_working_directory = current_working_directory_;
607 params.temp_path = temp_path_; 589 params.temp_path = temp_path_;
608 params.test_url = test_url_; 590 params.test_url = test_url_;
609 params.enable_pixel_dumping = enable_pixel_dumping_; 591 params.enable_pixel_dumping = enable_pixel_dumping_;
610 params.allow_external_pages = 592 params.allow_external_pages =
611 base::CommandLine::ForCurrentProcess()->HasSwitch( 593 base::CommandLine::ForCurrentProcess()->HasSwitch(
612 switches::kAllowExternalPages); 594 switches::kAllowExternalPages);
613 params.expected_pixel_hash = expected_pixel_hash_; 595 params.expected_pixel_hash = expected_pixel_hash_;
614 params.initial_size = initial_size_; 596 params.initial_size = initial_size_;
615 render_view_host->Send(new ShellViewMsg_SetTestConfiguration( 597
616 render_view_host->GetRoutingID(), params)); 598 if (did_send_initial_test_configuration_) {
599 frame->Send(new ShellViewMsg_ReplicateTestConfiguration(
600 frame->GetRoutingID(), params));
601 } else {
602 did_send_initial_test_configuration_ = true;
603 frame->Send(
604 new ShellViewMsg_SetTestConfiguration(frame->GetRoutingID(), params));
605 }
617 } 606 }
618 607
619 void BlinkTestController::OnTestFinished() { 608 void BlinkTestController::OnTestFinished() {
620 test_phase_ = CLEAN_UP; 609 test_phase_ = CLEAN_UP;
621 if (!printer_->output_finished()) 610 if (!printer_->output_finished())
622 printer_->PrintImageFooter(); 611 printer_->PrintImageFooter();
623 RenderViewHost* render_view_host = 612 RenderViewHost* render_view_host =
624 main_window_->web_contents()->GetRenderViewHost(); 613 main_window_->web_contents()->GetRenderViewHost();
625 main_window_->web_contents()->ExitFullscreen(/*will_cause_resize=*/false); 614 main_window_->web_contents()->ExitFullscreen(/*will_cause_resize=*/false);
626 615
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 } else { 878 } else {
890 printer_->AddErrorMessage(base::StringPrintf( 879 printer_->AddErrorMessage(base::StringPrintf(
891 "FAIL: Unexpected sendBluetoothManualChooserEvent() event name '%s'.", 880 "FAIL: Unexpected sendBluetoothManualChooserEvent() event name '%s'.",
892 event_name.c_str())); 881 event_name.c_str()));
893 return; 882 return;
894 } 883 }
895 bluetooth_chooser_factory_->SendEvent(event, argument); 884 bluetooth_chooser_factory_->SendEvent(event, argument);
896 } 885 }
897 886
898 } // namespace content 887 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/browser/layout_test/blink_test_controller.h ('k') | content/shell/common/shell_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698