tor-browser

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

exec-command-never-throw-exceptions.tentative.html (2952B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title>Test that execCommand and related methods never throw exceptions if HTML or XHTML document</title>
      4 <script src=/resources/testharness.js></script>
      5 <script src=/resources/testharnessreport.js></script>
      6 <div contenteditable=""></div>
      7 <script>
      8 "use strict";
      9 
     10 const editor = document.querySelector("div[contenteditable]");
     11 
     12 test(function execCommand_with_unknown_command() {
     13  editor.innerHTML = "abc";
     14  editor.focus();
     15  try {
     16    let done = document.execCommand("unknown-command", false, "foo");
     17    assert_equals(done, false,
     18        "Should return false without throwing exception");
     19  } catch (e) {
     20    assert_true(false,
     21        "Shouldn't throw exception for unknown command");
     22  }
     23 }, "Testing execCommand with unknown command");
     24 
     25 test(function queryCommandEnabled_with_unknown_command() {
     26  editor.innerHTML = "abc";
     27  editor.focus();
     28  try {
     29    let enabled = document.queryCommandEnabled("unknown-command");
     30    assert_equals(enabled, false,
     31        "Should return false without throwing exception");
     32  } catch (e) {
     33    assert_true(false,
     34        "Shouldn't throw exception for unknown command");
     35  }
     36 }, "Testing queryCommandEnabled with unknown command");
     37 
     38 test(function queryCommandIndeterm_with_unknown_command() {
     39  editor.innerHTML = "abc";
     40  editor.focus();
     41  try {
     42    let indeterminate = document.queryCommandIndeterm("unknown-command");
     43    assert_equals(indeterminate, false,
     44        "Should return false without throwing exception");
     45  } catch (e) {
     46    assert_true(false,
     47        "Shouldn't throw exception for unknown command");
     48  }
     49 }, "Testing queryCommandIndeterm with unknown command");
     50 
     51 test(function queryCommandState_with_unknown_command() {
     52  editor.innerHTML = "abc";
     53  editor.focus();
     54  try {
     55    let state = document.queryCommandState("unknown-command");
     56    assert_equals(state, false,
     57        "Should return false without throwing exception");
     58  } catch (e) {
     59    assert_true(false,
     60        "Shouldn't throw exception for unknown command");
     61  }
     62 }, "Testing queryCommandState with unknown command");
     63 
     64 test(function queryCommandSupported_with_unknown_command() {
     65  editor.innerHTML = "abc";
     66  editor.focus();
     67  try {
     68    let supported = document.queryCommandSupported("unknown-command");
     69    assert_equals(supported, false,
     70        "Should return false without throwing exception");
     71  } catch (e) {
     72    assert_true(false,
     73        "Shouldn't throw exception for unknown command");
     74  }
     75 }, "Testing queryCommandSupported with unknown command");
     76 
     77 test(function queryCommandValue_with_unknown_command() {
     78  editor.innerHTML = "abc";
     79  editor.focus();
     80  try {
     81    let value = document.queryCommandValue("unknown-command");
     82    assert_equals(value, "",
     83        "Should return empty string without throwing exception");
     84  } catch (e) {
     85    assert_true(false,
     86        "Shouldn't throw exception for unknown command");
     87  }
     88 }, "Testing queryCommandValue with unknown command");
     89 </script>