PageRenderTime 516ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/third_party/blink/web_tests/external/wpt/html/semantics/forms/attributes-common-to-form-controls/disabled-elements-01.html

https://github.com/chromium/chromium
HTML | 84 lines | 69 code | 15 blank | 0 comment | 0 complexity | cef9f57a6cebf456bee1d9490548ece8 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, Apache-2.0, BSD-3-Clause
  1. <!DOCTYPE html>
  2. <title>HTMLFormElement: the disabled attribute</title>
  3. <link rel="author" title="Eric Casler" href="mailto:ericorange@gmail.com">
  4. <link rel="help" href="https://html.spec.whatwg.org/multipage/#enabling-and-disabling-form-controls:-the-disabled-attribute">
  5. <script src=/resources/testharness.js></script>
  6. <script src=/resources/testharnessreport.js></script>
  7. <div id="log"></div>
  8. <div id="root"></div>
  9. <script>
  10. // Elements tested for in this file
  11. var types = ["button", "input", "select", "textarea"];
  12. // no tests for: optgroup, option, fieldset
  13. var root = document.getElementById("root");
  14. for (var element_type = 0; element_type < types.length; element_type++) {
  15. test(function() {
  16. root.innerHTML = "<"+types[element_type]+" + id='elem'></"+types[element_type]+">";
  17. var elem = document.getElementById("elem");
  18. assert_false(elem.disabled);
  19. },
  20. "Test ["+types[element_type]+"]: default behaviour is NOT disabled");
  21. test(function() {
  22. var formats = ["disabled",
  23. "disabled=disabled", "disabled='disabled'",
  24. "disabled='true'", "disabled=true",
  25. "disabled='false'", "disabled=false"];
  26. for (var f = 0; f < formats.length; f++) {
  27. root.innerHTML = "<"+types[element_type]+" id='elem' " + formats[f] + "></"+types[element_type]+">";
  28. var elem = document.getElementById("elem");
  29. assert_true(elem.disabled);
  30. }
  31. },
  32. "Test ["+types[element_type]+"]: verify disabled acts as boolean attribute");
  33. test(function() {
  34. root.innerHTML = "<"+types[element_type]+" id='elem'></"+types[element_type]+"><input id='other' value='no event dispatched'></input>";
  35. var elem = document.getElementById("elem"),
  36. other = document.getElementById("other");
  37. assert_equals(other.value, "no event dispatched");
  38. elem.disabled = true;
  39. assert_true(elem.disabled);
  40. elem.onclick = function () {
  41. // change value of other element, to avoid *.value returning "" for disabled elements
  42. document.getElementById("other").value = "event dispatched";
  43. };
  44. // Check if dispatched event executes
  45. var evObj = document.createEvent('Events');
  46. evObj.initEvent("click", true, false);
  47. elem.dispatchEvent(evObj);
  48. assert_equals(other.value, "event dispatched");
  49. },
  50. "Test ["+types[element_type]+"]: synthetic click events should be dispatched");
  51. test(function() {
  52. root.innerHTML = "<"+types[element_type]+" id='elem'></"+types[element_type]+"><input id='other' value='no event dispatched'></input>";
  53. var elem = document.getElementById("elem"),
  54. other = document.getElementById("other");
  55. assert_equals(other.value, "no event dispatched");
  56. elem.disabled = true;
  57. assert_true(elem.disabled);
  58. elem.onclick = function () {
  59. // change value of other element, to avoid *.value returning "" for disabled elements
  60. document.getElementById("other").value = "event dispatched";
  61. };
  62. // Check that click() on a disabled element doesn't dispatch a click event.
  63. elem.click();
  64. assert_equals(other.value, "no event dispatched");
  65. },
  66. "Test ["+types[element_type]+"]: click() should not dispatch a click event");
  67. }
  68. root.innerHTML = "";
  69. </script>