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

Unified Diff: cc/resources/picture_unittest.cc

Issue 13884018: cc: Add base64 encoding to picture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added check for picture validity Created 7 years, 8 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
« cc/resources/picture.cc ('K') | « cc/resources/picture.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/picture_unittest.cc
diff --git a/cc/resources/picture_unittest.cc b/cc/resources/picture_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..012adca3e79be7eae71798c6e5a88a003d0ccd98
--- /dev/null
+++ b/cc/resources/picture_unittest.cc
@@ -0,0 +1,108 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/resources/picture.h"
+
+#include "base/memory/ref_counted.h"
+#include "cc/test/fake_content_layer_client.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "third_party/skia/include/core/SkDevice.h"
+#include "third_party/skia/include/core/SkTileGridPicture.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/skia_util.h"
+
+namespace cc {
+namespace {
+
+void DrawPicture(unsigned char* buffer,
+ gfx::Rect layer_rect,
+ scoped_refptr<Picture> picture) {
+ SkBitmap bitmap;
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config,
+ layer_rect.width(),
+ layer_rect.height());
+ bitmap.setPixels(buffer);
+ SkDevice device(bitmap);
+ SkCanvas canvas(&device);
+ canvas.clipRect(gfx::RectToSkRect(layer_rect));
+ picture->Raster(&canvas, layer_rect, 1.0f, false);
+}
+
+TEST(PictureTest, AsBase64String) {
+ gfx::Rect layer_rect(100, 100);
+
+ SkTileGridPicture::TileGridInfo tile_grid_info;
+ tile_grid_info.fTileInterval = SkISize::Make(100, 100);
+ tile_grid_info.fMargin.setEmpty();
+ tile_grid_info.fOffset.setZero();
+
+ FakeContentLayerClient content_layer_client;
+
+ // Invalid picture (not base64).
+ scoped_refptr<Picture> invalid_picture =
+ Picture::CreateFromBase64String("abc!@#$%");
+ EXPECT_TRUE(!invalid_picture);
+
+ // Invalid picture (empty string).
+ scoped_refptr<Picture> second_invalid_picture =
+ Picture::CreateFromBase64String("");
+ EXPECT_TRUE(!second_invalid_picture);
+
+ // Invalid picture (random base64 string).
+ scoped_refptr<Picture> third_invalid_picture =
+ Picture::CreateFromBase64String("ABCDABCDABCDABCDABCDABCDABCDABCDABCD");
+ EXPECT_TRUE(!third_invalid_picture);
+
+ // Single full-size rect picture.
+ content_layer_client.add_draw_rect(layer_rect);
+ scoped_refptr<Picture> one_rect_picture = Picture::Create(layer_rect);
+ one_rect_picture->Record(&content_layer_client, NULL, tile_grid_info);
+ std::string serialized_one_rect;
+ one_rect_picture->AsBase64String(&serialized_one_rect);
+
+ // Reconstruct the picture.
+ scoped_refptr<Picture> one_rect_picture_check =
+ Picture::CreateFromBase64String(serialized_one_rect);
+
+ // Check for equivalence.
+ unsigned char one_rect_buffer[4 * 100 * 100] = {0};
+ DrawPicture(one_rect_buffer, layer_rect, one_rect_picture);
+ unsigned char one_rect_buffer_check[4 * 100 * 100] = {0};
+ DrawPicture(one_rect_buffer_check, layer_rect, one_rect_picture_check);
+
+ EXPECT_EQ(one_rect_picture->LayerRect(),
+ one_rect_picture_check->LayerRect());
+ EXPECT_EQ(one_rect_picture->OpaqueRect(),
+ one_rect_picture_check->OpaqueRect());
+ EXPECT_TRUE(
+ memcmp(one_rect_buffer, one_rect_buffer_check, 4 * 100 * 100) == 0);
+
+ // Two rect picture.
+ content_layer_client.add_draw_rect(gfx::Rect(25, 25, 50, 50));
+ scoped_refptr<Picture> two_rect_picture = Picture::Create(layer_rect);
+ two_rect_picture->Record(&content_layer_client, NULL, tile_grid_info);
+ std::string serialized_two_rect;
+ two_rect_picture->AsBase64String(&serialized_two_rect);
+
+ // Reconstruct the picture.
+ scoped_refptr<Picture> two_rect_picture_check =
+ Picture::CreateFromBase64String(serialized_two_rect);
+
+ // Check for equivalence.
+ unsigned char two_rect_buffer[4 * 100 * 100] = {0};
+ DrawPicture(two_rect_buffer, layer_rect, two_rect_picture);
+ unsigned char two_rect_buffer_check[4 * 100 * 100] = {0};
+ DrawPicture(two_rect_buffer_check, layer_rect, two_rect_picture_check);
+
+ EXPECT_EQ(two_rect_picture->LayerRect(),
+ two_rect_picture_check->LayerRect());
+ EXPECT_EQ(two_rect_picture->OpaqueRect(),
+ two_rect_picture_check->OpaqueRect());
+ EXPECT_TRUE(
+ memcmp(two_rect_buffer, two_rect_buffer_check, 4 * 100 * 100) == 0);
+}
+
+} // namespace
+} // namespace cc
« cc/resources/picture.cc ('K') | « cc/resources/picture.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698