summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-values/calc-background-position-003.html
blob: a3f5e848620fdce416f006fbbc6cdcc06c69b317 (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
<!DOCTYPE html>

  <meta charset="UTF-8">

  <title>CSS Values and Units Test: serialization of 'background-position' when specified with calc() function</title>

  <link rel="author" title="Gérard Talbot" href="http://www.gtalbot.org/BrowserBugsSection/css21testsuite/">
  <link rel="help" href="https://www.w3.org/TR/css-values-4/#calc-serialize">

  <meta content="This test verifies how 6 calc() functions are serialized for 'background-position'." name="assert">

  <script src="/resources/testharness.js"></script>

  <script src="/resources/testharnessreport.js"></script>

  <div id="target"></div>

  <script>
  function startTesting()
  {

  var targetElement = document.getElementById("target");

    function verifySerialization(specified_value, serialization_expected, description)
    {

    test(function()
      {

      targetElement.style.backgroundPosition = specified_value;

      assert_equals(targetElement.style.backgroundPosition, serialization_expected);

      }, description);
    }

  /*
    verifySerialization(specified_value, serialization_expected, description)
  */

    verifySerialization("calc(2px + 3px) calc(4px + 5px)", "calc(5px) calc(9px)", "testing background-position: calc(2px + 3px) calc(4px + 5px)");

    verifySerialization("calc(18px - 7px) calc(19px - 7px)", "calc(11px) calc(12px)", "testing background-position: calc(18px - 7px) calc(19px - 7px)");

    verifySerialization("calc(4 * 5px) calc(6px * 4)", "calc(20px) calc(24px)", "testing background-position: calc(4 * 5px) calc(6px * 4)");

    verifySerialization("calc(100px / 4) calc(119px / 7)", "calc(25px) calc(17px)", "testing background-position: calc(100px / 4) calc(119px / 7)");

  /*
    verifySerialization(specified_value, serialization_expected, description)
  */

    verifySerialization("calc(6px + 21%) calc(7em + 22%)", "calc(21% + 6px) calc(22% + 7em)", "testing background-position: calc(6px + 21%) calc(7em + 22%)");

    verifySerialization("calc(-8px + 23%) calc(-9em + 24%)", "calc(23% - 8px) calc(24% - 9em)", "testing background-position: calc(-8px + 23%) calc(-9em + 24%)");

  /*

  "
  Sort the terms in the following order:

    The number, if present

    The percentage, if present

    The dimensions, ordered by their units ASCII case-insensitive alphabetically
  "
  https://www.w3.org/TR/css-values-4/#math-function-serialize-a-summation

  */

  }

  startTesting();

  </script>