diff --git a/src/ssp.js b/src/ssp.js index 00b5335..00571ef 100644 --- a/src/ssp.js +++ b/src/ssp.js @@ -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(() => { @@ -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) { @@ -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"); @@ -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); diff --git a/src/test.js b/src/test.js index a9f152d..be8cfb0 100644 --- a/src/test.js +++ b/src/test.js @@ -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 = {}; @@ -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"); @@ -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"; @@ -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"); @@ -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); } @@ -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);