<!DOCTYPE HTML>
<html>
<head>
  <title>Test for HTMLButtonElement attributes reflection</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="../reflect.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">

/** Test for HTMLButtonElement attributes reflection **/

// .autofocus
reflectBoolean({
  element: document.createElement("button"),
  attribute: "autofocus",
});

// .disabled
reflectBoolean({
  element: document.createElement("button"),
  attribute: "disabled",
});

// .formAction
reflectURL({
  element: document.createElement("button"),
  attribute: "formAction",
});

// .formEnctype
reflectLimitedEnumerated({
  element: document.createElement("button"),
  attribute: "formEnctype",
  validValues: [
    "application/x-www-form-urlencoded",
    "multipart/form-data",
    "text/plain",
  ],
  invalidValues: [ "text/html", "", "tulip" ],
  defaultValue: {
    invalid: "application/x-www-form-urlencoded",
    missing: "",
  }
});

// .formMethod
add_task(async function() {
  await SpecialPowers.pushPrefEnv({ set: [["dom.dialog_element.enabled", false]] })
  reflectLimitedEnumerated({
    element: document.createElement("button"),
    attribute: "formMethod",
    validValues: [ "get", "post" ],
    invalidValues: [ "put", "", "tulip" ],
    unsupportedValues: [ "dialog" ],
    defaultValue: {
      invalid: "get",
      missing: "",
    }
  });
});

// .formMethod when dialog is enabled
add_task(async function() {
  await SpecialPowers.pushPrefEnv({ set: [["dom.dialog_element.enabled", true]] })
  reflectLimitedEnumerated({
    element: document.createElement("button"),
    attribute: "formMethod",
    validValues: [ "get", "post", "dialog"],
    invalidValues: [ "put", "", "tulip" ],
    defaultValue: {
      invalid: "get",
      missing: "",
    }
  });
});

// .formNoValidate
reflectBoolean({
  element: document.createElement("button"),
  attribute: "formNoValidate",
});

// .formTarget
reflectString({
  element: document.createElement("button"),
  attribute: "formTarget",
  otherValues: [ "_blank", "_self", "_parent", "_top" ],
});

// .name
reflectString({
  element: document.createElement("button"),
  attribute: "name",
  otherValues: [ "isindex", "_charset_" ]
});

// .type
reflectLimitedEnumerated({
  element: document.createElement("button"),
  attribute: "type",
  validValues: [ "submit", "reset", "button" ],
  invalidValues: [ "this-is-probably-a-wrong-type", "", "tulip" ],
  unsupportedValues: [ "menu" ],
  defaultValue: "submit",
});

// .value
reflectString({
  element: document.createElement("button"),
  attribute: "value",
});

// .willValidate
ok("willValidate" in document.createElement("button"),
   "willValidate should be an IDL attribute of the button element");
is(typeof(document.createElement("button").willValidate), "boolean",
   "button.willValidate should be a boolean");

// .validity
ok("validity" in document.createElement("button"),
   "validity should be an IDL attribute of the button element");
is(typeof(document.createElement("button").validity), "object",
   "button.validity should be an object");
ok(document.createElement("button").validity instanceof ValidityState,
   "button.validity sohuld be an instance of ValidityState");

// .validationMessage
ok("validationMessage" in document.createElement("button"),
   "validationMessage should be an IDL attribute of the button element");
is(typeof(document.createElement("button").validationMessage), "string",
   "button.validationMessage should be a string");

// .checkValidity()
ok("checkValidity" in document.createElement("button"),
   "checkValidity() should be a method of the button element");
is(typeof(document.createElement("button").checkValidity), "function",
   "button.checkValidity should be a function");

// .setCustomValidity()
ok("setCustomValidity" in document.createElement("button"),
   "setCustomValidity() should be a method of the button element");
is(typeof(document.createElement("button").setCustomValidity), "function",
   "button.setCustomValidity should be a function");

// .labels
ok("labels" in document.createElement("button"),
   "button.labels should be an IDL attribute of the button element");
is(typeof(document.createElement("button").labels), "object",
   "button.labels should be an object");
ok(document.createElement("button").labels instanceof NodeList,
   "button.labels sohuld be an instance of NodeList");
</script>
</pre>
</body>
</html>
