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

Side by Side Diff: cc/output/filter_operations_unittest.cc

Issue 16968002: Move implementation of WebFilterOperations into cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « cc/output/filter_operations.cc ('k') | cc/output/gl_renderer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/output/filter_operations.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/gfx/point.h"
8
9 namespace cc {
10 namespace {
11
12 TEST(FilterOperationsTest, GetOutsetsBlur) {
13 FilterOperations ops;
14 ops.Append(FilterOperation::CreateBlurFilter(20));
15 int top, right, bottom, left;
16 top = right = bottom = left = 0;
17 ops.GetOutsets(&top, &right, &bottom, &left);
18 EXPECT_EQ(57, top);
19 EXPECT_EQ(57, right);
20 EXPECT_EQ(57, bottom);
21 EXPECT_EQ(57, left);
22 }
23
24 TEST(FilterOperationsTest, GetOutsetsDropShadow) {
25 FilterOperations ops;
26 ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0));
27 int top, right, bottom, left;
28 top = right = bottom = left = 0;
29 ops.GetOutsets(&top, &right, &bottom, &left);
30 EXPECT_EQ(49, top);
31 EXPECT_EQ(60, right);
32 EXPECT_EQ(65, bottom);
33 EXPECT_EQ(54, left);
34 }
35
36 #define SAVE_RESTORE_AMOUNT(filter_name, filter_type, a) \
37 { \
38 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \
39 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
40 EXPECT_EQ(a, op.amount()); \
41 \
42 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
43 op2.set_type(FilterOperation::filter_type); \
44 \
45 EXPECT_NE(a, op2.amount()); \
46 \
47 op2.set_amount(a); \
48 \
49 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
50 EXPECT_EQ(a, op2.amount()); \
51 }
52
53 #define SAVE_RESTORE_OFFSET_AMOUNT_COLOR(filter_name, filter_type, a, b, c) \
54 { \
55 FilterOperation op = \
56 FilterOperation::Create##filter_name##Filter(a, b, c); \
57 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
58 EXPECT_EQ(a, op.drop_shadow_offset()); \
59 EXPECT_EQ(b, op.amount()); \
60 EXPECT_EQ(c, op.drop_shadow_color()); \
61 \
62 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
63 op2.set_type(FilterOperation::filter_type); \
64 \
65 EXPECT_NE(a, op2.drop_shadow_offset()); \
66 EXPECT_NE(b, op2.amount()); \
67 EXPECT_NE(c, op2.drop_shadow_color()); \
68 \
69 op2.set_drop_shadow_offset(a); \
70 op2.set_amount(b); \
71 op2.set_drop_shadow_color(c); \
72 \
73 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
74 EXPECT_EQ(a, op2.drop_shadow_offset()); \
75 EXPECT_EQ(b, op2.amount()); \
76 EXPECT_EQ(c, op2.drop_shadow_color()); \
77 }
78
79 #define SAVE_RESTORE_MATRIX(filter_name, filter_type, a) \
80 { \
81 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \
82 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
83 for (size_t i = 0; i < 20; ++i) \
84 EXPECT_EQ(a[i], op.matrix()[i]); \
85 \
86 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
87 op2.set_type(FilterOperation::filter_type); \
88 \
89 for (size_t i = 0; i < 20; ++i) \
90 EXPECT_NE(a[i], op2.matrix()[i]); \
91 \
92 op2.set_matrix(a); \
93 \
94 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
95 for (size_t i = 0; i < 20; ++i) \
96 EXPECT_EQ(a[i], op.matrix()[i]); \
97 }
98
99 #define SAVE_RESTORE_AMOUNT_INSET(filter_name, filter_type, a, b) \
100 { \
101 FilterOperation op = FilterOperation::Create##filter_name##Filter(a, b); \
102 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
103 EXPECT_EQ(a, op.amount()); \
104 EXPECT_EQ(b, op.zoom_inset()); \
105 \
106 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
107 op2.set_type(FilterOperation::filter_type); \
108 \
109 EXPECT_NE(a, op2.amount()); \
110 EXPECT_NE(b, op2.zoom_inset()); \
111 \
112 op2.set_amount(a); \
113 op2.set_zoom_inset(b); \
114 \
115 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
116 EXPECT_EQ(a, op2.amount()); \
117 EXPECT_EQ(b, op2.zoom_inset()); \
118 }
119
120 TEST(FilterOperationsTest, SaveAndRestore) {
121 SAVE_RESTORE_AMOUNT(Grayscale, GRAYSCALE, 0.6f);
122 SAVE_RESTORE_AMOUNT(Sepia, SEPIA, 0.6f);
123 SAVE_RESTORE_AMOUNT(Saturate, SATURATE, 0.6f);
124 SAVE_RESTORE_AMOUNT(HueRotate, HUE_ROTATE, 0.6f);
125 SAVE_RESTORE_AMOUNT(Invert, INVERT, 0.6f);
126 SAVE_RESTORE_AMOUNT(Brightness, BRIGHTNESS, 0.6f);
127 SAVE_RESTORE_AMOUNT(Contrast, CONTRAST, 0.6f);
128 SAVE_RESTORE_AMOUNT(Opacity, OPACITY, 0.6f);
129 SAVE_RESTORE_AMOUNT(Blur, BLUR, 0.6f);
130 SAVE_RESTORE_AMOUNT(SaturatingBrightness, SATURATING_BRIGHTNESS, 0.6f);
131 SAVE_RESTORE_OFFSET_AMOUNT_COLOR(
132 DropShadow, DROP_SHADOW, gfx::Point(3, 4), 0.4f, 0xffffff00);
133
134 SkScalar matrix[20] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
135 17, 18, 19, 20};
136 SAVE_RESTORE_MATRIX(ColorMatrix, COLOR_MATRIX, matrix);
137
138 SAVE_RESTORE_AMOUNT_INSET(Zoom, ZOOM, 0.5f, 32);
139 }
140
141 } // namespace
142 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/filter_operations.cc ('k') | cc/output/gl_renderer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698