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

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

Powered by Google App Engine
This is Rietveld 408576698