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

Side by Side Diff: cc/resources/picture_unittest.cc

Issue 1144693002: cc: Move files out of cc/resources/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: resources: android Created 5 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/resources/picture.h"
6
7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h"
10 #include "cc/test/fake_content_layer_client.h"
11 #include "cc/test/skia_common.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/skia/include/core/SkGraphics.h"
14 #include "ui/gfx/geometry/rect.h"
15 #include "ui/gfx/skia_util.h"
16
17 namespace cc {
18 namespace {
19
20 TEST(PictureTest, AsBase64String) {
21 SkGraphics::Init();
22
23 gfx::Rect layer_rect(100, 100);
24
25 gfx::Size tile_grid_size(100, 100);
26
27 FakeContentLayerClient content_layer_client;
28
29 scoped_ptr<base::Value> tmp;
30
31 SkPaint red_paint;
32 red_paint.setColor(SkColorSetARGB(255, 255, 0, 0));
33 SkPaint green_paint;
34 green_paint.setColor(SkColorSetARGB(255, 0, 255, 0));
35
36 // Invalid picture (not a dict).
37 tmp.reset(new base::StringValue("abc!@#$%"));
38 scoped_refptr<Picture> invalid_picture =
39 Picture::CreateFromValue(tmp.get());
40 EXPECT_FALSE(invalid_picture.get());
41
42 // Single full-size rect picture.
43 content_layer_client.add_draw_rect(layer_rect, red_paint);
44
45 scoped_refptr<Picture> one_rect_picture =
46 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false,
47 RecordingSource::RECORD_NORMALLY);
48 scoped_ptr<base::Value> serialized_one_rect(one_rect_picture->AsValue());
49
50 // Reconstruct the picture.
51 scoped_refptr<Picture> one_rect_picture_check =
52 Picture::CreateFromValue(serialized_one_rect.get());
53 EXPECT_TRUE(one_rect_picture_check);
54
55 // Check for equivalence.
56 unsigned char one_rect_buffer[4 * 100 * 100] = {0};
57 DrawPicture(one_rect_buffer, layer_rect, one_rect_picture);
58 unsigned char one_rect_buffer_check[4 * 100 * 100] = {0};
59 DrawPicture(one_rect_buffer_check, layer_rect, one_rect_picture_check);
60
61 EXPECT_EQ(one_rect_picture->LayerRect(), one_rect_picture_check->LayerRect());
62 EXPECT_EQ(0, memcmp(one_rect_buffer, one_rect_buffer_check, 4 * 100 * 100));
63
64 // Two rect picture.
65 content_layer_client.add_draw_rect(gfx::Rect(25, 25, 50, 50), green_paint);
66
67 scoped_refptr<Picture> two_rect_picture =
68 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false,
69 RecordingSource::RECORD_NORMALLY);
70
71 scoped_ptr<base::Value> serialized_two_rect(two_rect_picture->AsValue());
72
73 // Reconstruct the picture.
74 scoped_refptr<Picture> two_rect_picture_check =
75 Picture::CreateFromValue(serialized_two_rect.get());
76 EXPECT_TRUE(two_rect_picture_check);
77
78 // Check for equivalence.
79 unsigned char two_rect_buffer[4 * 100 * 100] = {0};
80 DrawPicture(two_rect_buffer, layer_rect, two_rect_picture);
81 unsigned char two_rect_buffer_check[4 * 100 * 100] = {0};
82 DrawPicture(two_rect_buffer_check, layer_rect, two_rect_picture_check);
83
84 EXPECT_EQ(two_rect_picture->LayerRect(), two_rect_picture_check->LayerRect());
85 EXPECT_EQ(0, memcmp(two_rect_buffer, two_rect_buffer_check, 4 * 100 * 100));
86 }
87
88 TEST(PictureTest, CreateFromSkpValue) {
89 SkGraphics::Init();
90
91 gfx::Rect layer_rect(100, 200);
92
93 gfx::Size tile_grid_size(100, 200);
94
95 FakeContentLayerClient content_layer_client;
96
97 scoped_ptr<base::Value> tmp;
98
99 SkPaint red_paint;
100 red_paint.setColor(SkColorSetARGB(255, 255, 0, 0));
101 SkPaint green_paint;
102 green_paint.setColor(SkColorSetARGB(255, 0, 255, 0));
103
104 // Invalid picture (not a dict).
105 tmp.reset(new base::StringValue("abc!@#$%"));
106 scoped_refptr<Picture> invalid_picture =
107 Picture::CreateFromSkpValue(tmp.get());
108 EXPECT_TRUE(!invalid_picture.get());
109
110 // Single full-size rect picture.
111 content_layer_client.add_draw_rect(layer_rect, red_paint);
112 scoped_refptr<Picture> one_rect_picture =
113 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false,
114 RecordingSource::RECORD_NORMALLY);
115 scoped_ptr<base::Value> serialized_one_rect(
116 one_rect_picture->AsValue());
117
118 const base::DictionaryValue* value = NULL;
119 EXPECT_TRUE(serialized_one_rect->GetAsDictionary(&value));
120
121 // Decode the picture from base64.
122 const base::Value* skp_value;
123 EXPECT_TRUE(value->Get("skp64", &skp_value));
124
125 // Reconstruct the picture.
126 scoped_refptr<Picture> one_rect_picture_check =
127 Picture::CreateFromSkpValue(skp_value);
128 EXPECT_TRUE(one_rect_picture_check);
129
130 EXPECT_EQ(100, one_rect_picture_check->LayerRect().width());
131 EXPECT_EQ(200, one_rect_picture_check->LayerRect().height());
132 }
133
134 TEST(PictureTest, RecordingModes) {
135 SkGraphics::Init();
136
137 gfx::Rect layer_rect(100, 200);
138
139 gfx::Size tile_grid_size(100, 200);
140
141 FakeContentLayerClient content_layer_client;
142 EXPECT_EQ(NULL, content_layer_client.last_canvas());
143
144 scoped_refptr<Picture> picture =
145 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false,
146 RecordingSource::RECORD_NORMALLY);
147 EXPECT_TRUE(content_layer_client.last_canvas() != NULL);
148 EXPECT_EQ(ContentLayerClient::PAINTING_BEHAVIOR_NORMAL,
149 content_layer_client.last_painting_control());
150 EXPECT_TRUE(picture.get());
151
152 picture = Picture::Create(layer_rect, &content_layer_client, tile_grid_size,
153 false, RecordingSource::RECORD_WITH_SK_NULL_CANVAS);
154 EXPECT_TRUE(content_layer_client.last_canvas() != NULL);
155 EXPECT_EQ(ContentLayerClient::PAINTING_BEHAVIOR_NORMAL,
156 content_layer_client.last_painting_control());
157 EXPECT_TRUE(picture.get());
158
159 picture =
160 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false,
161 RecordingSource::RECORD_WITH_PAINTING_DISABLED);
162 EXPECT_TRUE(content_layer_client.last_canvas() != NULL);
163 EXPECT_EQ(ContentLayerClient::DISPLAY_LIST_PAINTING_DISABLED,
164 content_layer_client.last_painting_control());
165 EXPECT_TRUE(picture.get());
166
167 picture =
168 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, false,
169 RecordingSource::RECORD_WITH_CACHING_DISABLED);
170 EXPECT_TRUE(content_layer_client.last_canvas() != NULL);
171 EXPECT_EQ(ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED,
172 content_layer_client.last_painting_control());
173 EXPECT_TRUE(picture.get());
174
175 // RECORD_WITH_CONSTRUCTION_DISABLED is not supported for Picture.
176
177 EXPECT_EQ(5, RecordingSource::RECORDING_MODE_COUNT);
178 }
179
180 } // namespace
181 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/picture_pile_unittest.cc ('k') | cc/resources/pixel_buffer_tile_task_worker_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698