diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/compositor/compositor.gyp | 1 | ||||
-rw-r--r-- | ui/compositor/layer_unittest.cc | 70 | ||||
-rw-r--r-- | ui/compositor/test/test_compositor_host_mac.mm | 3 | ||||
-rw-r--r-- | ui/gl/gl_implementation_mac.cc | 4 |
4 files changed, 9 insertions, 69 deletions
diff --git a/ui/compositor/compositor.gyp b/ui/compositor/compositor.gyp index c65ffe1..9f9b6a6 100644 --- a/ui/compositor/compositor.gyp +++ b/ui/compositor/compositor.gyp @@ -99,6 +99,7 @@ '<(DEPTH)/base/base.gyp:base', '<(DEPTH)/base/base.gyp:test_support_base', '<(DEPTH)/cc/cc.gyp:cc', + '<(DEPTH)/cc/cc_tests.gyp:cc_test_utils', '<(DEPTH)/skia/skia.gyp:skia', '<(DEPTH)/testing/gtest.gyp:gtest', '<(DEPTH)/ui/gl/gl.gyp:gl', diff --git a/ui/compositor/layer_unittest.cc b/ui/compositor/layer_unittest.cc index 80e9384..7008763 100644 --- a/ui/compositor/layer_unittest.cc +++ b/ui/compositor/layer_unittest.cc @@ -11,6 +11,7 @@ #include "base/string_util.h" #include "base/stringprintf.h" #include "cc/layer.h" +#include "cc/test/pixel_test_utils.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/compositor/compositor_observer.h" #include "ui/compositor/compositor_setup.h" @@ -22,77 +23,12 @@ #include "ui/gfx/gfx_paths.h" #include "ui/gfx/skia_util.h" +using cc::test::IsSameAsPNGFile; + namespace ui { namespace { -// Encodes a bitmap into a PNG and write to disk. Returns true on success. The -// parent directory does not have to exist. -bool WritePNGFile(const SkBitmap& bitmap, const FilePath& file_path) { - std::vector<unsigned char> png_data; - if (gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &png_data) && - file_util::CreateDirectory(file_path.DirName())) { - char* data = reinterpret_cast<char*>(&png_data[0]); - int size = static_cast<int>(png_data.size()); - return file_util::WriteFile(file_path, data, size) == size; - } - return false; -} - -// Reads and decodes a PNG image to a bitmap. Returns true on success. The PNG -// should have been encoded using |gfx::PNGCodec::Encode|. -bool ReadPNGFile(const FilePath& file_path, SkBitmap* bitmap) { - DCHECK(bitmap); - std::string png_data; - return file_util::ReadFileToString(file_path, &png_data) && - gfx::PNGCodec::Decode(reinterpret_cast<unsigned char*>(&png_data[0]), - png_data.length(), - bitmap); -} - -// Compares with a PNG file on disk, and returns true if it is the same as -// the given image. |ref_img_path| is absolute. -bool IsSameAsPNGFile(const SkBitmap& gen_bmp, FilePath ref_img_path) { - SkBitmap ref_bmp; - if (!ReadPNGFile(ref_img_path, &ref_bmp)) { - LOG(ERROR) << "Cannot read reference image: " << ref_img_path.value(); - return false; - } - - if (ref_bmp.width() != gen_bmp.width() || - ref_bmp.height() != gen_bmp.height()) { - LOG(ERROR) - << "Dimensions do not match (Expected) vs (Actual):" - << "(" << ref_bmp.width() << "x" << ref_bmp.height() - << ") vs. " - << "(" << gen_bmp.width() << "x" << gen_bmp.height() << ")"; - return false; - } - - // Compare pixels and create a simple diff image. - int diff_pixels_count = 0; - SkAutoLockPixels lock_bmp(gen_bmp); - SkAutoLockPixels lock_ref_bmp(ref_bmp); - // The reference images were saved with no alpha channel. Use the mask to - // set alpha to 0. - uint32_t kAlphaMask = 0x00FFFFFF; - for (int x = 0; x < gen_bmp.width(); ++x) { - for (int y = 0; y < gen_bmp.height(); ++y) { - if ((*gen_bmp.getAddr32(x, y) & kAlphaMask) != - (*ref_bmp.getAddr32(x, y) & kAlphaMask)) { - ++diff_pixels_count; - } - } - } - - if (diff_pixels_count != 0) { - LOG(ERROR) << "Images differ by pixel count: " << diff_pixels_count; - return false; - } - - return true; -} - // Returns a comma-separated list of the names of |layer|'s children in // bottom-to-top stacking order. std::string GetLayerChildrenNames(const Layer& layer) { diff --git a/ui/compositor/test/test_compositor_host_mac.mm b/ui/compositor/test/test_compositor_host_mac.mm index e808b80..3d237aa 100644 --- a/ui/compositor/test/test_compositor_host_mac.mm +++ b/ui/compositor/test/test_compositor_host_mac.mm @@ -127,8 +127,7 @@ void TestCompositorHostMac::Show() { backing:NSBackingStoreBuffered defer:NO]; scoped_nsobject<AcceleratedTestView> view([[AcceleratedTestView alloc] init]); - compositor_.reset(new ui::Compositor(this, view)); - compositor_->SetScaleAndSize(1.0f, bounds_.size()); + compositor_.reset(new ui::Compositor(this, view, bounds_.size())); [view setCompositor:compositor_.get()]; [window_ setContentView:view]; [window_ orderFront:nil]; diff --git a/ui/gl/gl_implementation_mac.cc b/ui/gl/gl_implementation_mac.cc index d22082e..0b22e43 100644 --- a/ui/gl/gl_implementation_mac.cc +++ b/ui/gl/gl_implementation_mac.cc @@ -49,6 +49,10 @@ bool InitializeGLBindings(GLImplementation implementation) { return false; } FilePath bundle_path = base::mac::GetAppBundlePath(exe_path); + // Some unit test targets depend on osmesa but aren't built as app + // bundles. In that case, the .so is next to the executable. + if (bundle_path.empty()) + bundle_path = exe_path; FilePath build_dir_path = bundle_path.DirName(); FilePath osmesa_path = build_dir_path.Append("osmesa.so"); |