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