File: lang-attribute-update.html

package info (click to toggle)
firefox-esr 140.3.1esr-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 4,539,016 kB
  • sloc: cpp: 7,380,478; javascript: 6,388,099; ansic: 3,710,142; python: 1,393,715; xml: 628,165; asm: 426,918; java: 184,025; sh: 65,742; makefile: 19,302; objc: 13,059; perl: 12,912; yacc: 4,583; cs: 3,846; pascal: 3,352; lex: 1,720; ruby: 1,226; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (51 lines) | stat: -rw-r--r-- 2,005 bytes parent folder | download | duplicates (8)
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
<!DOCTYPE html>
<html>
<meta charset=utf-8>
<link rel="help" href="https://github.com/WICG/PEPC/blob/main/explainer.md#locking-the-pepc-style">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<body>
  <div id="el1" lang="en">
    <div id="el2" lang="en">
      <div>
        <permission id="permission-element" type="geolocation" style="width:fit-content"></permission>
      </div>
    </div>
  </div>

<script>
  // Since the `lang` attribute is inherited, but the actual inherited value
  // isn't available via IDL, there's no direct way to check that it gets
  // invalidated and updated when changes are made. As such, this test looks
  // for side-effects of changing the language, such as changing the rendered
  // size of the element.
  promise_test(async() => {
    var permission_element = document.getElementById("permission-element");
    const initial_width = permission_element.offsetWidth;
    let widths = new Set();
    widths.add(initial_width);
    const outer_lang_div = document.getElementById("el1");
    const inner_lang_div = document.getElementById("el2");

    // Changing the lang of the outer div should not have any effect as it is
    // shadowed by the inner div.
    outer_lang_div.lang = "de";
    assert_equals(permission_element.offsetWidth, initial_width);

    // The width of the permission element should change due to the changed
    // language of the inner element. Try a couple languages to make sure one
    // of them has a different size.
    ['de','hu','fr-AG','es'].forEach(lang => {
      inner_lang_div.lang = lang;
      widths.add(permission_element.offsetWidth);
    });
    assert_true(widths.size > 1);

  }, "Permission element should dynamically change text when the lang \
      attribute changes")
</script>
</body>
</html>