File: rellist-feature-detection.html

package info (click to toggle)
thunderbird 1%3A60.9.0-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,339,492 kB
  • sloc: cpp: 5,457,040; ansic: 2,360,385; python: 596,167; asm: 340,963; java: 326,296; xml: 258,830; sh: 84,445; makefile: 23,705; perl: 17,317; objc: 3,768; yacc: 1,766; ada: 1,681; lex: 1,364; pascal: 1,264; cs: 879; exp: 527; php: 436; lisp: 258; ruby: 153; awk: 152; sed: 53; csh: 27
file content (80 lines) | stat: -rw-r--r-- 4,092 bytes parent folder | download | duplicates (2)
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
<!DOCTYPE html>
<title>Test relList attribute</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
let link_support_table = {};
// https://html.spec.whatwg.org/multipage/links.html#linkTypes
link_support_table['link'] = {
  supported : ['modulepreload', 'preload', 'preconnect', 'dns-prefetch',
               'stylesheet', 'import', 'icon', 'alternate', 'prefetch',
               'prerender', 'next', 'manifest', 'apple-touch-icon',
               'apple-touch-icon-precomposed', 'canonical'],
  unsupported : ['author', 'bookmark', 'external', 'help', 'license',
                 'nofollow', 'pingback', 'prev', 'search', 'tag',
                 'noreferrer', 'noopener']
};
link_support_table['a'] =  {
  supported : ['noreferrer', 'noopener'],
  unsupported : ['author', 'bookmark', 'external', 'help', 'license',
                 'nofollow', 'pingback', 'prev', 'search', 'tag',
                 'modulepreload', 'preload', 'preconnect', 'dns-prefetch',
                 'stylesheet', 'import', 'icon', 'alternate', 'prefetch',
                 'prerender', 'next', 'manifest', 'apple-touch-icon',
                 'apple-touch-icon-precomposed', 'canonical']
};
link_support_table['area'] = link_support_table['a'];

function test_rellist(tag_name, rel_table) {
  let element = document.createElement(tag_name);
  let tag = element.tagName;
  // Test that setting rel is also setting relList, for both
  // valid and invalid values.
  element.rel = 'whatever';
  assert_true(element.relList.contains('whatever'), 'tag = ' + tag + ', setting rel must work');
  element.rel = 'prefetch';
  assert_true(element.relList.contains('prefetch'), 'tag = ' + tag + ', setting rel must work');
  // Test that add() works.
  element.relList.add('preloadwhatever');
  assert_equals(element.rel, 'prefetch preloadwhatever', 'tag = ' + tag + ', add must work');
  assert_true(element.relList.contains('preloadwhatever'), 'tag = ' + tag + ', add must work');
  // Test that remove() works.
  element.relList.remove('preloadwhatever');
  assert_equals(element.rel, 'prefetch', 'tag = ' + tag + ', remove must work');
  assert_false(element.relList.contains('preloadwhatever'), 'tag = ' + tag + ', remove must work');
  // Test that toggle() works.
  element.relList.toggle('prefetch', false);
  assert_equals(element.rel, '', 'tag = ' + tag + ', toggle must work');
  element.relList.toggle('prefetch', true);
  assert_equals(element.rel, 'prefetch', 'tag = ' + tag + ', toggle must work');
  // Test that replace() works.
  element.relList.replace('prefetch', 'first');
  assert_equals(element.rel, 'first', 'tag = ' + tag + ', replace must work');
  // Test that indexed item getter works.
  element.relList.add('second');
  assert_equals(element.relList.length, 2, 'tag = ' + tag + ', relList length must be correct');
  assert_equals(element.relList[0], 'first', 'tag = ' + tag + ', relList indexed item must work');
  assert_equals(element.relList[1], 'second', 'tag = ' + tag + ', relList indexed item must work');
  // Test that relList is  [SameObject].
  let savedRelList = element.relList;
  element.rel = 'something';
  assert_equals(element.relList, savedRelList, 'tag = ' + tag + ', SameObject must work');

  // Test that supports() is returning true for valid values
  // and false for invalid ones.
  let supported = rel_table['supported'];
  for (let link_type in supported) {
    assert_true(element.relList.supports(supported[link_type]), 'tag = ' + tag + ', link type = ' + supported[link_type] + ' must be supported');
  }
  let unsupported = rel_table['unsupported'];
  for (let link_type in unsupported) {
    assert_false(element.relList.supports(unsupported[link_type]), 'tag = ' + tag + ', link type = ' + unsupported[link_type] + ' must be unsupported');
  }
}

test(function() {
  test_rellist('LINK', link_support_table['link']);
  test_rellist('A', link_support_table['a']);
  test_rellist('AREA', link_support_table['area']);
}, 'Make sure that relList based feature detection is working');
</script>