1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
<!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 should be true.");
assert_true(evt.bubbles, "The bubbles attribute of the submit event should be true.");
assert_true(evt.cancelable, "The cancelable attribute of the submit event should 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 should be true.");
assert_true(evt.bubbles, "The bubbles attribute of the reset event should be true.");
assert_true(evt.cancelable, "The cancelable attribute of the reset event should 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 should 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 should 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>
|