Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
An earlier change had introduced saveSettings, which prevents the mouseleave event from saving settings when it was generated by closing the settings, help, or instructions panel.  Unfortunately, some tests have multiple phases separated by a mouseleave event.  I introduced a function restoreForTesting() that lets me override that behavior.
  • Loading branch information
alanhkarp committed Sep 24, 2024
1 parent 11d2cbc commit dc59adf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/ssp.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ let saveSettings = true;
let warningMsg = false;
let bg = bgDefault;

// Some actions prevent the settings being saved when mousing out of the main panel.
// However, some tests want to save the settings. This function sets certain values
// to what they have when the popup is opened.
export function restoreForTesting() {
autoclose = true;
exporting = false;
saveSettings = true;
warningMsg = false;
}

// I can't get the debugger statement to work unless I wait at least 1 second on Chrome
let timeout = debugMode ? 1000 : 0;
setTimeout(() => {
Expand Down Expand Up @@ -179,11 +189,7 @@ get("mainpanel").onmouseleave = async function (event) {
let phishingDomain = getPhishingDomain(get("sitename").value);
if (logging) console.log("popup mainpanel mouseleave", phishingDomain);
if (phishingDomain && saveSettings) openPhishingWarning(phishingDomain);
if (testMode) {
event.pageX = 0;
event.pageY = 0;
}
let element = event.pageX ? document.elementFromPoint(event.pageX, event.pageY) : null;
let element = event.pageX ? document.elementFromPoint(event.pageX || 0, event.pageY || 0) : null;
if (logging) console.log("popup onmouseleave", phishingDomain, exporting, element);
// Don't persist if: phishing sites, exporting, the mouse is in the panel, or if event triggered by closing a help or instruction panel
if (phishingDomain || exporting || element || !saveSettings) {
Expand Down Expand Up @@ -770,7 +776,6 @@ get("nicknamebutton").onclick = function () {
clearDatalist("sitenames");
msgoff("phishing");
autoclose = false;
saveSettings = false;
}
get("forgetbutton").onclick = async function () {
if (logging) console.log("popup forgetbutton");
Expand Down Expand Up @@ -867,7 +872,6 @@ function helpAllOff() {
for (let help of helps) {
helpItemOff(help.id);
}
saveSettings = false;
}
function hidesitepw() {
if (logging) console.log("popup checking hidesitepw", get("hidesitepw").checked, database.hidesitepw);
Expand Down
8 changes: 7 additions & 1 deletion src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// see an alert "Starting tests". Click OK and check the console for results.
import { defaultSettings, isSafari } from "./bg.js";
import { normalize } from "./generate.js";
import { getsettings } from "./ssp.js";
import { getsettings, restoreForTesting } from "./ssp.js";

export let resolvers = {};

Expand All @@ -30,6 +30,7 @@ export async function runTests() {
// Fields needed for tests
const $mainpanel = get("mainpanel");
const $settingsshow = get("settingsshow");
const $settingssave = get("settingssave");
const $domainname = get("domainname");
const $sitename = get("sitename");
const $username = get("username");
Expand Down Expand Up @@ -185,6 +186,7 @@ export async function runTests() {
// Does same account option work?
await phishingSetup();
await triggerEvent("click", $warningbutton, "warningbuttonResolver");
restoreForTesting();
await triggerEvent("mouseleave", $mainpanel, "mouseleaveResolver");
if (loggingPhishing) console.log("testPhishing same account", $phishing.style.display, $sitename.value, $username.value);
test = $phishing.style.display === "none";
Expand Down Expand Up @@ -289,6 +291,7 @@ export async function runTests() {
await triggerEvent("click", $settingsshow, "settingsshowResolver");
await fillForm("qwerty", "alantheguru.alanhkarp.com", "Guru", "alan");
await triggerEvent("click", $clearsuperpw, "clearsuperpwResolver");
restoreForTesting();
await triggerEvent("mouseleave", $mainpanel, "mouseleaveResolver");
let response = await chrome.runtime.sendMessage({"cmd": "getPassword"});
await triggerEvent("blur", $domainname, "domainnameblurResolver");
Expand Down Expand Up @@ -362,6 +365,7 @@ export async function runTests() {
if (chrome.runtime.lastError) console.error("resetState reset message error", chrome.runtime.lastError);
if (loggingReset) console.log("resetState reset message response", response);
clearForm();
restoreForTesting();
await getsettings("");
if (loggingClear) console.log("resetState done", $pwlength.value);
}
Expand Down Expand Up @@ -431,7 +435,9 @@ export async function runTests() {
if (loggingPhishing) console.log("phishingSetup state reset");
await fillForm("qwerty", "alantheguru.alanhkarp.com", "Guru", "alan");
if (loggingPhishing) console.log("phishingSetup mouseleave", $domainname.value, $sitename.value, $username.value);
if (isSafari) await chrome.storage.sync.clear();
await triggerEvent("mouseleave", $mainpanel, "mouseleaveResolver");
restoreForTesting();
// if (loggingPhishing) console.log("phishingSetup domainname blur", $sitename.value, $username.value);
// await triggerEvent("blur", $domainname, "domainnameblurResolver");
if (loggingPhishing) console.log("phishingSetup allantheguru click", $domainname.value, $sitename.value, $username.value);
Expand Down

0 comments on commit dc59adf

Please sign in to comment.