Bug 1444441 - Remove unsafeSetInnerHTML in browser_reservedkey.js r?prathiksha draft
authorTrisha <guptatrisha97@gmail.com>
Thu, 05 Apr 2018 01:57:44 +0800
changeset 783817 891e1dbaa6b50b06bbae54e4db98fef120d2ebf9
parent 776018 c44f60c43432d468639b5fe078420e60c13fd3de
push id106791
push userbmo:guptatrisha97@gmail.com
push dateTue, 17 Apr 2018 19:23:02 +0000
reviewersprathiksha
bugs1444441
milestone61.0a1
Bug 1444441 - Remove unsafeSetInnerHTML in browser_reservedkey.js r?prathiksha MozReview-Commit-ID: 8E9LCxQ3StM
browser/base/content/test/permissions/browser_reservedkey.js
--- a/browser/base/content/test/permissions/browser_reservedkey.js
+++ b/browser/base/content/test/permissions/browser_reservedkey.js
@@ -1,23 +1,54 @@
 add_task(async function test_reserved_shortcuts() {
-  /* eslint-disable no-unsanitized/property */
-  let keyset = `<keyset>
-                  <key id='kt_reserved' modifiers='shift' key='O' reserved='true' count='0'
-                       oncommand='this.setAttribute("count", Number(this.getAttribute("count")) + 1)'/>
-                  <key id='kt_notreserved' modifiers='shift' key='P' reserved='false' count='0'
-                       oncommand='this.setAttribute("count", Number(this.getAttribute("count")) + 1)'/>
-                  <key id='kt_reserveddefault' modifiers='shift' key='Q' count='0'
-                       oncommand='this.setAttribute("count", Number(this.getAttribute("count")) + 1)'/>
-                </keyset>`;
+  let keyset = document.createElement("keyset");
+  let key1 = document.createElement("key");
+  key1.setAttribute("id", "kt_reserved");
+  key1.setAttribute("modifiers", "shift");
+  key1.setAttribute("key", "O");
+  key1.setAttribute("reserved", "true");
+  key1.setAttribute("count", "0");
+  // We need to have the attribute "oncommand" for the "command" listener to fire
+  key1.setAttribute("oncommand", "//");
+  key1.addEventListener("command", () => {
+    let attribute = key1.getAttribute("count");
+    key1.setAttribute("count", Number(attribute) + 1);
+  });
 
+  let key2 = document.createElement("key");
+  key2.setAttribute("id", "kt_notreserved");
+  key2.setAttribute("modifiers", "shift");
+  key2.setAttribute("key", "P");
+  key2.setAttribute("reserved", "false");
+  key2.setAttribute("count", "0");
+  // We need to have the attribute "oncommand" for the "command" listener to fire
+  key2.setAttribute("oncommand", "//");
+  key2.addEventListener("command", () => {
+    let attribute = key2.getAttribute("count");
+    key2.setAttribute("count", Number(attribute) + 1);
+  });
+
+  let key3 = document.createElement("key");
+  key3.setAttribute("id", "kt_reserveddefault");
+  key3.setAttribute("modifiers", "shift");
+  key3.setAttribute("key", "Q");
+  key3.setAttribute("count", "0");
+  // We need to have the attribute "oncommand" for the "command" listener to fire
+  key3.setAttribute("oncommand", "//");
+  key3.addEventListener("command", () => {
+    let attribute = key3.getAttribute("count");
+    key3.setAttribute("count", Number(attribute) + 1);
+  });
+
+  keyset.appendChild(key1);
+  keyset.appendChild(key2);
+  keyset.appendChild(key3);
   let container = document.createElement("box");
-  container.unsafeSetInnerHTML(keyset);
+  container.appendChild(keyset);
   document.documentElement.appendChild(container);
-  /* eslint-enable no-unsanitized/property */
 
   const pageUrl = "data:text/html,<body onload='document.body.firstChild.focus();'><div onkeydown='event.preventDefault();' tabindex=0>Test</div></body>";
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, pageUrl);
 
   EventUtils.sendString("OPQ");
 
   is(document.getElementById("kt_reserved").getAttribute("count"), "1", "reserved='true' with preference off");
   is(document.getElementById("kt_notreserved").getAttribute("count"), "0", "reserved='false' with preference off");