browser_markup_events_01.js (3400B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 /* import-globals-from helper_events_test_runner.js */ 4 5 "use strict"; 6 7 // Test that markup view event bubbles show the correct event info for DOM 8 // events. 9 10 const TEST_URL = URL_ROOT_SSL + "doc_markup_events_01.html"; 11 12 loadHelperScript("helper_events_test_runner.js"); 13 14 const TEST_DATA = [ 15 { 16 selector: "html", 17 expected: [ 18 { 19 type: "load", 20 filename: TEST_URL, 21 attributes: ["Bubbling"], 22 handler: "function onload(event) {\n" + " init();\n" + "}", 23 }, 24 ], 25 }, 26 { 27 selector: "#container", 28 expected: [ 29 { 30 type: "mouseover", 31 filename: TEST_URL + ":48:31", 32 attributes: ["Capturing"], 33 handler: 34 "function mouseoverHandler(event) {\n" + 35 ' if (event.target.id !== "container") {\n' + 36 ' const output = document.getElementById("output");\n' + 37 " output.textContent = event.target.textContent;\n" + 38 " }\n" + 39 "}", 40 }, 41 ], 42 }, 43 { 44 selector: "#multiple", 45 expected: [ 46 { 47 type: "click", 48 filename: TEST_URL + ":55:27", 49 attributes: ["Bubbling"], 50 handler: 51 "function clickHandler(event) {\n" + 52 ' const output = document.getElementById("output");\n' + 53 ' output.textContent = "click";\n' + 54 "}", 55 }, 56 { 57 type: "mouseup", 58 filename: TEST_URL + ":60:29", 59 attributes: ["Bubbling"], 60 handler: 61 "function mouseupHandler(event) {\n" + 62 ' const output = document.getElementById("output");\n' + 63 ' output.textContent = "mouseup";\n' + 64 "}", 65 }, 66 ], 67 }, 68 // #noevents tests check that dynamically added events are properly displayed 69 // in the markupview 70 { 71 selector: "#noevents", 72 expected: [], 73 }, 74 { 75 selector: "#noevents", 76 async beforeTest(inspector) { 77 const nodeMutated = inspector.once("markupmutation"); 78 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => 79 content.wrappedJSObject.addNoeventsClickHandler() 80 ); 81 await nodeMutated; 82 }, 83 expected: [ 84 { 85 type: "click", 86 filename: TEST_URL + ":76:35", 87 attributes: ["Bubbling"], 88 handler: 89 "function noeventsClickHandler(event) {\n" + 90 ' alert("noevents has an event listener");\n' + 91 "}", 92 }, 93 ], 94 }, 95 { 96 selector: "#noevents", 97 async beforeTest(inspector) { 98 const nodeMutated = inspector.once("markupmutation"); 99 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => 100 content.wrappedJSObject.removeNoeventsClickHandler() 101 ); 102 await nodeMutated; 103 }, 104 expected: [], 105 }, 106 { 107 selector: "#DOM0", 108 expected: [ 109 { 110 type: "click", 111 filename: TEST_URL, 112 attributes: ["Bubbling"], 113 handler: "function onclick(event) {\n" + " alert('DOM0')\n" + "}", 114 }, 115 ], 116 }, 117 { 118 selector: "#handleevent", 119 expected: [ 120 { 121 type: "click", 122 filename: TEST_URL + ":71:29", 123 attributes: ["Bubbling"], 124 handler: "function(blah) {\n" + ' alert("handleEvent");\n' + "}", 125 }, 126 ], 127 }, 128 ]; 129 130 add_task(async function () { 131 await runEventPopupTests(TEST_URL, TEST_DATA); 132 });