Bug 1444441 - Remove unsafeSetInnerHTML in browser_reservedkey.js r=johannh,prathiksha
authorTrisha <guptatrisha97@gmail.com>
Thu, 05 Apr 2018 01:57:44 +0800
changeset 414359 081b471aa819
parent 414358 10697d111e50
child 414360 9923d93eddd8
push id33867
push usernerli@mozilla.com
push dateThu, 19 Apr 2018 09:50:16 +0000
treeherdermozilla-central@2c32c973232d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh, prathiksha
bugs1444441
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1444441 - Remove unsafeSetInnerHTML in browser_reservedkey.js r=johannh,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");