OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #undef LOG | 5 #undef LOG |
6 | 6 |
7 #include "webkit/tools/test_shell/test_shell.h" | 7 #include "webkit/tools/test_shell/test_shell.h" |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 printf("#MD5:%s\n", md5sum.c_str()); | 318 printf("#MD5:%s\n", md5sum.c_str()); |
319 } | 319 } |
320 if (dumped_anything) | 320 if (dumped_anything) |
321 printf("#EOF\n"); | 321 printf("#EOF\n"); |
322 fflush(stdout); | 322 fflush(stdout); |
323 } | 323 } |
324 } | 324 } |
325 | 325 |
326 // static | 326 // static |
327 std::string TestShell::DumpImage(skia::PlatformCanvas* canvas, | 327 std::string TestShell::DumpImage(skia::PlatformCanvas* canvas, |
328 const std::wstring& file_name, const std::string& pixel_hash) { | 328 const FilePath& path, const std::string& pixel_hash) { |
329 skia::BitmapPlatformDevice& device = | 329 skia::BitmapPlatformDevice& device = |
330 static_cast<skia::BitmapPlatformDevice&>(canvas->getTopPlatformDevice()); | 330 static_cast<skia::BitmapPlatformDevice&>(canvas->getTopPlatformDevice()); |
331 const SkBitmap& src_bmp = device.accessBitmap(false); | 331 const SkBitmap& src_bmp = device.accessBitmap(false); |
332 | 332 |
333 // Encode image. | 333 // Encode image. |
334 std::vector<unsigned char> png; | 334 std::vector<unsigned char> png; |
335 SkAutoLockPixels src_bmp_lock(src_bmp); | 335 SkAutoLockPixels src_bmp_lock(src_bmp); |
336 gfx::PNGCodec::ColorFormat color_format = gfx::PNGCodec::FORMAT_BGRA; | 336 gfx::PNGCodec::ColorFormat color_format = gfx::PNGCodec::FORMAT_BGRA; |
337 | 337 |
338 // Fix the alpha. The expected PNGs on Mac have an alpha channel, so we want | 338 // Fix the alpha. The expected PNGs on Mac have an alpha channel, so we want |
(...skipping 25 matching lines...) Expand all Loading... |
364 | 364 |
365 // Only encode and dump the png if the hashes don't match. Encoding the image | 365 // Only encode and dump the png if the hashes don't match. Encoding the image |
366 // is really expensive. | 366 // is really expensive. |
367 if (md5hash.compare(pixel_hash) != 0) { | 367 if (md5hash.compare(pixel_hash) != 0) { |
368 gfx::PNGCodec::Encode( | 368 gfx::PNGCodec::Encode( |
369 reinterpret_cast<const unsigned char*>(src_bmp.getPixels()), | 369 reinterpret_cast<const unsigned char*>(src_bmp.getPixels()), |
370 color_format, src_bmp.width(), src_bmp.height(), | 370 color_format, src_bmp.width(), src_bmp.height(), |
371 static_cast<int>(src_bmp.rowBytes()), discard_transparency, &png); | 371 static_cast<int>(src_bmp.rowBytes()), discard_transparency, &png); |
372 | 372 |
373 // Write to disk. | 373 // Write to disk. |
374 file_util::WriteFile(file_name, reinterpret_cast<const char *>(&png[0]), | 374 file_util::WriteFile(path, reinterpret_cast<const char *>(&png[0]), |
375 png.size()); | 375 png.size()); |
376 } | 376 } |
377 | 377 |
378 return md5hash; | 378 return md5hash; |
379 } | 379 } |
380 | 380 |
381 // static | 381 // static |
382 void TestShell::InitLogging(bool suppress_error_dialogs, | 382 void TestShell::InitLogging(bool suppress_error_dialogs, |
383 bool layout_test_mode, | 383 bool layout_test_mode, |
384 bool enable_gp_fault_error_box) { | 384 bool enable_gp_fault_error_box) { |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 SetFocus(webViewHost(), true); | 685 SetFocus(webViewHost(), true); |
686 | 686 |
687 return true; | 687 return true; |
688 } | 688 } |
689 | 689 |
690 void TestShell::GoBackOrForward(int offset) { | 690 void TestShell::GoBackOrForward(int offset) { |
691 navigation_controller_->GoToOffset(offset); | 691 navigation_controller_->GoToOffset(offset); |
692 } | 692 } |
693 | 693 |
694 void TestShell::DumpDocumentText() { | 694 void TestShell::DumpDocumentText() { |
695 std::wstring file_path; | 695 FilePath file_path; |
696 if (!PromptForSaveFile(L"Dump document text", &file_path)) | 696 if (!PromptForSaveFile(L"Dump document text", &file_path)) |
697 return; | 697 return; |
698 | 698 |
699 const std::string data = | 699 const std::string data = |
700 WideToUTF8(webkit_glue::DumpDocumentText(webView()->mainFrame())); | 700 WideToUTF8(webkit_glue::DumpDocumentText(webView()->mainFrame())); |
701 file_util::WriteFile(file_path, data.c_str(), data.length()); | 701 file_util::WriteFile(file_path, data.c_str(), data.length()); |
702 } | 702 } |
703 | 703 |
704 void TestShell::DumpRenderTree() { | 704 void TestShell::DumpRenderTree() { |
705 std::wstring file_path; | 705 FilePath file_path; |
706 if (!PromptForSaveFile(L"Dump render tree", &file_path)) | 706 if (!PromptForSaveFile(L"Dump render tree", &file_path)) |
707 return; | 707 return; |
708 | 708 |
709 const std::string data = | 709 const std::string data = |
710 WideToUTF8(webkit_glue::DumpRenderer(webView()->mainFrame())); | 710 WideToUTF8(webkit_glue::DumpRenderer(webView()->mainFrame())); |
711 file_util::WriteFile(file_path, data.c_str(), data.length()); | 711 file_util::WriteFile(file_path, data.c_str(), data.length()); |
712 } | 712 } |
713 | 713 |
714 std::wstring TestShell::GetDocumentText() { | 714 std::wstring TestShell::GetDocumentText() { |
715 return webkit_glue::DumpDocumentText(webView()->mainFrame()); | 715 return webkit_glue::DumpDocumentText(webView()->mainFrame()); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 | 807 |
808 std::string GetProductVersion() { | 808 std::string GetProductVersion() { |
809 return std::string("Chrome/0.0.0.0"); | 809 return std::string("Chrome/0.0.0.0"); |
810 } | 810 } |
811 | 811 |
812 bool IsSingleProcess() { | 812 bool IsSingleProcess() { |
813 return true; | 813 return true; |
814 } | 814 } |
815 | 815 |
816 } // namespace webkit_glue | 816 } // namespace webkit_glue |
OLD | NEW |