|
|
@@ -132,14 +132,9 @@ describe('TopNav', function () {
|
|
|
|
|
|
// builds the create-document navbar and stubs the actual send, so no
|
|
|
// server interaction happens
|
|
|
- function setUpCreateMode(userAgent) {
|
|
|
+ function setUpCreateMode() {
|
|
|
cleanup();
|
|
|
sendCount = 0;
|
|
|
- if (userAgent) {
|
|
|
- Object.defineProperty(window.navigator, 'userAgent', {
|
|
|
- value: userAgent, configurable: true
|
|
|
- });
|
|
|
- }
|
|
|
document.documentElement.innerHTML =
|
|
|
'<nav><div id="navbar"><ul><li><button id="newbutton" ' +
|
|
|
'type="button" class="hidden">New</button></li><li><a ' +
|
|
|
@@ -174,62 +169,43 @@ describe('TopNav', function () {
|
|
|
|
|
|
it('sends the document on Ctrl+S and suppresses the browser save dialog', function () {
|
|
|
setUpCreateMode();
|
|
|
- const prevented = pressKey({key: 's', ctrlKey: true});
|
|
|
+ const prevented = pressKey({key: 's', code: 'KeyS', ctrlKey: true});
|
|
|
assert.strictEqual(sendCount, 1);
|
|
|
assert.ok(prevented);
|
|
|
});
|
|
|
|
|
|
it('sends the document on Cmd+S (macOS)', function () {
|
|
|
setUpCreateMode();
|
|
|
- const prevented = pressKey({key: 's', metaKey: true});
|
|
|
+ const prevented = pressKey({key: 's', code: 'KeyS', metaKey: true});
|
|
|
assert.strictEqual(sendCount, 1);
|
|
|
assert.ok(prevented);
|
|
|
});
|
|
|
|
|
|
- it('still sends when caps lock turns the key into an upper case S', function () {
|
|
|
+ it('sends on the physical S key of non-Latin keyboard layouts', function () {
|
|
|
setUpCreateMode();
|
|
|
- pressKey({key: 'S', ctrlKey: true});
|
|
|
+ // on a Russian layout the S key produces "ы"
|
|
|
+ pressKey({key: 'ы', code: 'KeyS', ctrlKey: true});
|
|
|
assert.strictEqual(sendCount, 1);
|
|
|
});
|
|
|
|
|
|
it('leaves Ctrl+S to the browser when viewing a document', function () {
|
|
|
setUpCreateMode();
|
|
|
PrivateBin.TopNav.hideCreateButtons();
|
|
|
- const prevented = pressKey({key: 's', ctrlKey: true});
|
|
|
+ const prevented = pressKey({key: 's', code: 'KeyS', ctrlKey: true});
|
|
|
assert.strictEqual(sendCount, 0);
|
|
|
assert.ok(!prevented);
|
|
|
});
|
|
|
|
|
|
- it('ignores S without Ctrl/Cmd, with AltGr (Ctrl+Alt) or with Shift', function () {
|
|
|
+ it('ignores S without Ctrl/Cmd, with AltGr (Ctrl+Alt), with Shift, or other keys', function () {
|
|
|
setUpCreateMode();
|
|
|
const prevented = [
|
|
|
- pressKey({key: 's'}),
|
|
|
- pressKey({key: 's', ctrlKey: true, altKey: true}),
|
|
|
- pressKey({key: 'S', ctrlKey: true, shiftKey: true})
|
|
|
+ pressKey({key: 's', code: 'KeyS'}),
|
|
|
+ pressKey({key: 's', code: 'KeyS', ctrlKey: true, altKey: true}),
|
|
|
+ pressKey({key: 'S', code: 'KeyS', ctrlKey: true, shiftKey: true}),
|
|
|
+ pressKey({key: 'd', code: 'KeyD', ctrlKey: true})
|
|
|
];
|
|
|
assert.strictEqual(sendCount, 0);
|
|
|
- assert.deepStrictEqual(prevented, [false, false, false]);
|
|
|
- });
|
|
|
-
|
|
|
- it('shows the Ctrl+S shortcut as tooltip and to assistive technology', function () {
|
|
|
- setUpCreateMode();
|
|
|
- const sendButton = query('#sendbutton');
|
|
|
- assert.strictEqual(sendButton.getAttribute('title'), 'Ctrl+S');
|
|
|
- assert.strictEqual(sendButton.getAttribute('aria-keyshortcuts'), 'Control+S');
|
|
|
- });
|
|
|
-
|
|
|
- it('shows Cmd+S on macOS', function () {
|
|
|
- setUpCreateMode('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)');
|
|
|
- const sendButton = query('#sendbutton');
|
|
|
- assert.strictEqual(sendButton.getAttribute('title'), 'Cmd+S');
|
|
|
- assert.strictEqual(sendButton.getAttribute('aria-keyshortcuts'), 'Meta+S');
|
|
|
- });
|
|
|
-
|
|
|
- it('translates the tooltip once the language has loaded', function () {
|
|
|
- setUpCreateMode();
|
|
|
- PrivateBin.I18n.reset('de', {Ctrl: 'Strg'});
|
|
|
- document.dispatchEvent(new window.CustomEvent('languageLoaded'));
|
|
|
- assert.strictEqual(query('#sendbutton').getAttribute('title'), 'Strg+S');
|
|
|
+ assert.deepStrictEqual(prevented, [false, false, false, false]);
|
|
|
});
|
|
|
});
|
|
|
|