[Pkg-mozext-commits] [requestpolicy] 25/65: [fix] keyboard shortcuts: changing required restart
David Prévot
taffit at moszumanska.debian.org
Fri Mar 25 22:59:48 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository requestpolicy.
commit 4c583df24a0321e7626d71cbbf8e1b9b5ea959ad
Author: Martin Kimmerle <dev at 256k.de>
Date: Sat Jan 16 21:26:50 2016 +0100
[fix] keyboard shortcuts: changing required restart
When a keyboard shortcut has been changed, either the combo or
the "disabled" attribute, the changes only applied to new
browser windows. The main poin is to re-add the <keyset> to its
parent.
---
src/content/lib/classes/keyboard-shortcut.jsm | 13 +++++++----
src/content/models/windows.jsm | 4 ++--
tests/marionette/tests/menu/test_open.py | 33 +++++++++++++++++++++++----
3 files changed, 40 insertions(+), 10 deletions(-)
diff --git a/src/content/lib/classes/keyboard-shortcut.jsm b/src/content/lib/classes/keyboard-shortcut.jsm
index af1a54c..4b793a6 100644
--- a/src/content/lib/classes/keyboard-shortcut.jsm
+++ b/src/content/lib/classes/keyboard-shortcut.jsm
@@ -127,7 +127,15 @@ KeyboardShortcut.prototype._onPress = function(event) {
KeyboardShortcut.prototype._onPrefChange = function() {
this._determineElementAttributes();
- Windows.forEachOpenWindow(this._setElementAttributes.bind(this));
+ Windows.forEachOpenWindow(function(window) {
+ this._setElementAttributes(window);
+
+ // Each time one of the key's attributes changes it's necessary to
+ // newly append the keyset to it's parent. Otherwise the
+ // keyboard shortcut doesn't get updated!
+ let keyset = window.document.getElementById("rpcontinuedKeyset");
+ keyset.parentNode.appendChild(keyset);
+ }, this);
};
//------------------------------------------------------------------------------
@@ -149,9 +157,6 @@ KeyboardShortcut.prototype._createElement = function(window) {
KeyboardShortcut.prototype._setElementAttributes = function(window) {
let element = window.document.getElementById(this._elementID);
- // disable temporarily
- element.setAttribute("disabled", "true");
-
element.setAttribute("modifiers", this._elementAttributes.modifiers);
element.setAttribute("key", this._elementAttributes.key);
element.setAttribute("disabled", this._elementAttributes.disabled);
diff --git a/src/content/models/windows.jsm b/src/content/models/windows.jsm
index 9645c48..ae26e5f 100644
--- a/src/content/models/windows.jsm
+++ b/src/content/models/windows.jsm
@@ -106,12 +106,12 @@ function LoadAndUnloadListener(callback) {
var Windows = (function() {
let self = {};
- self.forEachOpenWindow = function(aCallback) {
+ self.forEachOpenWindow = function(aCallback, aThisArg=null) {
// Apply a function to all open browser windows
let windows = Services.wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
let window = windows.getNext().QueryInterface(Ci.nsIDOMWindow);
- aCallback.call(null, window);
+ aCallback.call(aThisArg, window);
}
};
diff --git a/tests/marionette/tests/menu/test_open.py b/tests/marionette/tests/menu/test_open.py
index 00ae4df..baef524 100644
--- a/tests/marionette/tests/menu/test_open.py
+++ b/tests/marionette/tests/menu/test_open.py
@@ -4,11 +4,16 @@
from rp_ui_harness import RequestPolicyTestCase
from marionette_driver.errors import TimeoutException
+from marionette_driver.wait import Wait
import time
class TestOpenMenu(RequestPolicyTestCase):
+ ################
+ # Test Methods #
+ ################
+
def test_shortcut_disabled(self):
pref_name = ("extensions.requestpolicy."
"keyboardShortcuts.openMenu.enabled")
@@ -16,8 +21,8 @@ class TestOpenMenu(RequestPolicyTestCase):
time.sleep(0.001)
self.assertFalse(self.menu.is_open())
- with self.assertRaises(TimeoutException):
- self.menu.open(trigger="shortcut")
+
+ self._assert_menu_does_not_open(trigger="shortcut")
self.assertFalse(self.menu.is_open())
self.prefs.reset_pref(pref_name)
@@ -34,8 +39,7 @@ class TestOpenMenu(RequestPolicyTestCase):
self.assertFalse(self.menu.is_open())
# The default shortcut should not open the menu anymore
- with self.assertRaises(TimeoutException):
- self.menu.open(trigger="shortcut")
+ self._assert_menu_does_not_open(trigger="shortcut")
self.assertFalse(self.menu.is_open())
# Test the custom combo
self.menu.open(trigger=press_shortcut)
@@ -44,3 +48,24 @@ class TestOpenMenu(RequestPolicyTestCase):
self.menu.close()
self.prefs.reset_pref(pref_name)
time.sleep(0.001)
+
+ ##########################
+ # Private Helper Methods #
+ ##########################
+
+ def _assert_menu_does_not_open(self, *args, **kwargs):
+ def try_to_open(_):
+ self.menu.open(*args, **kwargs)
+ # Close the menu in case `open()` does _not_fail.
+ self.menu.close()
+ self._wait_until_raises(try_to_open, TimeoutException,
+ message="The menu should not open.")
+
+ def _wait_until_raises(self, condition, exception, message=""):
+ def until(*args, **kwargs):
+ try:
+ condition(*args, **kwargs)
+ return False
+ except exception:
+ return True
+ Wait(self.marionette).until(until, message=message)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git
More information about the Pkg-mozext-commits
mailing list