Skip to content

Commit 6ec8b55

Browse files
author
Sami Vänttinen
authored
Merge pull request #1066 from keepassxreboot/feature/content_script_tests
Content script tests
2 parents 992d4a0 + eebb930 commit 6ec8b55

31 files changed

Lines changed: 5097 additions & 155 deletions

keepassxc-browser/content/keepassxc-browser.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,16 +491,18 @@ kpxcFields.isVisible = function(elem) {
491491
const rect = elem.getBoundingClientRect();
492492
if (rect.x < 0
493493
|| rect.y < 0
494-
|| rect.width < 8
494+
|| rect.width < MIN_INPUT_FIELD_WIDTH_PX
495495
|| rect.x > Math.max(document.body.scrollWidth, document.body.offsetWidth, document.documentElement.clientWidth)
496496
|| rect.y > Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight)
497-
|| rect.height < 8) {
497+
|| rect.height < MIN_INPUT_FIELD_WIDTH_PX) {
498498
return false;
499499
}
500500

501501
// Check CSS visibility
502502
const elemStyle = getComputedStyle(elem);
503-
if (elemStyle.visibility && (elemStyle.visibility === 'hidden' || elemStyle.visibility === 'collapse')) {
503+
if (elemStyle.visibility && (elemStyle.visibility === 'hidden' || elemStyle.visibility === 'collapse')
504+
|| parseInt(elemStyle.width, 10) <= MIN_INPUT_FIELD_WIDTH_PX
505+
|| parseInt(elemStyle.height, 10) <= MIN_INPUT_FIELD_WIDTH_PX) {
504506
return false;
505507
}
506508

@@ -1722,6 +1724,11 @@ MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
17221724
const initContentScript = async function() {
17231725
try {
17241726
const settings = await sendMessage('load_settings');
1727+
if (!settings) {
1728+
console.log('Error: Cannot load extension settings');
1729+
return;
1730+
}
1731+
17251732
kpxc.settings = settings;
17261733

17271734
if (await kpxc.siteIgnored()) {

keepassxc-browser/content/pwgen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ kpxcPasswordIcons.deleteHiddenIcons = function() {
1818
kpxcPasswordIcons.isValid = function(field) {
1919
if (!field
2020
|| field.readOnly
21-
|| field.offsetWidth < MINIMUM_INPUT_FIELD_WIDTH
21+
|| field.offsetWidth < MIN_INPUT_FIELD_OFFSET_WIDTH
2222
|| kpxcIcons.hasIcon(field)
2323
|| !kpxcFields.isVisible(field)) {
2424
return false;

keepassxc-browser/content/totp-field.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const acceptedOTPFields = [
88
'auth',
99
'challenge',
1010
'code',
11+
'idvpin',
1112
'mfa',
1213
'otp',
1314
'token',
@@ -53,7 +54,7 @@ kpxcTOTPIcons.isValid = function(field, forced) {
5354

5455
if (!forced) {
5556
if (ignoredTypes.some(t => t === field.type)
56-
|| field.offsetWidth < MINIMUM_INPUT_FIELD_WIDTH
57+
|| field.offsetWidth < MIN_INPUT_FIELD_OFFSET_WIDTH
5758
|| field.size < 2
5859
|| (field.maxLength > 0 && (field.maxLength < MIN_TOTP_INPUT_LENGTH || field.maxLength > kpxcSites.expectedTOTPMaxLength()))
5960
|| ignoredTypes.some(t => t === field.autocomplete)

keepassxc-browser/content/ui.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict';
22

3-
const MINIMUM_INPUT_FIELD_WIDTH = 60;
43
const MIN_TOTP_INPUT_LENGTH = 6;
54
const MAX_TOTP_INPUT_LENGTH = 10;
5+
const MIN_INPUT_FIELD_WIDTH_PX = 8;
6+
const MIN_INPUT_FIELD_OFFSET_WIDTH = 60;
67

78
const DatabaseState = {
89
DISCONNECTED: 0,

keepassxc-browser/content/username-field.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ kpxcUsernameIcons.deleteHiddenIcons = function() {
1818

1919
kpxcUsernameIcons.isValid = function(field) {
2020
if (!field
21-
|| field.offsetWidth < MINIMUM_INPUT_FIELD_WIDTH
21+
|| field.offsetWidth < MIN_INPUT_FIELD_OFFSET_WIDTH
2222
|| field.readOnly
2323
|| kpxcIcons.hasIcon(field)
2424
|| !kpxcFields.isVisible(field)) {

keepassxc-browser/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"manifest_version": 2,
33
"name": "KeePassXC-Browser",
4-
"version": "1.7.3",
5-
"version_name": "1.7.3",
4+
"version": "1.7.4",
5+
"version_name": "1.7.4",
66
"description": "__MSG_extensionDescription__",
77
"author": "KeePassXC Team",
88
"icons": {

0 commit comments

Comments
 (0)