Skip to content

Commit

Permalink
Merge pull request #1066 from keepassxreboot/feature/content_script_t…
Browse files Browse the repository at this point in the history
…ests

Content script tests
  • Loading branch information
Sami Vänttinen authored Dec 21, 2020
2 parents 992d4a0 + eebb930 commit 6ec8b55
Show file tree
Hide file tree
Showing 31 changed files with 5,097 additions and 155 deletions.
13 changes: 10 additions & 3 deletions keepassxc-browser/content/keepassxc-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,16 +491,18 @@ kpxcFields.isVisible = function(elem) {
const rect = elem.getBoundingClientRect();
if (rect.x < 0
|| rect.y < 0
|| rect.width < 8
|| rect.width < MIN_INPUT_FIELD_WIDTH_PX
|| rect.x > Math.max(document.body.scrollWidth, document.body.offsetWidth, document.documentElement.clientWidth)
|| rect.y > Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight)
|| rect.height < 8) {
|| rect.height < MIN_INPUT_FIELD_WIDTH_PX) {
return false;
}

// Check CSS visibility
const elemStyle = getComputedStyle(elem);
if (elemStyle.visibility && (elemStyle.visibility === 'hidden' || elemStyle.visibility === 'collapse')) {
if (elemStyle.visibility && (elemStyle.visibility === 'hidden' || elemStyle.visibility === 'collapse')
|| parseInt(elemStyle.width, 10) <= MIN_INPUT_FIELD_WIDTH_PX
|| parseInt(elemStyle.height, 10) <= MIN_INPUT_FIELD_WIDTH_PX) {
return false;
}

Expand Down Expand Up @@ -1722,6 +1724,11 @@ MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
const initContentScript = async function() {
try {
const settings = await sendMessage('load_settings');
if (!settings) {
console.log('Error: Cannot load extension settings');
return;
}

kpxc.settings = settings;

if (await kpxc.siteIgnored()) {
Expand Down
2 changes: 1 addition & 1 deletion keepassxc-browser/content/pwgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ kpxcPasswordIcons.deleteHiddenIcons = function() {
kpxcPasswordIcons.isValid = function(field) {
if (!field
|| field.readOnly
|| field.offsetWidth < MINIMUM_INPUT_FIELD_WIDTH
|| field.offsetWidth < MIN_INPUT_FIELD_OFFSET_WIDTH
|| kpxcIcons.hasIcon(field)
|| !kpxcFields.isVisible(field)) {
return false;
Expand Down
3 changes: 2 additions & 1 deletion keepassxc-browser/content/totp-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const acceptedOTPFields = [
'auth',
'challenge',
'code',
'idvpin',
'mfa',
'otp',
'token',
Expand Down Expand Up @@ -53,7 +54,7 @@ kpxcTOTPIcons.isValid = function(field, forced) {

if (!forced) {
if (ignoredTypes.some(t => t === field.type)
|| field.offsetWidth < MINIMUM_INPUT_FIELD_WIDTH
|| field.offsetWidth < MIN_INPUT_FIELD_OFFSET_WIDTH
|| field.size < 2
|| (field.maxLength > 0 && (field.maxLength < MIN_TOTP_INPUT_LENGTH || field.maxLength > kpxcSites.expectedTOTPMaxLength()))
|| ignoredTypes.some(t => t === field.autocomplete)
Expand Down
3 changes: 2 additions & 1 deletion keepassxc-browser/content/ui.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';

const MINIMUM_INPUT_FIELD_WIDTH = 60;
const MIN_TOTP_INPUT_LENGTH = 6;
const MAX_TOTP_INPUT_LENGTH = 10;
const MIN_INPUT_FIELD_WIDTH_PX = 8;
const MIN_INPUT_FIELD_OFFSET_WIDTH = 60;

const DatabaseState = {
DISCONNECTED: 0,
Expand Down
2 changes: 1 addition & 1 deletion keepassxc-browser/content/username-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ kpxcUsernameIcons.deleteHiddenIcons = function() {

kpxcUsernameIcons.isValid = function(field) {
if (!field
|| field.offsetWidth < MINIMUM_INPUT_FIELD_WIDTH
|| field.offsetWidth < MIN_INPUT_FIELD_OFFSET_WIDTH
|| field.readOnly
|| kpxcIcons.hasIcon(field)
|| !kpxcFields.isVisible(field)) {
Expand Down
4 changes: 2 additions & 2 deletions keepassxc-browser/manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"manifest_version": 2,
"name": "KeePassXC-Browser",
"version": "1.7.3",
"version_name": "1.7.3",
"version": "1.7.4",
"version_name": "1.7.4",
"description": "__MSG_extensionDescription__",
"author": "KeePassXC Team",
"icons": {
Expand Down
Loading

0 comments on commit 6ec8b55

Please sign in to comment.