Commit f7af8094 authored by Jared Wein's avatar Jared Wein
Browse files

Bug 15500911 - Add button to open a a site from a login item. r=MattN,Pike

Differential Revision: https://phabricator.services.mozilla.com/D30975

--HG--
extra : moz-landing-system : lando
parent b3d1ba9b
......@@ -36,6 +36,7 @@ let LEGACY_ACTORS = {
module: "resource:///actors/AboutLoginsChild.jsm",
events: {
"AboutLoginsDeleteLogin": {wantUntrusted: true},
"AboutLoginsOpenSite": {wantUntrusted: true},
"AboutLoginsUpdateLogin": {wantUntrusted: true},
"AboutLoginsInit": {wantUntrusted: true},
},
......@@ -546,8 +547,9 @@ const listeners = {
mm: {
"AboutLogins:DeleteLogin": ["AboutLoginsParent"],
"AboutLogins:UpdateLogin": ["AboutLoginsParent"],
"AboutLogins:OpenSite": ["AboutLoginsParent"],
"AboutLogins:Subscribe": ["AboutLoginsParent"],
"AboutLogins:UpdateLogin": ["AboutLoginsParent"],
"Content:Click": ["ContentClick"],
"ContentSearch": ["ContentSearch"],
"FormValidation:ShowPopup": ["FormValidationHandler"],
......
......@@ -30,6 +30,10 @@ class AboutLoginsChild extends ActorChild {
this.mm.sendAsyncMessage("AboutLogins:DeleteLogin", {login: event.detail});
break;
}
case "AboutLoginsOpenSite": {
this.mm.sendAsyncMessage("AboutLogins:OpenSite", {login: event.detail});
break;
}
case "AboutLoginsUpdateLogin": {
this.mm.sendAsyncMessage("AboutLogins:UpdateLogin", {login: event.detail});
break;
......
......@@ -61,6 +61,17 @@ var AboutLoginsParent = {
Services.logins.removeLogin(login);
break;
}
case "AboutLogins:OpenSite": {
let guid = message.data.login.guid;
let logins = LoginHelper.searchLoginsWithObject({guid});
if (!logins || logins.length != 1) {
log.warn(`AboutLogins:OpenSite: expected to find a login for guid: ${guid} but found ${(logins || []).length}`);
return;
}
message.target.ownerGlobal.openWebLinkIn(logins[0].hostname, "tab", {relatedToCurrent: true});
break;
}
case "AboutLogins:Subscribe": {
if (!ChromeUtils.nondeterministicGetWeakSetKeys(this._subscribers).length) {
Services.obs.addObserver(this, "passwordmgr-storage-changed");
......
......@@ -28,6 +28,7 @@ login-item =
.edit-button = Edit
.hostname-label = Website Address
.modal-input-reveal-button = Toggle password visibility
.open-site-button = Launch
.password-label = Password
.save-changes-button = Save Changes
.time-created = Created: { DATETIME($timeCreated, day: "numeric", month: "long", year: "numeric") }
......
......@@ -34,6 +34,7 @@
edit-button,
hostname-label,
modal-input-reveal-button,
open-site-button,
password-label,
save-changes-button,
time-created,
......@@ -70,6 +71,7 @@
<span class="hostname-label field-label"></span>
<span class="hostname"/>
</label>
<button class="open-site-button"></button>
<label>
<span class="username-label field-label"></span>
<modal-input name="username"/>
......
......@@ -25,6 +25,7 @@ class LoginItem extends ReflectedFluentElement {
for (let selector of [
".delete-button",
".edit-button",
".open-site-button",
".save-changes-button",
".cancel-button",
]) {
......@@ -44,6 +45,7 @@ class LoginItem extends ReflectedFluentElement {
"edit-button",
"hostname-label",
"modal-input-reveal-button",
"open-site-button",
"password-label",
"save-changes-button",
"time-created",
......@@ -104,6 +106,13 @@ class LoginItem extends ReflectedFluentElement {
this.toggleEditing();
return;
}
if (event.target.classList.contains("open-site-button")) {
document.dispatchEvent(new CustomEvent("AboutLoginsOpenSite", {
bubbles: true,
detail: this._login,
}));
return;
}
if (event.target.classList.contains("save-changes-button")) {
let loginUpdates = {
guid: this._login.guid,
......
......@@ -4,4 +4,5 @@ prefs =
[browser_deleteLogin.js]
[browser_loginListChanges.js]
[browser_openSite.js]
[browser_updateLogin.js]
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
let nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
Ci.nsILoginInfo, "init");
const LOGIN_URL = "https://example.com/";
let TEST_LOGIN1 = new nsLoginInfo(LOGIN_URL, LOGIN_URL, null, "user1", "pass1", "username", "password");
add_task(async function setup() {
let storageChangedPromised = TestUtils.topicObserved("passwordmgr-storage-changed",
(_, data) => data == "addLogin");
TEST_LOGIN1 = Services.logins.addLogin(TEST_LOGIN1);
await storageChangedPromised;
await BrowserTestUtils.openNewForegroundTab({gBrowser, url: "about:logins"});
registerCleanupFunction(() => {
BrowserTestUtils.removeTab(gBrowser.selectedTab);
Services.logins.removeAllLogins();
});
});
add_task(async function test_launch_login_item() {
let promiseNewTab = BrowserTestUtils.waitForNewTab(gBrowser, LOGIN_URL);
let browser = gBrowser.selectedBrowser;
await ContentTask.spawn(browser, LoginHelper.loginToVanillaObject(TEST_LOGIN1), async (login) => {
let loginItem = Cu.waiveXrays(content.document.querySelector("login-item"));
loginItem.setLogin(login);
let openSiteButton = loginItem.shadowRoot.querySelector(".open-site-button");
openSiteButton.click();
});
info("waiting for new tab to get opened");
let newTab = await promiseNewTab;
ok(true, "New tab opened to " + LOGIN_URL);
BrowserTestUtils.removeTab(newTab);
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment