OLD | NEW |
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/webkit_test_controller.h" | 5 #include "content/shell/browser/webkit_test_controller.h" |
6 | 6 |
7 #include <iostream> | 7 #include <iostream> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 195 |
196 // static | 196 // static |
197 WebKitTestController* WebKitTestController::Get() { | 197 WebKitTestController* WebKitTestController::Get() { |
198 DCHECK(instance_); | 198 DCHECK(instance_); |
199 return instance_; | 199 return instance_; |
200 } | 200 } |
201 | 201 |
202 WebKitTestController::WebKitTestController() | 202 WebKitTestController::WebKitTestController() |
203 : main_window_(NULL), | 203 : main_window_(NULL), |
204 test_phase_(BETWEEN_TESTS), | 204 test_phase_(BETWEEN_TESTS), |
205 is_leak_detection_enabled_(CommandLine::ForCurrentProcess()->HasSwitch( | 205 is_leak_detection_enabled_( |
206 switches::kEnableLeakDetection)), | 206 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 207 switches::kEnableLeakDetection)), |
207 crash_when_leak_found_(false) { | 208 crash_when_leak_found_(false) { |
208 CHECK(!instance_); | 209 CHECK(!instance_); |
209 instance_ = this; | 210 instance_ = this; |
210 | 211 |
211 if (is_leak_detection_enabled_) { | 212 if (is_leak_detection_enabled_) { |
212 std::string switchValue = | 213 std::string switchValue = |
213 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 214 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
214 switches::kEnableLeakDetection); | 215 switches::kEnableLeakDetection); |
215 crash_when_leak_found_ = switchValue == switches::kCrashOnFailure; | 216 crash_when_leak_found_ = switchValue == switches::kCrashOnFailure; |
216 } | 217 } |
217 | 218 |
218 printer_.reset(new WebKitTestResultPrinter(&std::cout, &std::cerr)); | 219 printer_.reset(new WebKitTestResultPrinter(&std::cout, &std::cerr)); |
219 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEncodeBinary)) | 220 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 221 switches::kEncodeBinary)) |
220 printer_->set_encode_binary_data(true); | 222 printer_->set_encode_binary_data(true); |
221 registrar_.Add(this, | 223 registrar_.Add(this, |
222 NOTIFICATION_RENDERER_PROCESS_CREATED, | 224 NOTIFICATION_RENDERER_PROCESS_CREATED, |
223 NotificationService::AllSources()); | 225 NotificationService::AllSources()); |
224 GpuDataManager::GetInstance()->AddObserver(this); | 226 GpuDataManager::GetInstance()->AddObserver(this); |
225 ResetAfterLayoutTest(); | 227 ResetAfterLayoutTest(); |
226 } | 228 } |
227 | 229 |
228 WebKitTestController::~WebKitTestController() { | 230 WebKitTestController::~WebKitTestController() { |
229 DCHECK(CalledOnValidThread()); | 231 DCHECK(CalledOnValidThread()); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 printer_->AddErrorMessage("#CRASHED - worker"); | 330 printer_->AddErrorMessage("#CRASHED - worker"); |
329 DiscardMainWindow(); | 331 DiscardMainWindow(); |
330 } | 332 } |
331 | 333 |
332 void WebKitTestController::OverrideWebkitPrefs(WebPreferences* prefs) { | 334 void WebKitTestController::OverrideWebkitPrefs(WebPreferences* prefs) { |
333 if (should_override_prefs_) { | 335 if (should_override_prefs_) { |
334 *prefs = prefs_; | 336 *prefs = prefs_; |
335 } else { | 337 } else { |
336 ApplyLayoutTestDefaultPreferences(prefs); | 338 ApplyLayoutTestDefaultPreferences(prefs); |
337 if (is_compositing_test_) { | 339 if (is_compositing_test_) { |
338 CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 340 base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); |
339 if (!command_line.HasSwitch(switches::kDisableGpu)) | 341 if (!command_line.HasSwitch(switches::kDisableGpu)) |
340 prefs->accelerated_2d_canvas_enabled = true; | 342 prefs->accelerated_2d_canvas_enabled = true; |
341 prefs->mock_scrollbars_enabled = true; | 343 prefs->mock_scrollbars_enabled = true; |
342 } | 344 } |
343 } | 345 } |
344 } | 346 } |
345 | 347 |
346 void WebKitTestController::OpenURL(const GURL& url) { | 348 void WebKitTestController::OpenURL(const GURL& url) { |
347 if (test_phase_ != DURING_TEST) | 349 if (test_phase_ != DURING_TEST) |
348 return; | 350 return; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 } | 491 } |
490 | 492 |
491 void WebKitTestController::SendTestConfiguration() { | 493 void WebKitTestController::SendTestConfiguration() { |
492 RenderViewHost* render_view_host = | 494 RenderViewHost* render_view_host = |
493 main_window_->web_contents()->GetRenderViewHost(); | 495 main_window_->web_contents()->GetRenderViewHost(); |
494 ShellTestConfiguration params; | 496 ShellTestConfiguration params; |
495 params.current_working_directory = current_working_directory_; | 497 params.current_working_directory = current_working_directory_; |
496 params.temp_path = temp_path_; | 498 params.temp_path = temp_path_; |
497 params.test_url = test_url_; | 499 params.test_url = test_url_; |
498 params.enable_pixel_dumping = enable_pixel_dumping_; | 500 params.enable_pixel_dumping = enable_pixel_dumping_; |
499 params.allow_external_pages = CommandLine::ForCurrentProcess()->HasSwitch( | 501 params.allow_external_pages = |
500 switches::kAllowExternalPages); | 502 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 503 switches::kAllowExternalPages); |
501 params.expected_pixel_hash = expected_pixel_hash_; | 504 params.expected_pixel_hash = expected_pixel_hash_; |
502 params.initial_size = initial_size_; | 505 params.initial_size = initial_size_; |
503 render_view_host->Send(new ShellViewMsg_SetTestConfiguration( | 506 render_view_host->Send(new ShellViewMsg_SetTestConfiguration( |
504 render_view_host->GetRoutingID(), params)); | 507 render_view_host->GetRoutingID(), params)); |
505 } | 508 } |
506 | 509 |
507 void WebKitTestController::OnTestFinished() { | 510 void WebKitTestController::OnTestFinished() { |
508 test_phase_ = CLEAN_UP; | 511 test_phase_ = CLEAN_UP; |
509 if (!printer_->output_finished()) | 512 if (!printer_->output_finished()) |
510 printer_->PrintImageFooter(); | 513 printer_->PrintImageFooter(); |
(...skipping 12 matching lines...) Expand all Loading... |
523 SkAutoLockPixels image_lock(image); | 526 SkAutoLockPixels image_lock(image); |
524 | 527 |
525 printer_->PrintImageHeader(actual_pixel_hash, expected_pixel_hash_); | 528 printer_->PrintImageHeader(actual_pixel_hash, expected_pixel_hash_); |
526 | 529 |
527 // Only encode and dump the png if the hashes don't match. Encoding the | 530 // Only encode and dump the png if the hashes don't match. Encoding the |
528 // image is really expensive. | 531 // image is really expensive. |
529 if (actual_pixel_hash != expected_pixel_hash_) { | 532 if (actual_pixel_hash != expected_pixel_hash_) { |
530 std::vector<unsigned char> png; | 533 std::vector<unsigned char> png; |
531 | 534 |
532 bool discard_transparency = true; | 535 bool discard_transparency = true; |
533 if (CommandLine::ForCurrentProcess()->HasSwitch( | 536 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
534 switches::kEnableOverlayFullscreenVideo)) | 537 switches::kEnableOverlayFullscreenVideo)) |
535 discard_transparency = false; | 538 discard_transparency = false; |
536 | 539 |
537 std::vector<gfx::PNGCodec::Comment> comments; | 540 std::vector<gfx::PNGCodec::Comment> comments; |
538 comments.push_back(gfx::PNGCodec::Comment("checksum", actual_pixel_hash)); | 541 comments.push_back(gfx::PNGCodec::Comment("checksum", actual_pixel_hash)); |
539 bool success = gfx::PNGCodec::Encode( | 542 bool success = gfx::PNGCodec::Encode( |
540 static_cast<const unsigned char*>(image.getPixels()), | 543 static_cast<const unsigned char*>(image.getPixels()), |
541 gfx::PNGCodec::FORMAT_BGRA, | 544 gfx::PNGCodec::FORMAT_BGRA, |
542 gfx::Size(image.width(), image.height()), | 545 gfx::Size(image.width(), image.height()), |
543 static_cast<int>(image.rowBytes()), | 546 static_cast<int>(image.rowBytes()), |
544 discard_transparency, | 547 discard_transparency, |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 | 685 |
683 printer_->AddErrorMessage( | 686 printer_->AddErrorMessage( |
684 base::StringPrintf("#LEAK - renderer pid %d (%s)", current_pid_, | 687 base::StringPrintf("#LEAK - renderer pid %d (%s)", current_pid_, |
685 result.detail.c_str())); | 688 result.detail.c_str())); |
686 CHECK(!crash_when_leak_found_); | 689 CHECK(!crash_when_leak_found_); |
687 | 690 |
688 DiscardMainWindow(); | 691 DiscardMainWindow(); |
689 } | 692 } |
690 | 693 |
691 } // namespace content | 694 } // namespace content |
OLD | NEW |