OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <link rel="help" href="http://www.whatwg.org/specs/web-apps/current-work/multipa
ge/interactive-elements.html#attr-details-open"> | 4 <link rel="help" href="http://www.whatwg.org/specs/web-apps/current-work/multipa
ge/interactive-elements.html#attr-details-open"> |
5 <script src="../../resources/js-test.js"></script> | 5 <script src="../../resources/js-test.js"></script> |
6 </head> | 6 </head> |
7 <body> | 7 <body> |
8 <details id="details"> | 8 <details id="details" ontoggle="handleToggleEventFromHTMLAttribute(event)"> |
9 <summary>details</summary> | 9 <summary>details</summary> |
10 <input> | 10 <input> |
11 </details> | 11 </details> |
12 <script> | 12 <script> |
13 description("Tests that a 'toggle' event is fired asynchronously whenever the op
en attribute is added to or removed from a details element."); | 13 description("Tests that a 'toggle' event is fired asynchronously whenever the op
en attribute is added to or removed from a details element."); |
14 window.jsTestIsAsync = true; | 14 window.jsTestIsAsync = true; |
15 | 15 |
16 var toggleEventCount = 0; | 16 var toggleEventCount = 0; |
| 17 var toggleEventCountFromHTMLAttribute = 0; |
17 var testEvent; | 18 var testEvent; |
18 | 19 |
| 20 function handleToggleEventFromHTMLAttribute(ev) { |
| 21 testEvent = ev; |
| 22 shouldBe("testEvent.__proto__", "Event.prototype"); |
| 23 shouldBeEqualToString("testEvent.type", "toggle"); |
| 24 ++toggleEventCountFromHTMLAttribute; |
| 25 } |
| 26 |
19 function handleToggleEvent(ev) { | 27 function handleToggleEvent(ev) { |
20 testEvent = ev; | 28 testEvent = ev; |
21 shouldBe("testEvent.__proto__", "Event.prototype"); | 29 shouldBe("testEvent.__proto__", "Event.prototype"); |
22 shouldBeEqualToString("testEvent.type", "toggle"); | 30 shouldBeEqualToString("testEvent.type", "toggle"); |
23 ++toggleEventCount; | 31 ++toggleEventCount; |
24 } | 32 } |
25 | 33 |
26 function checkSingleToggleEvent() { | 34 function checkSingleToggleEvent() { |
27 shouldBe("toggleEventCount", "1"); | 35 shouldBe("toggleEventCount", "1"); |
| 36 shouldBe("toggleEventCountFromHTMLAttribute", "1"); |
28 shouldBeTrue("details.open"); | 37 shouldBeTrue("details.open"); |
29 testEventsCoalesced(); | 38 testEventsCoalesced(); |
30 } | 39 } |
31 | 40 |
32 function testToogleEventFired() { | 41 function testToogleEventFired() { |
33 shouldBe("toggleEventCount", "0"); | 42 shouldBe("toggleEventCount", "0"); |
| 43 shouldBe("toggleEventCountFromHTMLAttribute", "0"); |
34 details.open = true; | 44 details.open = true; |
35 shouldBe("toggleEventCount", "0"); | 45 shouldBe("toggleEventCount", "0"); |
| 46 shouldBe("toggleEventCountFromHTMLAttribute", "0"); |
36 setTimeout(checkSingleToggleEvent, 0); | 47 setTimeout(checkSingleToggleEvent, 0); |
37 } | 48 } |
38 | 49 |
39 function checkEventsCoalesced() { | 50 function checkEventsCoalesced() { |
40 shouldBe("toggleEventCount", "2"); | 51 shouldBe("toggleEventCount", "2"); |
| 52 shouldBe("toggleEventCountFromHTMLAttribute", "2"); |
41 shouldBeFalse("details.open"); | 53 shouldBeFalse("details.open"); |
42 finishJSTest(); | 54 finishJSTest(); |
43 } | 55 } |
44 | 56 |
45 function testEventsCoalesced() { | 57 function testEventsCoalesced() { |
46 // When the open attribute is toggled several times in succession, | 58 // When the open attribute is toggled several times in succession, |
47 // these steps essentially get coalesced so that only one event is | 59 // these steps essentially get coalesced so that only one event is |
48 // fired. | 60 // fired. |
49 details.open = false; | 61 details.open = false; |
50 details.open = true; | 62 details.open = true; |
51 details.open = false; | 63 details.open = false; |
52 setTimeout(checkEventsCoalesced, 0); | 64 setTimeout(checkEventsCoalesced, 0); |
53 } | 65 } |
54 | 66 |
55 var details = document.getElementById("details"); | 67 var details = document.getElementById("details"); |
| 68 shouldBe("details.ontoggle.__proto__", "Function.prototype"); |
56 details.addEventListener("toggle", handleToggleEvent); | 69 details.addEventListener("toggle", handleToggleEvent); |
57 shouldBeFalse("details.open"); | 70 shouldBeFalse("details.open"); |
58 testToogleEventFired(); | 71 testToogleEventFired(); |
59 </script> | 72 </script> |
60 </body> | 73 </body> |
61 </html> | 74 </html> |
OLD | NEW |