summaryrefslogtreecommitdiffstats
path: root/layout/style/test/test_specified_value_serialization.html
blob: cb7e67dda780b9091928cd06be40bc0b779db437 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<!doctype html>
<html>
<head>
  <title>Test for miscellaneous specified value issues</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
<p id="display"></p>
<div id="content" style="display: none">
</div>

<pre id="test">
<script type="application/javascript">

(function test_bug_721136() {
  // Test for transform property serialization.
  [
    [" mAtRiX(1, 2,3,4, 5,6 ) ", "matrix(1, 2, 3, 4, 5, 6)"],
    [" mAtRiX3d( 1,2,3,0,4 ,5,6,0,7,8 , 9,0,10, 11,12,1 )  ",
     "matrix3d(1, 2, 3, 0, 4, 5, 6, 0, 7, 8, 9, 0, 10, 11, 12, 1)"],
    [" pErSpEcTiVe( 400Px ) ", "perspective(400px)"],
    [" rOtAtE( 90dEg ) ", "rotate(90deg)"],
    [" rOtAtE3d( 0,0 , 1 ,180DeG ) ", "rotate3d(0, 0, 1, 180deg)"],
    [" rOtAtEx( 100GrAD ) ", "rotateX(100grad)"],
    [" rOtAtEy( 1.57RaD ) ", "rotateY(1.57rad)"],
    [" rOtAtEz( 0.25TuRn ) ", "rotateZ(0.25turn)"],
    [" sCaLe( 2 ) ", "scale(2)"],
    [" sCaLe( 2,3 ) ", "scale(2, 3)"],
    [" sCaLe3D( 2,4 ,  -9 )  ", "scale3d(2, 4, -9)"],
    [" sCaLeX( 2 ) ", "scaleX(2)"],
    [" sCaLeY( 2 ) ", "scaleY(2)"],
    [" sCaLeZ( 2 ) ", "scaleZ(2)"],
    [" sKeW( 45dEg ) ", "skew(45deg)"],
    [" sKeW( 45dEg,45DeG ) ", "skew(45deg, 45deg)"],
    [" sKeWx( 45DeG ) ", "skewX(45deg)"],
    [" sKeWy( 45DeG ) ", "skewY(45deg)"],
    [" tRaNsLaTe( 1Px ) ", "translate(1px)"],
    [" tRaNsLaTe( 1Px,3Pt ) ", "translate(1px, 3pt)"],
    [" tRaNsLaTe3D( 21pX,-6pX , 4pX )  ", "translate3d(21px, -6px, 4px)"],
    [" tRaNsLaTeX( 1pT ) ", "translateX(1pt)"],
    [" tRaNsLaTeY( 1iN ) ", "translateY(1in)"],
    [" tRaNsLaTeZ( 15.4pX ) ", "translateZ(15.4px)"],
    ["tranSlatex( 16px )rotatez(-90deg)  rotate(100grad)\ttranslate3d(12pt, 0pc, 0.0em)",
     "translateX(16px) rotateZ(-90deg) rotate(100grad) translate3d(12pt, 0pc, 0em)"],
  ].forEach(function(arr) {
    document.documentElement.style.MozTransform = arr[0];
    is(document.documentElement.style.MozTransform, arr[1],
      "bug-721136 incorrect serialization");
  });

  var elt = document.documentElement;

  elt.setAttribute("style",
                   "transform: tRANslatEX(5px) TRanslATey(10px) translatez(2px) ROTATEX(30deg) rotateY(30deg) rotatez(5deg) SKEWx(10deg) skewy(10deg) scaleX(2) SCALEY(0.5) scalez(2)");
  is(elt.style.getPropertyValue("transform"),
     "translateX(5px) translateY(10px) translateZ(2px) rotateX(30deg) rotateY(30deg) rotateZ(5deg) skewX(10deg) skewY(10deg) scaleX(2) scaleY(0.5) scaleZ(2)",
     "bug-721136 expected case canonicalization of transform functions");

  elt.setAttribute("style",
                   "font-variant-alternates: SWASH(fOo) stYLIStiC(Bar)");
  is(elt.style.getPropertyValue("font-variant-alternates"),
     "stylistic(Bar) swash(fOo)",
     "expected case and ordering canonicalization of font-variant-alternates functions");

  elt.setAttribute("style", ""); // leave the page in a useful state
})();

(function test_bug_1347164() {
  // Test that specified color values are serialized as "rgb()"
  // IFF they're fully-opaque (and otherwise as "rgba()").
  var color = [
    ["rgba(0, 0, 0, 1)", "rgb(0, 0, 0)"],
    ["rgba(0, 0, 0, 0.5)", "rgba(0, 0, 0, 0.5)"],
    ["hsla(0, 0%, 0%, 1)", "rgb(0, 0, 0)"],
    ["hsla(0, 0%, 0%, 0.5)", "rgba(0, 0, 0, 0.5)"],
  ];

  var css_color_4 = [
    ["rgba(0 0 0 / 1)", "rgb(0, 0, 0)"],
    ["rgba(0 0 0 / 0.1)", "rgba(0, 0, 0, 0.1)"],
    ["rgb(0 0 0 / 1)", "rgb(0, 0, 0)"],
    ["rgb(0 0 0 / 0.2)", "rgba(0, 0, 0, 0.2)"],
    ["hsla(0 0% 0% / 1)", "rgb(0, 0, 0)"],
    ["hsla(0deg 0% 0% / 0.3)", "rgba(0, 0, 0, 0.3)"],
    ["hsl(0 0% 0% / 1)", "rgb(0, 0, 0)"],
    ["hsl(0 0% 0% / 0.4)", "rgba(0, 0, 0, 0.4)"],
  ];

  var frame_container = document.getElementById("display");
  var p = document.createElement("p");
  frame_container.appendChild(p);

  for (var i = 0; i < color.length; ++i) {
    var test = color[i];
    p.style.color = test[0];
    is(p.style.color, test[1], "serialization value of " + test[0]);
  }
  for (var i = 0; i < css_color_4.length; ++i) {
    var test = css_color_4[i];
    p.style.color = test[0];
    is(p.style.color, test[1], "css-color-4 serialization value of " + test[0]);
  }

  p.remove();
})();

