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

Side by Side Diff: third_party/WebKit/LayoutTests/typedcssom/cssCalcLength.html

Issue 2867883003: [CSS Typed OM] Delete obsolete number and length classes from Typed OM (Closed)
Patch Set: rebase Created 3 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
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <script src='../resources/testharness.js'></script>
3 <script src='../resources/testharnessreport.js'></script>
4
5 <script>
6 test(function() {
7 assert_throws(null, function() { new CSSCalcLength(); });
8 assert_throws(null, function() { new CSSCalcLength({}); });
9 assert_throws(null, function() { new CSSCalcLength({foo: 1}); });
10 }, 'Passing invalid arguments to CSSCalcLength throws an exception.');
11
12 test(function() {
13 var calcLength1 = new CSSCalcLength({px: 1, percent: 2.2});
14 var calcLength2 = new CSSCalcLength({px: 3, percent: 4.3});
15
16 var result = calcLength1.add(calcLength2);
17
18 assert_not_equals(calcLength1, result);
19 assert_not_equals(calcLength2, result);
20 assert_equals(result.constructor.name, CSSCalcLength.name);
21 assert_equals(result.px, 4);
22 assert_equals(result.percent, 6.5);
23 }, 'Adding two CSSCalcLengths produces a new CSSCalcLength with the correct valu e.');
24
25 test(function() {
26 var calcLength1 = new CSSCalcLength({px: 1, percent: 2.2});
27 var calcLength2 = new CSSCalcLength({px: 3, percent: 4.3});
28
29 var result = calcLength1.subtract(calcLength2);
30
31 assert_not_equals(calcLength1, result);
32 assert_not_equals(calcLength2, result);
33 assert_equals(result.constructor.name, CSSCalcLength.name);
34 assert_equals(result.px, -2);
35 assert_approx_equals(result.percent, -2.1, 0.000001);
36 }, 'Subtracting two CSSCalcLengths produces a new CSSCalcLength with the correct values.');
37
38 test(function() {
39 var calcLength = new CSSCalcLength({px: 1, percent: 5.2});
40 var result = calcLength.multiply(3);
41
42 assert_not_equals(calcLength, result);
43 assert_equals(result.px, 3);
44 assert_approx_equals(result.percent, 15.6, 0.000001);
45 }, 'Multiplying a CSSCalcLength produces a new CSSCalcLength with the correct va lues.');
46
47 test(function() {
48 var calcLength = new CSSCalcLength({px: 3, percent: 15.6});
49 var result = calcLength.divide(3);
50
51 assert_not_equals(calcLength, result);
52 assert_equals(result.px, 1);
53 assert_equals(result.percent, 5.2);
54 }, 'Dividing a CSSCalcLength produces a new CSSCalcLength with the correct value s.');
55
56 test(function() {
57 var calcLength = new CSSCalcLength({px: 4, percent: 1});
58 assert_throws(new RangeError(), function() { calcLength.divide(0); });
59 }, 'Dividing by zero throws a RangeError');
60
61 test(function() {
62 var values = [
63 {input: new CSSCalcLength({px: 1}), cssText: 'calc(1px)'},
64 {input: new CSSCalcLength({px: -1}), cssText: 'calc(-1px)'},
65 {input: new CSSCalcLength({px: 1, percent: 15.6}), cssText: 'calc(15.6% + 1p x)'},
66 {input: new CSSCalcLength({px: 1, percent: -15.6}), cssText: 'calc(-15.6% + 1px)'},
67 {input: new CSSCalcLength({px: -1, percent: -15.6}), cssText: 'calc(-15.6% - 1px)'},
68 {input: new CSSCalcLength({px: -1, percent: -15.6, vw: 5}), cssText: 'calc(( -15.6% - 1px) + 5vw)'},
69 {input: new CSSCalcLength({px: -1, percent: -15.6, vw: -5}), cssText: 'calc( (-15.6% - 1px) - 5vw)'},
70 ];
71
72 for (var i = 0; i < values.length; ++i) {
73 assert_equals(values[i].input.cssText, values[i].cssText);
74 }
75
76 }, 'cssText produces the correct string');
77
78 </script>
79
80 <body>
81 </body>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698