Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | const HTML_NS = "http://www.w3.org/1999/xhtml"; |
michael@0 | 2 | |
michael@0 | 3 | const INPUT_ID = "input1"; |
michael@0 | 4 | const FORM1_ID = "form1"; |
michael@0 | 5 | const FORM2_ID = "form2"; |
michael@0 | 6 | const CHANGE_INPUT_ID = "input2"; |
michael@0 | 7 | |
michael@0 | 8 | function test() { |
michael@0 | 9 | waitForExplicitFinish(); |
michael@0 | 10 | let tab = gBrowser.selectedTab = |
michael@0 | 11 | gBrowser.addTab("data:text/html;charset=utf-8," + |
michael@0 | 12 | "<html><body>" + |
michael@0 | 13 | "<form id='" + FORM1_ID + "'><input id='" + CHANGE_INPUT_ID + "'></form>" + |
michael@0 | 14 | "<form id='" + FORM2_ID + "'></form>" + |
michael@0 | 15 | "</body></html>"); |
michael@0 | 16 | tab.linkedBrowser.addEventListener("load", tabLoad, true); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | function unexpectedContentEvent(evt) { |
michael@0 | 20 | ok(false, "Received a " + evt.type + " event on content"); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | var gDoc = null; |
michael@0 | 24 | |
michael@0 | 25 | function tabLoad() { |
michael@0 | 26 | let tab = gBrowser.selectedTab; |
michael@0 | 27 | tab.linkedBrowser.removeEventListener("load", tabLoad, true); |
michael@0 | 28 | gDoc = gBrowser.selectedBrowser.contentDocument; |
michael@0 | 29 | // These events shouldn't escape to content. |
michael@0 | 30 | gDoc.addEventListener("DOMFormHasPassword", unexpectedContentEvent, false); |
michael@0 | 31 | gDoc.defaultView.setTimeout(test_inputAdd, 0); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function test_inputAdd() { |
michael@0 | 35 | gBrowser.addEventListener("DOMFormHasPassword", test_inputAddHandler, false); |
michael@0 | 36 | let input = gDoc.createElementNS(HTML_NS, "input"); |
michael@0 | 37 | input.setAttribute("type", "password"); |
michael@0 | 38 | input.setAttribute("id", INPUT_ID); |
michael@0 | 39 | input.setAttribute("data-test", "unique-attribute"); |
michael@0 | 40 | gDoc.getElementById(FORM1_ID).appendChild(input); |
michael@0 | 41 | info("Done appending the input element"); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function test_inputAddHandler(evt) { |
michael@0 | 45 | gBrowser.removeEventListener(evt.type, test_inputAddHandler, false); |
michael@0 | 46 | is(evt.target.id, FORM1_ID, |
michael@0 | 47 | evt.type + " event targets correct form element (added password element)"); |
michael@0 | 48 | gDoc.defaultView.setTimeout(test_inputChangeForm, 0); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | function test_inputChangeForm() { |
michael@0 | 52 | gBrowser.addEventListener("DOMFormHasPassword", test_inputChangeFormHandler, false); |
michael@0 | 53 | let input = gDoc.getElementById(INPUT_ID); |
michael@0 | 54 | input.setAttribute("form", FORM2_ID); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function test_inputChangeFormHandler(evt) { |
michael@0 | 58 | gBrowser.removeEventListener(evt.type, test_inputChangeFormHandler, false); |
michael@0 | 59 | is(evt.target.id, FORM2_ID, |
michael@0 | 60 | evt.type + " event targets correct form element (changed form)"); |
michael@0 | 61 | gDoc.defaultView.setTimeout(test_inputChangesType, 0); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | function test_inputChangesType() { |
michael@0 | 65 | gBrowser.addEventListener("DOMFormHasPassword", test_inputChangesTypeHandler, false); |
michael@0 | 66 | let input = gDoc.getElementById(CHANGE_INPUT_ID); |
michael@0 | 67 | input.setAttribute("type", "password"); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function test_inputChangesTypeHandler(evt) { |
michael@0 | 71 | gBrowser.removeEventListener(evt.type, test_inputChangesTypeHandler, false); |
michael@0 | 72 | is(evt.target.id, FORM1_ID, |
michael@0 | 73 | evt.type + " event targets correct form element (changed type)"); |
michael@0 | 74 | gDoc.defaultView.setTimeout(completeTest, 0); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | function completeTest() { |
michael@0 | 78 | ok(true, "Test completed"); |
michael@0 | 79 | gDoc.removeEventListener("DOMFormHasPassword", unexpectedContentEvent, false); |
michael@0 | 80 | gBrowser.removeCurrentTab(); |
michael@0 | 81 | finish(); |
michael@0 | 82 | } |