(function test_bug_1357117() {
  // Test that vendor-prefixed gradient styles round-trip with the same prefix,
  // or with no prefix.
  var backgroundImages = [
    // [ specified style,
    //   expected serialization,
    //   descriptionOfTestcase ],
    // Linear gradient with legacy-gradient-line (needs prefixed syntax):
    [ "-webkit-linear-gradient(10deg, red, blue)",
      "-webkit-linear-gradient(10deg, red, blue)",
      "-webkit-linear-gradient with angled legacy-gradient-line" ],

    // Linear gradient with box corner (needs prefixed syntax):
    [ "-webkit-linear-gradient(top left, red, blue)",
      "-webkit-linear-gradient(left top, red, blue)",
      "-webkit-linear-gradient with box corner" ],

    // Servo keeps the original prefix form which is closer to other impls.
    [ "-webkit-radial-gradient(contain, red, blue)",
      "-webkit-radial-gradient(closest-side, red, blue)",
      "-webkit-radial-gradient with legacy 'contain' keyword" ],
  ];

  var frame_container = document.getElementById("display");
  var p = document.createElement("p");
  frame_container.appendChild(p);

  for (var i = 0; i < backgroundImages.length; ++i) {
    var test = backgroundImages[i];
    p.style.backgroundImage = test[0];
    is(p.style.backgroundImage, test[1],
       "serialization value of prefixed gradient expression (" + test[2] + ")");
  }

  p.remove();
})();

(function test_bug_1357932() {
  // Test for box-position keyword ordering, in serialization of specified CSS
  // gradients.
  var backgroundImages = [
    // [ specified style,
    //   expected serialization,
    //   descriptionOfTestcase ],
    // Linear gradient to box position ordering:
    [ "linear-gradient(to right top, gray, pink)",
      "linear-gradient(to right top, gray, pink)",
      "linear-gradient ordering to right top" ],
    [ "linear-gradient(to top right, yellow, teal)",
      "linear-gradient(to right top, yellow, teal)",
      "linear-gradient ordering to top right" ],
  ];

  var frame_container = document.getElementById("display");
  var p = document.createElement("p");
  frame_container.appendChild(p);

  for (var i = 0; i < backgroundImages.length; ++i) {
    var test = backgroundImages[i];
    p.style.backgroundImage = test[0];
    is(p.style.backgroundImage, test[1],
       "serialization value of gradient expression (" + test[2] + ")");
  }

  p.remove();
})();

(function test_bug_1367028() {
  const borderImageSubprops = [
    "border-image-slice",
    "border-image-outset",
    "border-image-width"
  ];
  const rectValues = [
    {
      values: ["5 5 5 5", "5 5 5", "5 5", "5"],
      expected: "5",
      desc: "identical four sides",
    },
    {
      values: ["5 6 5 6", "5 6 5", "5 6"],
      expected: "5 6",
      desc: "identical values on each axis",
    },
    {
      values: ["5 6 7 6", "5 6 7"],
      expected: "5 6 7",
      desc: "identical values on left and right",
    },
    {
      values: ["5 6 5 7"],
      desc: "identical values on top and bottom",
    },
    {
      values: ["5 5 6 6", "5 6 6 5"],
      desc: "identical values on unrelated sides",
    },
    {
      values: ["5 6 7 8"],
      desc: "different values on all sides",
    },
  ];

  let frameContainer = document.getElementById("display");
  let p = document.createElement("p");
  frameContainer.appendChild(p);

  for (let prop of borderImageSubprops) {
    for (let {values, expected, desc} of rectValues) {
      for (let value of values) {
        p.style.setProperty(prop, value);
        is(p.style.getPropertyValue(prop),
           expected ? expected : value, `${desc} for ${prop}`);
        p.style.removeProperty(prop);
      }
    }
  }

  p.remove();
})();

(function test_bug_1397619() {
  var borderRadius = [
    // [ specified style,
    //   expected serialization,
    //   descriptionOfTestcase ],
    [ "10px 10px",
      "10px",
      "Width and height specified for " ],
    [ "10px",
      "10px",
      "Only width specified for " ],
  ];


  var frame_container = document.getElementById("display");
  var p = document.createElement("p");
  frame_container.appendChild(p);

  [
    "border-top-left-radius",
    "border-bottom-left-radius",
    "border-top-right-radius",
    "border-bottom-right-radius",
    "border-spacing",
  ].forEach(function(property) {
    for (var i = 0; i < borderRadius.length; ++i) {
      var test = borderRadius[i];
      p.style.setProperty(property, test[0]);
      is(p.style.getPropertyValue(property), test[1], test[2] + property);
    }
  });

  p.style.paintOrder = "markers";
  is(p.style.paintOrder, "markers",
     "specified value serialization for paint-order doesn't contain repetitive values");

  p.remove();
})();

SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv(
  {
    set: [['layout.css.individual-transform.enabled', true]],
  },
  () =>
    window.open('file_specified_value_serialization_individual_transforms.html')
);

</script>
</pre>
</body>
</html>