OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // Command line flag for overriding the default location for putting generated | 51 // Command line flag for overriding the default location for putting generated |
52 // test images that do not match references. | 52 // test images that do not match references. |
53 const char kGeneratedDir[] = "generated-dir"; | 53 const char kGeneratedDir[] = "generated-dir"; |
54 // Command line flag for overriding the default location for reference images. | 54 // Command line flag for overriding the default location for reference images. |
55 const char kReferenceDir[] = "reference-dir"; | 55 const char kReferenceDir[] = "reference-dir"; |
56 | 56 |
57 // Reads and decodes a PNG image to a bitmap. Returns true on success. The PNG | 57 // Reads and decodes a PNG image to a bitmap. Returns true on success. The PNG |
58 // should have been encoded using |gfx::PNGCodec::Encode|. | 58 // should have been encoded using |gfx::PNGCodec::Encode|. |
59 bool ReadPNGFile(const base::FilePath& file_path, SkBitmap* bitmap) { | 59 bool ReadPNGFile(const base::FilePath& file_path, SkBitmap* bitmap) { |
60 DCHECK(bitmap); | 60 DCHECK(bitmap); |
61 base::FilePath abs_path(file_path); | 61 base::FilePath abs_path = base::MakeAbsoluteFilePath(file_path); |
62 if (!file_util::AbsolutePath(&abs_path)) | 62 if (abs_path.empty()) |
63 return false; | 63 return false; |
64 | 64 |
65 std::string png_data; | 65 std::string png_data; |
66 return file_util::ReadFileToString(abs_path, &png_data) && | 66 return file_util::ReadFileToString(abs_path, &png_data) && |
67 gfx::PNGCodec::Decode(reinterpret_cast<unsigned char*>(&png_data[0]), | 67 gfx::PNGCodec::Decode(reinterpret_cast<unsigned char*>(&png_data[0]), |
68 png_data.length(), | 68 png_data.length(), |
69 bitmap); | 69 bitmap); |
70 } | 70 } |
71 | 71 |
72 // Encodes a bitmap into a PNG and write to disk. Returns true on success. The | 72 // Encodes a bitmap into a PNG and write to disk. Returns true on success. The |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 {160, 100, 0, 0, 0} | 540 {160, 100, 0, 0, 0} |
541 }; | 541 }; |
542 const size_t ref_pixel_count = sizeof(ref_pixels) / sizeof(ReferencePixel); | 542 const size_t ref_pixel_count = sizeof(ref_pixels) / sizeof(ReferencePixel); |
543 | 543 |
544 gfx::Size container_size(400, 300); | 544 gfx::Size container_size(400, 300); |
545 base::FilePath url = | 545 base::FilePath url = |
546 test_data_dir().AppendASCII("pixel_canvas2d.html"); | 546 test_data_dir().AppendASCII("pixel_canvas2d.html"); |
547 RunPixelTest(container_size, url, ref_img_revision_update, | 547 RunPixelTest(container_size, url, ref_img_revision_update, |
548 ref_pixels, ref_pixel_count); | 548 ref_pixels, ref_pixel_count); |
549 } | 549 } |
OLD | NEW |