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

Unified Diff: cc/test/pixel_test_utils.cc

Issue 371863002: cc: For cc pixel test, create data url for pngs and print bounding rect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments addressed. Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/test/pixel_test_utils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/test/pixel_test_utils.cc
diff --git a/cc/test/pixel_test_utils.cc b/cc/test/pixel_test_utils.cc
index 99970b864b70738d6f8e913147fa64349bb2302e..9fbc86a79a34787b548c46288a81adb0060c6ae5 100644
--- a/cc/test/pixel_test_utils.cc
+++ b/cc/test/pixel_test_utils.cc
@@ -7,6 +7,7 @@
#include <string>
#include <vector>
+#include "base/base64.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -28,6 +29,17 @@ bool WritePNGFile(const SkBitmap& bitmap, const base::FilePath& file_path,
return false;
}
+std::string GetPNGDataUrl(const SkBitmap& bitmap) {
+ std::vector<unsigned char> png_data;
+ gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &png_data);
+ std::string data_url;
+ data_url.insert(data_url.end(), png_data.begin(), png_data.end());
+ base::Base64Encode(data_url, &data_url);
+ data_url.insert(0, "data:image/png;base64,");
+
+ return data_url;
+}
+
bool ReadPNGFile(const base::FilePath& file_path, SkBitmap* bitmap) {
DCHECK(bitmap);
std::string png_data;
@@ -60,6 +72,12 @@ bool MatchesPNGFile(const SkBitmap& gen_bmp, base::FilePath ref_img_path,
if (gen_bmp.width() == 0 || gen_bmp.height() == 0)
return true;
+ std::string gen_bmp_data_url = GetPNGDataUrl(gen_bmp);
+ std::string ref_bmp_data_url = GetPNGDataUrl(ref_bmp);
+ LOG(ERROR) << "Pixels do not match!";
vmpstr 2014/07/11 02:57:04 Is this meant to be printed only if comparator.Com
sohanjg 2014/07/11 05:15:21 Yeah, right! its better to log it based on Compare
+ LOG(ERROR) << "Actual: " << gen_bmp_data_url;
+ LOG(ERROR) << "Expected: " << ref_bmp_data_url;
+
return comparator.Compare(gen_bmp, ref_bmp);
}
« no previous file with comments | « cc/test/pixel_test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698