File: edit-context-property.tentative.html

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (91 lines) | stat: -rw-r--r-- 5,005 bytes parent folder | download
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
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html>
<head>
<title>EditContext: The HTMLElement.editContext property</title>
<meta name="author" title="Dan Clark" href="mailto:daniec@microsoft.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src='../../html/resources/common.js'></script>
<link rel="help" href="https://w3c.github.io/edit-context/#extensions-to-the-htmlelement-interface">
</head>
<body>
<script>

test(function () {
  assert_true('editContext' in HTMLElement.prototype, 'Element.prototype.editContext must exist');
  assert_equals(typeof(document.createElement('div').editContext), 'object', 'An instance of div must have editContext which is an object');
}, 'Check the existence of HTMLElement.editContext');

test(function () {
  assert_false('editContext' in Node.prototype, 'Node.prototype.editContext must not exist');
  assert_false('editContext' in Element.prototype, 'Element.prototype.editContext must not exist');
  assert_false('editContext' in CharacterData.prototype, 'CharacterData.prototype.editContext must not exist');
  assert_false('editContext' in Comment.prototype, 'Comment.prototype.editContext must not exist');
  assert_equals(typeof(document.createComment('').editContext), 'undefined', 'An instance of comment must not have editContext');
  assert_false('editContext' in Document.prototype, 'Document.prototype.editContext must not exist');
  assert_equals(typeof(document.editContext), 'undefined', 'An instance of document must not have editContext which is a function');
  assert_false('editContext' in DocumentFragment.prototype, 'DocumentFragment.prototype.editContext must not exist');
  assert_equals(typeof((new DOMParser()).parseFromString('', 'text/html').editContext), 'undefined', 'An instance of document must not have editContext which is a function');
  assert_false('editContext' in Text.prototype, 'Text.prototype.editContext must not exist');
  assert_equals(typeof(document.createTextNode('').editContext), 'undefined', 'An instance of text node must not have editContext');
}, 'Nodes other than Element should not have editContext');

test(function () {
  assert_throws_js(TypeError, function () {
    document.createElement('div').editContext = "hello";
  }, 'editContext must throw a TypeError when set to a string');

  assert_throws_js(TypeError, function () {
    document.createElement('div').editContext = 42;
  }, 'editContext must throw a TypeError when set to a number');

  assert_throws_js(TypeError, function () {
    document.createElement('div').editContext = document.createElement('span');
  }, 'editContext must throw a TypeError when set to a node');
}, 'HTMLElement.editContext must throw a TypeError if set to something other than an EditContext');

test(function () {
  const EDIT_CONTEXT_ALLOWED_ELEMENTS = HTML5_SHADOW_ALLOWED_ELEMENTS.concat(['canvas']);
  for (const elementName of EDIT_CONTEXT_ALLOWED_ELEMENTS) {
    const element = document.createElement(elementName);
    const ec = new EditContext();
    element.editContext = ec;
    assert_equals(element.editContext, ec, 'Getting HTMLElement.editContext should yield the same EditContext instance');
  }
}, 'HTMLElement.editContext can be set on the shadow root elements plus canvas.');

test(function () {
  // EditContext shares all of the shadow root disallowed elements except for canvas.
  const EDIT_CONTEXT_DISALLOWED_ELEMENTS = HTML5_SHADOW_DISALLOWED_ELEMENTS.toSpliced(HTML5_SHADOW_DISALLOWED_ELEMENTS.indexOf('canvas'), 1);
  for (const elementName of EDIT_CONTEXT_DISALLOWED_ELEMENTS) {
    const element = document.createElement(elementName);
    const ec = new EditContext();
    assert_throws_dom('NotSupportedError', () => {
      element.editContext = ec;
    }, `Setting editContext on <${elementName}> must throw.`);
    assert_equals(element.editContext, null);
  }
}, 'Setting HTMLElement.editContext must throw a NotSupportedError for disallowed elements');

test(function () {
  const element1 = document.createElement('div');
  const element2 = document.createElement('div');
  const editContext1 = new EditContext();
  const editContext2 = new EditContext();
  element1.editContext = editContext1;
  assert_throws_dom('NotSupportedError', () => {
    element2.editContext = editContext1;
  }, `TypeError should be thrown when author attempts to associate an EditContext with a second element`);
  assert_equals(element1.editContext, editContext1, "element1 association should not have changed");
  assert_equals(element2.editContext, null, "element2 association should not have changed");

  element1.editContext = editContext2;
  assert_equals(element1.editContext, editContext2, "Association can be switched directly to second EditContext");

  element1.editContext = editContext2;
  assert_equals(element1.editContext, editContext2, "Assigning to the same EditContext again is a no-op");
}, 'An EditContext can only be associated with one element at a time');

</script>
</body>
</html>