| <!DOCTYPE html> |
| <meta charset="utf-8"> |
| <title>HTML Test: Button - events</title> |
| <link rel="author" title="Intel" href="http://www.intel.com/"> |
| <link rel="help" href="https://html.spec.whatwg.org/multipage/#the-button-element"> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| <div id="log"></div> |
| <form name="fm1" style="display:none"> |
| <button id="btn">BUTTON</button> |
| <button id="menu_btn" type="menu" menu="menu">MENU BUTTON</button> |
| <menu id="menu" label="MENU"> |
| <li>Menu item</li> |
| </menu> |
| </form> |
| <script> |
| |
| var btn = document.getElementById("btn"), |
| menu_btn = document.getElementById("menu_btn"), |
| t1 = async_test("The submit event must be fired when click a button in submit status"), |
| t2 = async_test("The reset event must be fired when click a button in reset status"), |
| t3 = async_test("The show event must be fired when click a button in menu status"); |
| |
| document.forms.fm1.onsubmit = t1.step_func(function (evt) { |
| evt.preventDefault(); |
| assert_true(evt.isTrusted, "The isTrusted attribute of the submit event shoud be true."); |
| assert_true(evt.bubbles, "The bubbles attribute of the submit event shoud be true."); |
| assert_true(evt.cancelable, "The cancelable attribute of the submit event shoud be true."); |
| assert_true(evt instanceof Event, "The submit event is an instance of Event interface."); |
| t1.done(); |
| }); |
| |
| document.forms.fm1.onreset = t2.step_func(function (evt) { |
| assert_true(evt.isTrusted, "The isTrusted attribute of the reset event shoud be true."); |
| assert_true(evt.bubbles, "The bubbles attribute of the reset event shoud be true."); |
| assert_true(evt.cancelable, "The cancelable attribute of the reset event shoud be true."); |
| assert_true(evt instanceof Event, "The reset event is an instance of Event interface."); |
| t2.done(); |
| }); |
| |
| document.getElementById("menu").onshow = t3.step_func(function (evt) { |
| assert_true(evt.isTrusted, "The isTrusted attribute of the show event shoud be true."); |
| assert_equals(evt.relatedTarget, menu_btn, "The relatedTarget attribute should be initialized to the related button element."); |
| assert_true(evt.cancelable, "The cancelable attribute of the show event shoud be true."); |
| assert_true(evt instanceof RelatedEvent, "The show event is an instance of RelatedEvent interface."); |
| t3.done(); |
| }); |
| |
| t1.step(function () { |
| btn.type = "submit"; |
| assert_equals(btn.type, "submit", "The button type should be 'submit'."); |
| btn.click(); |
| }); |
| |
| t2.step(function () { |
| btn.type = "reset"; |
| assert_equals(btn.type, "reset", "The button type should be 'reset'."); |
| btn.click(); |
| }); |
| |
| t3.step(function () { |
| assert_equals(menu_btn.type, "menu", "The button type should be 'menu'."); |
| menu_btn.click(); |
| }); |
| |
| </script> |