[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor-browser/tor-browser-45.1.0esr-6.0-1] Regression tests for Bug 17009: Pref to suppress some modifier key events



commit b815400e8aae371dcc55141d202ae96155c4c78d
Author: Arthur Edelstein <arthuredelstein@xxxxxxxxx>
Date:   Wed Dec 23 09:52:05 2015 -0800

    Regression tests for Bug 17009: Pref to suppress some modifier key events
---
 dom/tests/browser/browser.ini               |  2 +
 dom/tests/browser/browser_tor_bug17009.html |  8 +++
 dom/tests/browser/browser_tor_bug17009.js   | 98 +++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+)

diff --git a/dom/tests/browser/browser.ini b/dom/tests/browser/browser.ini
index 363758e..bd07b47 100644
--- a/dom/tests/browser/browser.ini
+++ b/dom/tests/browser/browser.ini
@@ -2,6 +2,7 @@
 skip-if = e10s # Bug ?????? - most of these tests fail for currently unknown reasons.
 support-files =
   browser_frame_elements.html
+  browser_tor_bug17009.html
   page_privatestorageevent.html
   position.html
   test-console-api.html
@@ -44,3 +45,4 @@ disabled = re-enable when bug 794920 is fixed
 [browser_xhr_sandbox.js]
 skip-if= buildapp == 'mulet'
 [browser_bug1004814.js]
+[browser_tor_bug17009.js]
diff --git a/dom/tests/browser/browser_tor_bug17009.html b/dom/tests/browser/browser_tor_bug17009.html
new file mode 100644
index 0000000..455d547
--- /dev/null
+++ b/dom/tests/browser/browser_tor_bug17009.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<head>
+  <meta charset="utf-8">
+  <title>Tor Bug 17009 tests</title>
+</head>
+<body>
+  Testing that Alt and Shift keydown/keyup events aren't detected in content.
+</body>
diff --git a/dom/tests/browser/browser_tor_bug17009.js b/dom/tests/browser/browser_tor_bug17009.js
new file mode 100644
index 0000000..794baa4
--- /dev/null
+++ b/dom/tests/browser/browser_tor_bug17009.js
@@ -0,0 +1,98 @@
+"use strict";
+
+/*jshint esnext:true */
+
+const CONTENT_PAGE = "http://example.com/browser/dom/tests/browser/browser_tor_bug17009.html";;
+
+// __pushPref(key, value)__.
+// Set the given pref to a value. Returns a promise
+// that resolves asynchronously when the pref is
+// successfully set.
+let pushPref = function (key, value) {
+  return new Promise(resolve => {
+    SpecialPowers.pushPrefEnv({"set": [[key, value]]}, resolve);
+  });
+};
+
+// __listen(target, eventType, useCapture)__.
+// Returns a promise that resolves after a single event
+// of eventType is received by the target.
+let listen = function (target, eventType, useCapture) {
+  return new Promise(function (resolve, reject) {
+    let listenFunction = function (event) {
+      target.removeEventListener(eventType, listenFunction, useCapture);
+      resolve(event);
+    };
+    target.addEventListener(eventType, listenFunction, useCapture);
+  });
+};
+
+// __soon()__.
+// Wait a little bit before we continue. Returns a promise.
+let soon = function () {
+  return new Promise(resolve => executeSoon(resolve));
+};
+
+// __runTests(contentWindow)__.
+// The main tests. We test to make sure that, when
+// "privacy.suppressModifierKeyEvents" is true, then content
+// will not see Alt or Shift keydown or keyup events,
+// but chrome will still see those events.
+// If the pref is off, then both content and chrome
+// should see all events.
+let runTests = function* (contentWindow) {
+  // Check behavior for both non-resistance and resistance.
+  for (let resistFingerprinting of [false, true]) {
+    yield pushPref("privacy.resistFingerprinting", resistFingerprinting);
+    // Check behavior, both non-suppressing and suppressing.
+    for (let suppressModifiers of [false, true]) {
+      yield pushPref("privacy.suppressModifierKeyEvents", suppressModifiers);
+      // Check both keydown and keyup events.
+      for (let eventType of ["keydown", "keyup"]) {
+        // Check Alt and Shift keys.
+        for (let modifierKey of ["Alt", "Shift"]) {
+          // Listen for a single key event in the content window.
+          let contentEventPromise = listen(contentWindow, eventType, false);
+          // Listen for a single key event in the chrome window.
+          let chromeEventPromise = listen(window, eventType, false);
+          // Generate a Alt or Shift key event.
+          EventUtils.synthesizeKey("VK_" + modifierKey.toUpperCase(),
+                                   { type : eventType }, contentWindow);
+          // Generate a dummy "x" key event that will only be handled if
+          // modifier key is successfully suppressed.
+          EventUtils.synthesizeKey("x", { type: eventType }, contentWindow);
+          // Collect the events received in content and chrome.
+          let contentEvent = yield contentEventPromise;
+          let chromeEvent = yield chromeEventPromise;
+          // We should always see the modifier key in chrome, regardless of the
+          // pref state.
+          is(chromeEvent.key, modifierKey,
+             modifierKey + " key should be seen in chrome.");
+          // If and only if fingerprinting resistance is active and suppression
+          // is enabled, we should see the dummy "x" key; otherwise we expect
+          // to see the modifier key as usual.
+          let expectedContentKey = resistFingerprinting && suppressModifiers
+                                   ? "x" : modifierKey;
+          is(contentEvent.key, expectedContentKey,
+             expectedContentKey + " key should be seen in content.");
+        }
+      }
+    }
+  }
+};
+
+// Run tests asynchronously to make testing event handling straightforward.
+add_task(function* () {
+  // Set up a content tab and select it.
+  let tab = gBrowser.addTab(CONTENT_PAGE),
+      browser = gBrowser.getBrowserForTab(tab);
+  gBrowser.selectedTab = tab;
+
+  // Wait for tab to be completely loaded, then run the tests.
+  yield listen(browser, "DOMContentLoaded", false);
+  yield soon();
+  yield runTests(gBrowser.contentWindow);
+
+  // cleanup
+  gBrowser.removeTab(tab);
+});



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits