michael@0: const HTML_NS = "http://www.w3.org/1999/xhtml"; michael@0: michael@0: const INPUT_ID = "input1"; michael@0: const FORM1_ID = "form1"; michael@0: const FORM2_ID = "form2"; michael@0: const CHANGE_INPUT_ID = "input2"; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: let tab = gBrowser.selectedTab = michael@0: gBrowser.addTab("data:text/html;charset=utf-8," + michael@0: "
" + michael@0: "" + michael@0: "" + michael@0: ""); michael@0: tab.linkedBrowser.addEventListener("load", tabLoad, true); michael@0: } michael@0: michael@0: function unexpectedContentEvent(evt) { michael@0: ok(false, "Received a " + evt.type + " event on content"); michael@0: } michael@0: michael@0: var gDoc = null; michael@0: michael@0: function tabLoad() { michael@0: let tab = gBrowser.selectedTab; michael@0: tab.linkedBrowser.removeEventListener("load", tabLoad, true); michael@0: gDoc = gBrowser.selectedBrowser.contentDocument; michael@0: // These events shouldn't escape to content. michael@0: gDoc.addEventListener("DOMFormHasPassword", unexpectedContentEvent, false); michael@0: gDoc.defaultView.setTimeout(test_inputAdd, 0); michael@0: } michael@0: michael@0: function test_inputAdd() { michael@0: gBrowser.addEventListener("DOMFormHasPassword", test_inputAddHandler, false); michael@0: let input = gDoc.createElementNS(HTML_NS, "input"); michael@0: input.setAttribute("type", "password"); michael@0: input.setAttribute("id", INPUT_ID); michael@0: input.setAttribute("data-test", "unique-attribute"); michael@0: gDoc.getElementById(FORM1_ID).appendChild(input); michael@0: info("Done appending the input element"); michael@0: } michael@0: michael@0: function test_inputAddHandler(evt) { michael@0: gBrowser.removeEventListener(evt.type, test_inputAddHandler, false); michael@0: is(evt.target.id, FORM1_ID, michael@0: evt.type + " event targets correct form element (added password element)"); michael@0: gDoc.defaultView.setTimeout(test_inputChangeForm, 0); michael@0: } michael@0: michael@0: function test_inputChangeForm() { michael@0: gBrowser.addEventListener("DOMFormHasPassword", test_inputChangeFormHandler, false); michael@0: let input = gDoc.getElementById(INPUT_ID); michael@0: input.setAttribute("form", FORM2_ID); michael@0: } michael@0: michael@0: function test_inputChangeFormHandler(evt) { michael@0: gBrowser.removeEventListener(evt.type, test_inputChangeFormHandler, false); michael@0: is(evt.target.id, FORM2_ID, michael@0: evt.type + " event targets correct form element (changed form)"); michael@0: gDoc.defaultView.setTimeout(test_inputChangesType, 0); michael@0: } michael@0: michael@0: function test_inputChangesType() { michael@0: gBrowser.addEventListener("DOMFormHasPassword", test_inputChangesTypeHandler, false); michael@0: let input = gDoc.getElementById(CHANGE_INPUT_ID); michael@0: input.setAttribute("type", "password"); michael@0: } michael@0: michael@0: function test_inputChangesTypeHandler(evt) { michael@0: gBrowser.removeEventListener(evt.type, test_inputChangesTypeHandler, false); michael@0: is(evt.target.id, FORM1_ID, michael@0: evt.type + " event targets correct form element (changed type)"); michael@0: gDoc.defaultView.setTimeout(completeTest, 0); michael@0: } michael@0: michael@0: function completeTest() { michael@0: ok(true, "Test completed"); michael@0: gDoc.removeEventListener("DOMFormHasPassword", unexpectedContentEvent, false); michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: }