tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

edit-context-property.tentative.html (4904B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <title>EditContext: The HTMLElement.editContext property</title>
      5 <meta name="author" title="Dan Clark" href="mailto:daniec@microsoft.com">
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <script src='../../html/resources/common.js'></script>
      9 </head>
     10 <body>
     11 <script>
     12 
     13 test(function () {
     14  assert_true('editContext' in HTMLElement.prototype, 'Element.prototype.editContext must exist');
     15  assert_equals(typeof(document.createElement('div').editContext), 'object', 'An instance of div must have editContext which is an object');
     16 }, 'Check the existence of HTMLElement.editContext');
     17 
     18 test(function () {
     19  assert_false('editContext' in Node.prototype, 'Node.prototype.editContext must not exist');
     20  assert_false('editContext' in Element.prototype, 'Element.prototype.editContext must not exist');
     21  assert_false('editContext' in CharacterData.prototype, 'CharacterData.prototype.editContext must not exist');
     22  assert_false('editContext' in Comment.prototype, 'Comment.prototype.editContext must not exist');
     23  assert_equals(typeof(document.createComment('').editContext), 'undefined', 'An instance of comment must not have editContext');
     24  assert_false('editContext' in Document.prototype, 'Document.prototype.editContext must not exist');
     25  assert_equals(typeof(document.editContext), 'undefined', 'An instance of document must not have editContext which is a function');
     26  assert_false('editContext' in DocumentFragment.prototype, 'DocumentFragment.prototype.editContext must not exist');
     27  assert_equals(typeof((new DOMParser()).parseFromString('', 'text/html').editContext), 'undefined', 'An instance of document must not have editContext which is a function');
     28  assert_false('editContext' in Text.prototype, 'Text.prototype.editContext must not exist');
     29  assert_equals(typeof(document.createTextNode('').editContext), 'undefined', 'An instance of text node must not have editContext');
     30 }, 'Nodes other than Element should not have editContext');
     31 
     32 test(function () {
     33  assert_throws_js(TypeError, function () {
     34    document.createElement('div').editContext = "hello";
     35  }, 'editContext must throw a TypeError when set to a string');
     36 
     37  assert_throws_js(TypeError, function () {
     38    document.createElement('div').editContext = 42;
     39  }, 'editContext must throw a TypeError when set to a number');
     40 
     41  assert_throws_js(TypeError, function () {
     42    document.createElement('div').editContext = document.createElement('span');
     43  }, 'editContext must throw a TypeError when set to a node');
     44 }, 'HTMLElement.editContext must throw a TypeError if set to something other than an EditContext');
     45 
     46 test(function () {
     47  const EDIT_CONTEXT_ALLOWED_ELEMENTS = HTML5_SHADOW_ALLOWED_ELEMENTS.concat(['canvas']);
     48  for (const elementName of EDIT_CONTEXT_ALLOWED_ELEMENTS) {
     49    const element = document.createElement(elementName);
     50    const ec = new EditContext();
     51    element.editContext = ec;
     52    assert_equals(element.editContext, ec, 'Getting HTMLElement.editContext should yield the same EditContext instance');
     53  }
     54 }, 'HTMLElement.editContext can be set on the shadow root elements plus canvas.');
     55 
     56 test(function () {
     57  // EditContext shares all of the shadow root disallowed elements except for canvas.
     58  const EDIT_CONTEXT_DISALLOWED_ELEMENTS = HTML5_SHADOW_DISALLOWED_ELEMENTS.toSpliced(HTML5_SHADOW_DISALLOWED_ELEMENTS.indexOf('canvas'), 1);
     59  for (const elementName of EDIT_CONTEXT_DISALLOWED_ELEMENTS) {
     60    const element = document.createElement(elementName);
     61    const ec = new EditContext();
     62    assert_throws_dom('NotSupportedError', () => {
     63      element.editContext = ec;
     64    }, `Setting editContext on <${elementName}> must throw.`);
     65    assert_equals(element.editContext, null);
     66  }
     67 }, 'Setting HTMLElement.editContext must throw a NotSupportedError for disallowed elements');
     68 
     69 test(function () {
     70  const element1 = document.createElement('div');
     71  const element2 = document.createElement('div');
     72  const editContext1 = new EditContext();
     73  const editContext2 = new EditContext();
     74  element1.editContext = editContext1;
     75  assert_throws_dom('NotSupportedError', () => {
     76    element2.editContext = editContext1;
     77  }, `TypeError should be thrown when author attempts to associate an EditContext with a second element`);
     78  assert_equals(element1.editContext, editContext1, "element1 association should not have changed");
     79  assert_equals(element2.editContext, null, "element2 association should not have changed");
     80 
     81  element1.editContext = editContext2;
     82  assert_equals(element1.editContext, editContext2, "Association can be switched directly to second EditContext");
     83 
     84  element1.editContext = editContext2;
     85  assert_equals(element1.editContext, editContext2, "Assigning to the same EditContext again is a no-op");
     86 }, 'An EditContext can only be associated with one element at a time');
     87 
     88 </script>
     89 </body>
     90 </html>