1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_bug771331.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +const HTML_NS = "http://www.w3.org/1999/xhtml"; 1.5 + 1.6 +const INPUT_ID = "input1"; 1.7 +const FORM1_ID = "form1"; 1.8 +const FORM2_ID = "form2"; 1.9 +const CHANGE_INPUT_ID = "input2"; 1.10 + 1.11 +function test() { 1.12 + waitForExplicitFinish(); 1.13 + let tab = gBrowser.selectedTab = 1.14 + gBrowser.addTab("data:text/html;charset=utf-8," + 1.15 + "<html><body>" + 1.16 + "<form id='" + FORM1_ID + "'><input id='" + CHANGE_INPUT_ID + "'></form>" + 1.17 + "<form id='" + FORM2_ID + "'></form>" + 1.18 + "</body></html>"); 1.19 + tab.linkedBrowser.addEventListener("load", tabLoad, true); 1.20 +} 1.21 + 1.22 +function unexpectedContentEvent(evt) { 1.23 + ok(false, "Received a " + evt.type + " event on content"); 1.24 +} 1.25 + 1.26 +var gDoc = null; 1.27 + 1.28 +function tabLoad() { 1.29 + let tab = gBrowser.selectedTab; 1.30 + tab.linkedBrowser.removeEventListener("load", tabLoad, true); 1.31 + gDoc = gBrowser.selectedBrowser.contentDocument; 1.32 + // These events shouldn't escape to content. 1.33 + gDoc.addEventListener("DOMFormHasPassword", unexpectedContentEvent, false); 1.34 + gDoc.defaultView.setTimeout(test_inputAdd, 0); 1.35 +} 1.36 + 1.37 +function test_inputAdd() { 1.38 + gBrowser.addEventListener("DOMFormHasPassword", test_inputAddHandler, false); 1.39 + let input = gDoc.createElementNS(HTML_NS, "input"); 1.40 + input.setAttribute("type", "password"); 1.41 + input.setAttribute("id", INPUT_ID); 1.42 + input.setAttribute("data-test", "unique-attribute"); 1.43 + gDoc.getElementById(FORM1_ID).appendChild(input); 1.44 + info("Done appending the input element"); 1.45 +} 1.46 + 1.47 +function test_inputAddHandler(evt) { 1.48 + gBrowser.removeEventListener(evt.type, test_inputAddHandler, false); 1.49 + is(evt.target.id, FORM1_ID, 1.50 + evt.type + " event targets correct form element (added password element)"); 1.51 + gDoc.defaultView.setTimeout(test_inputChangeForm, 0); 1.52 +} 1.53 + 1.54 +function test_inputChangeForm() { 1.55 + gBrowser.addEventListener("DOMFormHasPassword", test_inputChangeFormHandler, false); 1.56 + let input = gDoc.getElementById(INPUT_ID); 1.57 + input.setAttribute("form", FORM2_ID); 1.58 +} 1.59 + 1.60 +function test_inputChangeFormHandler(evt) { 1.61 + gBrowser.removeEventListener(evt.type, test_inputChangeFormHandler, false); 1.62 + is(evt.target.id, FORM2_ID, 1.63 + evt.type + " event targets correct form element (changed form)"); 1.64 + gDoc.defaultView.setTimeout(test_inputChangesType, 0); 1.65 +} 1.66 + 1.67 +function test_inputChangesType() { 1.68 + gBrowser.addEventListener("DOMFormHasPassword", test_inputChangesTypeHandler, false); 1.69 + let input = gDoc.getElementById(CHANGE_INPUT_ID); 1.70 + input.setAttribute("type", "password"); 1.71 +} 1.72 + 1.73 +function test_inputChangesTypeHandler(evt) { 1.74 + gBrowser.removeEventListener(evt.type, test_inputChangesTypeHandler, false); 1.75 + is(evt.target.id, FORM1_ID, 1.76 + evt.type + " event targets correct form element (changed type)"); 1.77 + gDoc.defaultView.setTimeout(completeTest, 0); 1.78 +} 1.79 + 1.80 +function completeTest() { 1.81 + ok(true, "Test completed"); 1.82 + gDoc.removeEventListener("DOMFormHasPassword", unexpectedContentEvent, false); 1.83 + gBrowser.removeCurrentTab(); 1.84 + finish(); 1.85 +}