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

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

Issue 2837083003: DevTools: create test infrastructure so devtools drives the test (Closed)
Patch Set: all Created 3 years, 6 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 <set> 10 #include <set>
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 BlinkTestController* BlinkTestController::instance_ = NULL; 242 BlinkTestController* BlinkTestController::instance_ = NULL;
243 243
244 // static 244 // static
245 BlinkTestController* BlinkTestController::Get() { 245 BlinkTestController* BlinkTestController::Get() {
246 DCHECK(instance_); 246 DCHECK(instance_);
247 return instance_; 247 return instance_;
248 } 248 }
249 249
250 BlinkTestController::BlinkTestController() 250 BlinkTestController::BlinkTestController()
251 : main_window_(NULL), 251 : main_window_(NULL),
252 secondary_window_(nullptr),
252 devtools_window_(nullptr), 253 devtools_window_(nullptr),
253 test_phase_(BETWEEN_TESTS), 254 test_phase_(BETWEEN_TESTS),
254 is_leak_detection_enabled_( 255 is_leak_detection_enabled_(
255 base::CommandLine::ForCurrentProcess()->HasSwitch( 256 base::CommandLine::ForCurrentProcess()->HasSwitch(
256 switches::kEnableLeakDetection)), 257 switches::kEnableLeakDetection)),
257 crash_when_leak_found_(false), 258 crash_when_leak_found_(false),
258 render_process_host_observer_(this) { 259 render_process_host_observer_(this) {
259 CHECK(!instance_); 260 CHECK(!instance_);
260 instance_ = this; 261 instance_ = this;
261 262
(...skipping 27 matching lines...) Expand all
289 bool BlinkTestController::PrepareForLayoutTest( 290 bool BlinkTestController::PrepareForLayoutTest(
290 const GURL& test_url, 291 const GURL& test_url,
291 const base::FilePath& current_working_directory, 292 const base::FilePath& current_working_directory,
292 bool enable_pixel_dumping, 293 bool enable_pixel_dumping,
293 const std::string& expected_pixel_hash) { 294 const std::string& expected_pixel_hash) {
294 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); 295 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
295 test_phase_ = DURING_TEST; 296 test_phase_ = DURING_TEST;
296 current_working_directory_ = current_working_directory; 297 current_working_directory_ = current_working_directory;
297 enable_pixel_dumping_ = enable_pixel_dumping; 298 enable_pixel_dumping_ = enable_pixel_dumping;
298 expected_pixel_hash_ = expected_pixel_hash; 299 expected_pixel_hash_ = expected_pixel_hash;
299 if (test_url.spec().find("/inspector-unit/") == std::string::npos) 300 bool is_devtools_integration_test;
dgozman 2017/06/19 22:55:51 bool is_devtools_js_test = false;
chenwilliam 2017/06/19 23:48:17 Done.
dgozman 2017/06/20 00:02:06 I mostly meant to rename the variable :)
chenwilliam 2017/06/20 01:10:08 ah :) done.
300 test_url_ = test_url; 301 test_url_ = LayoutTestDevToolsBindings::MapTestURLIfNeeded(
301 else 302 test_url, &is_devtools_integration_test);
302 test_url_ = LayoutTestDevToolsBindings::MapJSTestURL(test_url);
303 did_send_initial_test_configuration_ = false; 303 did_send_initial_test_configuration_ = false;
304 printer_->reset(); 304 printer_->reset();
305 frame_to_layout_dump_map_.clear(); 305 frame_to_layout_dump_map_.clear();
306 render_process_host_observer_.RemoveAll(); 306 render_process_host_observer_.RemoveAll();
307 all_observed_render_process_hosts_.clear(); 307 all_observed_render_process_hosts_.clear();
308 main_window_render_process_hosts_.clear(); 308 main_window_render_process_hosts_.clear();
309 accumulated_layout_test_runtime_flags_changes_.Clear(); 309 accumulated_layout_test_runtime_flags_changes_.Clear();
310 layout_test_control_map_.clear(); 310 layout_test_control_map_.clear();
311 ShellBrowserContext* browser_context = 311 ShellBrowserContext* browser_context =
312 ShellContentBrowserClient::Get()->browser_context(); 312 ShellContentBrowserClient::Get()->browser_context();
313 is_compositing_test_ = 313 is_compositing_test_ =
314 test_url_.spec().find("compositing/") != std::string::npos; 314 test_url_.spec().find("compositing/") != std::string::npos;
315 initial_size_ = Shell::GetShellDefaultSize(); 315 initial_size_ = Shell::GetShellDefaultSize();
316 // The W3C SVG layout tests use a different size than the other layout tests. 316 // The W3C SVG layout tests use a different size than the other layout tests.
317 if (test_url_.spec().find("W3C-SVG-1.1") != std::string::npos) 317 if (test_url_.spec().find("W3C-SVG-1.1") != std::string::npos)
318 initial_size_ = gfx::Size(kTestSVGWindowWidthDip, kTestSVGWindowHeightDip); 318 initial_size_ = gfx::Size(kTestSVGWindowWidthDip, kTestSVGWindowHeightDip);
319 if (!main_window_) { 319 if (!main_window_) {
320 main_window_ = content::Shell::CreateNewWindow( 320 main_window_ = content::Shell::CreateNewWindow(
321 browser_context, 321 browser_context,
322 GURL(), 322 GURL(),
323 NULL, 323 NULL,
324 initial_size_); 324 initial_size_);
325 WebContentsObserver::Observe(main_window_->web_contents()); 325 WebContentsObserver::Observe(main_window_->web_contents());
326 current_pid_ = base::kNullProcessId; 326 current_pid_ = base::kNullProcessId;
327 default_prefs_ = 327 default_prefs_ =
328 main_window_->web_contents()->GetRenderViewHost()->GetWebkitPreferences(); 328 main_window_->web_contents()->GetRenderViewHost()->GetWebkitPreferences();
329 main_window_->LoadURL(test_url_); 329 if (is_devtools_integration_test)
330 LoadDevToolsJSTest();
331 else
332 main_window_->LoadURL(test_url_);
330 } else { 333 } else {
331 #if defined(OS_MACOSX) 334 #if defined(OS_MACOSX)
332 // Shell::SizeTo is not implemented on all platforms. 335 // Shell::SizeTo is not implemented on all platforms.
333 main_window_->SizeTo(initial_size_); 336 main_window_->SizeTo(initial_size_);
334 #endif 337 #endif
335 main_window_->web_contents() 338 main_window_->web_contents()
336 ->GetRenderViewHost() 339 ->GetRenderViewHost()
337 ->GetWidget() 340 ->GetWidget()
338 ->GetView() 341 ->GetView()
339 ->SetSize(initial_size_); 342 ->SetSize(initial_size_);
340 main_window_->web_contents() 343 main_window_->web_contents()
341 ->GetRenderViewHost() 344 ->GetRenderViewHost()
342 ->GetWidget() 345 ->GetWidget()
343 ->WasResized(); 346 ->WasResized();
344 RenderViewHost* render_view_host = 347 RenderViewHost* render_view_host =
345 main_window_->web_contents()->GetRenderViewHost(); 348 main_window_->web_contents()->GetRenderViewHost();
346 349
347 // Compositing tests override the default preferences (see 350 // Compositing tests override the default preferences (see
348 // BlinkTestController::OverrideWebkitPrefs) so we force them to be 351 // BlinkTestController::OverrideWebkitPrefs) so we force them to be
349 // calculated again to ensure is_compositing_test_ changes are picked up. 352 // calculated again to ensure is_compositing_test_ changes are picked up.
350 OverrideWebkitPrefs(&default_prefs_); 353 OverrideWebkitPrefs(&default_prefs_);
351 354
352 render_view_host->UpdateWebkitPreferences(default_prefs_); 355 render_view_host->UpdateWebkitPreferences(default_prefs_);
353 HandleNewRenderFrameHost(render_view_host->GetMainFrame()); 356 HandleNewRenderFrameHost(render_view_host->GetMainFrame());
354 357
355 NavigationController::LoadURLParams params(test_url_); 358 if (is_devtools_integration_test) {
356 params.transition_type = ui::PageTransitionFromInt( 359 LoadDevToolsJSTest();
357 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); 360 } else {
358 params.should_clear_history_list = true; 361 NavigationController::LoadURLParams params(test_url_);
359 main_window_->web_contents()->GetController().LoadURLWithParams(params); 362 params.transition_type = ui::PageTransitionFromInt(
360 main_window_->web_contents()->Focus(); 363 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
364 params.should_clear_history_list = true;
365 main_window_->web_contents()->GetController().LoadURLWithParams(params);
366 main_window_->web_contents()->Focus();
367 }
361 } 368 }
362 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->SetActive( 369 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->SetActive(
363 true); 370 true);
364 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus(); 371 main_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus();
365 return true; 372 return true;
366 } 373 }
367 374
375 Shell* BlinkTestController::SecondaryWindow() {
376 if (!secondary_window_) {
377 ShellBrowserContext* browser_context =
378 ShellContentBrowserClient::Get()->browser_context();
379 secondary_window_ = content::Shell::CreateNewWindow(browser_context, GURL(),
380 nullptr, initial_size_);
381 }
382 return secondary_window_;
383 }
384
385 void BlinkTestController::LoadDevToolsJSTest() {
386 devtools_window_ = main_window_;
387 SecondaryWindow();
dgozman 2017/06/19 22:55:51 Shell* secondary = SecondaryWindow(); And use |sec
chenwilliam 2017/06/19 23:48:17 Done.
388 devtools_bindings_.reset(LayoutTestDevToolsBindings::LoadDevTools(
389 devtools_window_->web_contents(), secondary_window_->web_contents(), "",
390 test_url_.spec()));
391 secondary_window_->LoadURL(GURL(url::kAboutBlankURL));
392 }
393
368 bool BlinkTestController::ResetAfterLayoutTest() { 394 bool BlinkTestController::ResetAfterLayoutTest() {
369 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); 395 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
370 printer_->PrintTextFooter(); 396 printer_->PrintTextFooter();
371 printer_->PrintImageFooter(); 397 printer_->PrintImageFooter();
372 printer_->CloseStderr(); 398 printer_->CloseStderr();
373 did_send_initial_test_configuration_ = false; 399 did_send_initial_test_configuration_ = false;
374 test_phase_ = BETWEEN_TESTS; 400 test_phase_ = BETWEEN_TESTS;
375 is_compositing_test_ = false; 401 is_compositing_test_ = false;
376 enable_pixel_dumping_ = false; 402 enable_pixel_dumping_ = false;
377 expected_pixel_hash_.clear(); 403 expected_pixel_hash_.clear();
378 test_url_ = GURL(); 404 test_url_ = GURL();
379 prefs_ = WebPreferences(); 405 prefs_ = WebPreferences();
380 should_override_prefs_ = false; 406 should_override_prefs_ = false;
381 LayoutTestContentBrowserClient::Get()->SetPopupBlockingEnabled(false); 407 LayoutTestContentBrowserClient::Get()->SetPopupBlockingEnabled(false);
408 devtools_bindings_.reset();
382 409
383 #if defined(OS_ANDROID) 410 #if defined(OS_ANDROID)
384 // Re-using the shell's main window on Android causes issues with networking 411 // Re-using the shell's main window on Android causes issues with networking
385 // requests never succeeding. See http://crbug.com/277652. 412 // requests never succeeding. See http://crbug.com/277652.
386 DiscardMainWindow(); 413 DiscardMainWindow();
387 #endif 414 #endif
388 return true; 415 return true;
389 } 416 }
390 417
391 void BlinkTestController::SetTempPath(const base::FilePath& temp_path) { 418 void BlinkTestController::SetTempPath(const base::FilePath& temp_path) {
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 ShellContentBrowserClient::Get()->browser_context(); 861 ShellContentBrowserClient::Get()->browser_context();
835 StoragePartition* storage_partition = 862 StoragePartition* storage_partition =
836 BrowserContext::GetStoragePartition(browser_context, NULL); 863 BrowserContext::GetStoragePartition(browser_context, NULL);
837 storage_partition->GetDOMStorageContext()->DeleteLocalStorage( 864 storage_partition->GetDOMStorageContext()->DeleteLocalStorage(
838 content::LayoutTestDevToolsBindings::GetDevToolsPathAsURL("") 865 content::LayoutTestDevToolsBindings::GetDevToolsPathAsURL("")
839 .GetOrigin()); 866 .GetOrigin());
840 } 867 }
841 868
842 void BlinkTestController::OnShowDevTools(const std::string& settings, 869 void BlinkTestController::OnShowDevTools(const std::string& settings,
843 const std::string& frontend_url) { 870 const std::string& frontend_url) {
844 if (!devtools_window_) { 871 devtools_window_ = SecondaryWindow();
845 ShellBrowserContext* browser_context =
846 ShellContentBrowserClient::Get()->browser_context();
847 devtools_window_ = content::Shell::CreateNewWindow(browser_context, GURL(),
848 nullptr, initial_size_);
849 }
850
851 devtools_bindings_.reset(LayoutTestDevToolsBindings::LoadDevTools( 872 devtools_bindings_.reset(LayoutTestDevToolsBindings::LoadDevTools(
852 devtools_window_->web_contents(), main_window_->web_contents(), settings, 873 devtools_window_->web_contents(), main_window_->web_contents(), settings,
853 frontend_url)); 874 frontend_url));
854 devtools_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus(); 875 devtools_window_->web_contents()->GetRenderViewHost()->GetWidget()->Focus();
855 devtools_window_->web_contents()->Focus(); 876 devtools_window_->web_contents()->Focus();
856 } 877 }
857 878
858 void BlinkTestController::OnEvaluateInDevTools( 879 void BlinkTestController::OnEvaluateInDevTools(
859 int call_id, const std::string& script) { 880 int call_id, const std::string& script) {
860 if (devtools_bindings_) 881 if (devtools_bindings_)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 Send(new ShellViewMsg_SessionHistory(render_view_host->GetRoutingID(), 938 Send(new ShellViewMsg_SessionHistory(render_view_host->GetRoutingID(),
918 routing_ids, 939 routing_ids,
919 session_histories, 940 session_histories,
920 current_entry_indexes)); 941 current_entry_indexes));
921 } 942 }
922 943
923 void BlinkTestController::OnCloseRemainingWindows() { 944 void BlinkTestController::OnCloseRemainingWindows() {
924 DevToolsAgentHost::DetachAllClients(); 945 DevToolsAgentHost::DetachAllClients();
925 std::vector<Shell*> open_windows(Shell::windows()); 946 std::vector<Shell*> open_windows(Shell::windows());
926 for (size_t i = 0; i < open_windows.size(); ++i) { 947 for (size_t i = 0; i < open_windows.size(); ++i) {
927 if (open_windows[i] != main_window_ && open_windows[i] != devtools_window_) 948 if (open_windows[i] != main_window_ && open_windows[i] != secondary_window_)
928 open_windows[i]->Close(); 949 open_windows[i]->Close();
929 } 950 }
930 base::RunLoop().RunUntilIdle(); 951 base::RunLoop().RunUntilIdle();
931 } 952 }
932 953
933 void BlinkTestController::OnResetDone() { 954 void BlinkTestController::OnResetDone() {
934 if (is_leak_detection_enabled_) { 955 if (is_leak_detection_enabled_) {
935 if (main_window_ && main_window_->web_contents()) { 956 if (main_window_ && main_window_->web_contents()) {
936 RenderViewHost* render_view_host = 957 RenderViewHost* render_view_host =
937 main_window_->web_contents()->GetRenderViewHost(); 958 main_window_->web_contents()->GetRenderViewHost();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 } 1037 }
1017 DCHECK(layout_test_control_map_[frame].get()); 1038 DCHECK(layout_test_control_map_[frame].get());
1018 return layout_test_control_map_[frame].get(); 1039 return layout_test_control_map_[frame].get();
1019 } 1040 }
1020 1041
1021 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) { 1042 void BlinkTestController::HandleLayoutTestControlError(RenderFrameHost* frame) {
1022 layout_test_control_map_.erase(frame); 1043 layout_test_control_map_.erase(frame);
1023 } 1044 }
1024 1045
1025 } // namespace content 1046 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698