11cb0ef41Sopenharmony_ci<!DOCTYPE html> 21cb0ef41Sopenharmony_ci<meta charset=utf-8> 31cb0ef41Sopenharmony_ci<title> Dispatch additional events inside an event listener </title> 41cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script> 51cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script> 61cb0ef41Sopenharmony_ci<div id=log></div> 71cb0ef41Sopenharmony_ci<table id="table" border="1" style="display: none"> 81cb0ef41Sopenharmony_ci <tbody id="table-body"> 91cb0ef41Sopenharmony_ci <tr id="table-row"> 101cb0ef41Sopenharmony_ci <td id="table-cell">Shady Grove</td> 111cb0ef41Sopenharmony_ci <td>Aeolian</td> 121cb0ef41Sopenharmony_ci </tr> 131cb0ef41Sopenharmony_ci <tr id="parent"> 141cb0ef41Sopenharmony_ci <td id="target">Over the river, Charlie</td> 151cb0ef41Sopenharmony_ci <td>Dorian</td> 161cb0ef41Sopenharmony_ci </tr> 171cb0ef41Sopenharmony_ci </tbody> 181cb0ef41Sopenharmony_ci</table> 191cb0ef41Sopenharmony_ci<script> 201cb0ef41Sopenharmony_citest(function() { 211cb0ef41Sopenharmony_ci var event_type = "foo"; 221cb0ef41Sopenharmony_ci var target = document.getElementById("target"); 231cb0ef41Sopenharmony_ci var parent = document.getElementById("parent"); 241cb0ef41Sopenharmony_ci var tbody = document.getElementById("table-body"); 251cb0ef41Sopenharmony_ci var table = document.getElementById("table"); 261cb0ef41Sopenharmony_ci var body = document.body; 271cb0ef41Sopenharmony_ci var html = document.documentElement; 281cb0ef41Sopenharmony_ci var targets = [window, document, html, body, table, tbody, parent, target]; 291cb0ef41Sopenharmony_ci var expected_targets = [ 301cb0ef41Sopenharmony_ci window, document, html, body, table, 311cb0ef41Sopenharmony_ci target, parent, tbody, 321cb0ef41Sopenharmony_ci table, body, html, document, window, 331cb0ef41Sopenharmony_ci tbody, parent, target]; 341cb0ef41Sopenharmony_ci var actual_targets = []; 351cb0ef41Sopenharmony_ci var expected_types = [ 361cb0ef41Sopenharmony_ci "foo", "foo", "foo", "foo", "foo", 371cb0ef41Sopenharmony_ci "bar", "bar", "bar", 381cb0ef41Sopenharmony_ci "bar", "bar", "bar", "bar", "bar", 391cb0ef41Sopenharmony_ci "foo", "foo", "foo" 401cb0ef41Sopenharmony_ci ]; 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci var actual_targets = [], actual_types = []; 431cb0ef41Sopenharmony_ci var test_event = this.step_func(function(evt) { 441cb0ef41Sopenharmony_ci actual_targets.push(evt.currentTarget); 451cb0ef41Sopenharmony_ci actual_types.push(evt.type); 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci if (table == evt.currentTarget && event_type == evt.type) { 481cb0ef41Sopenharmony_ci var e = document.createEvent("Event"); 491cb0ef41Sopenharmony_ci e.initEvent("bar", true, true); 501cb0ef41Sopenharmony_ci target.dispatchEvent(e); 511cb0ef41Sopenharmony_ci } 521cb0ef41Sopenharmony_ci }); 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci for (var i = 0; i < targets.length; ++i) { 551cb0ef41Sopenharmony_ci targets[i].addEventListener(event_type, test_event, true); 561cb0ef41Sopenharmony_ci targets[i].addEventListener("bar", test_event, false); 571cb0ef41Sopenharmony_ci } 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci var evt = document.createEvent("Event"); 601cb0ef41Sopenharmony_ci evt.initEvent(event_type, false, true); 611cb0ef41Sopenharmony_ci target.dispatchEvent(evt); 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ci assert_array_equals(actual_targets, expected_targets, "actual_targets"); 641cb0ef41Sopenharmony_ci assert_array_equals(actual_types, expected_types, "actual_types"); 651cb0ef41Sopenharmony_ci}); 661cb0ef41Sopenharmony_ci</script> 67