summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/align.html
blob: b5f3ec1aa62d8238628409fcda14b189e7ed2a65 (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
<!doctype html>
<title>align attribute mapping on replaced elements</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<img id="replaced" src="/images/green.png">
<something id="non-replaced"></something>
<script>
const kMapping = {
  "left": ["float", "left"],
  "right": ["float", "right"],

  "top": ["vertical-align", "top"],

  // This one requires a magic value (`-moz-middle-with-baseline` on Gecko,
  // `-webkit-baseline-middle` on WebKit-based browsers).
  "middle": ["vertical-align", undefined],
  // These are inconsistent across browsers. WebKit maps it to "middle", Gecko
  // to the aforementioned value.
  "center": ["vertical-align", undefined],

  "baseline": ["vertical-align", "baseline"],
  "bottom": ["vertical-align", "baseline"], // *shrug*

  "texttop": ["vertical-align", "text-top"],
  "absmiddle": ["vertical-align", "middle"],
  "abscenter": ["vertical-align", "middle"],
  "absbottom": ["vertical-align", "bottom"],
};

const kInitialValues = {
  "vertical-align": "baseline",
  "float": "none",
};

let replaced = document.getElementById("replaced");
let nonReplaced = document.getElementById("non-replaced");
let t = async_test("align attribute mapping");
onload = t.step_func_done(function() {
  for (const attributeValue in kMapping) {
    for (const element of [replaced, nonReplaced]) {
      test(function() {
        element.setAttribute("align", attributeValue);
        let [property, expected] = kMapping[attributeValue];
        let actual = getComputedStyle(element).getPropertyValue(property);
        if (element == nonReplaced) {
          assert_equals(actual, kInitialValues[property], "align shouldn't map to non-replaced elements")
        } else {
          if (expected) {
            assert_equals(actual, expected, `align=${attributeValue} should map to ${property}: ${expected}`);
          } else {
            assert_equals(property, "vertical-align");
            assert_not_equals(actual, "baseline", `align=${attributeValue} should map a vertical-align value`);
          }
        }
      }, `align=${attributeValue} on ${element == replaced ? "replaced" : "non-replaced"} elements`);
    }
  }
});
</script>