Backed out changeset 19efa711bd54 (bug 1714749) for causing assertion failures at foundWebScheme. CLOSED TREE

This commit is contained in:
Butkovits Atila 2021-07-07 04:40:29 +03:00
Родитель 2ec5e2abd7
Коммит 9d17bf1f4b
5 изменённых файлов: 26 добавлений и 107 удалений

Просмотреть файл

@ -11,12 +11,6 @@ ChromeUtils.defineModuleGetter(
"chrome://pocket/content/pktApi.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"SaveToPocket",
"chrome://pocket/content/SaveToPocket.jsm"
);
class AboutPocketParent extends JSWindowActorParent {
sendResponseMessageToPanel(messageId, panelId, payload) {
this.sendAsyncMessage(`${messageId}_response_${panelId}`, payload);
@ -136,7 +130,9 @@ class AboutPocketParent extends JSWindowActorParent {
pktApi.deleteItem(message.data.payload.itemId, {
success: () => {
resolve({ status: "success" });
SaveToPocket.itemDeleted();
this.browsingContext.topChromeWindow?.pktUI
.getPanelFrame()
.setAttribute("itemAdded", "false");
},
error: error => resolve({ status: "error", error }),
});

Просмотреть файл

@ -45,8 +45,6 @@ var PocketCustomizableWidget = {
l10nId: "save-to-pocket-button",
type: "view",
viewId: "PanelUI-savetopocket",
// This closes any open Pocket panels if you change tabs.
tabSpecific: true,
onViewShowing(aEvent) {
let panelView = aEvent.target;
let panelNode = panelView.querySelector(
@ -65,6 +63,17 @@ var PocketCustomizableWidget = {
let panelNode = panelView.querySelector(
".PanelUI-savetopocket-container"
);
let frame = panelNode.querySelector("browser");
let browser = panelNode.ownerGlobal.gBrowser.selectedBrowser;
if (frame.getAttribute("itemAdded") == "true") {
SaveToPocket.innerWindowIDsByBrowser.set(
browser,
browser.innerWindowID
);
} else {
SaveToPocket.innerWindowIDsByBrowser.delete(browser);
}
panelNode.textContent = "";
SaveToPocket.updateToolbarNodeState(panelNode.ownerGlobal);
@ -248,24 +257,6 @@ var SaveToPocket = {
Pocket._initPanelView(window);
},
// If an item is saved to Pocket, we cache the browser's inner window ID,
// so if you navigate to that tab again, we can check the ID
// and see if we need to update the toolbar icon.
itemSaved() {
const browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
const browser = browserWindow.gBrowser.selectedBrowser;
SaveToPocket.innerWindowIDsByBrowser.set(browser, browser.innerWindowID);
},
// If an item is removed from Pocket, we remove that browser's inner window ID,
// so if you navigate to that tab again, we can check the ID
// and see if we need to update the toolbar icon.
itemDeleted() {
const browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
const browser = browserWindow.gBrowser.selectedBrowser;
SaveToPocket.innerWindowIDsByBrowser.delete(browser);
},
updateElements(enabled) {
// loop through windows and show/hide all our elements.
for (let win of browserWindows()) {

Просмотреть файл

@ -59,11 +59,6 @@ ChromeUtils.defineModuleGetter(
"pktApi",
"chrome://pocket/content/pktApi.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"SaveToPocket",
"chrome://pocket/content/SaveToPocket.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"pktTelemetry",
@ -249,8 +244,6 @@ var pktUI = (function() {
}
function onShowSignup() {
// Ensure opening the signup panel clears the icon state from any previous sessions.
SaveToPocket.itemDeleted();
// A successful button click, for logged out users.
pktTelemetry.sendStructuredIngestionEvent(
pktTelemetry.createPingPayload({
@ -280,6 +273,7 @@ var pktUI = (function() {
function onShowSaved() {
var saveLinkMessageId = "PKT_saveLink";
getPanelFrame().setAttribute("itemAdded", "false");
// Send error message for invalid url
if (!isValidURL()) {
@ -338,7 +332,7 @@ var pktUI = (function() {
_panelId,
successResponse
);
SaveToPocket.itemSaved();
getPanelFrame().setAttribute("itemAdded", "true");
getAndShowRecsForItem(item, {
success(data) {
@ -532,11 +526,16 @@ var pktUI = (function() {
}
function closePanel() {
// The panel frame doesn't exist until the Pocket panel is showing.
// So we ensure it is open before attempting to hide it.
getPanelFrame()
?.closest("panel")
?.hidePopup();
getPanel().hidePopup();
}
function getPanel() {
var frame = getPanelFrame();
var panel = frame;
while (panel && panel.localName != "panel") {
panel = panel.parentNode;
}
return panel;
}
var toolbarPanelFrame;

Просмотреть файл

@ -7,4 +7,3 @@ support-files =
[browser_pocket_context_menu_action.js]
[browser_pocket_panel.js]
[browser_pocket_home_panel.js]
[browser_pocket_button_icon_state.js]

Просмотреть файл

@ -1,66 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
ChromeUtils.defineModuleGetter(
this,
"SaveToPocket",
"chrome://pocket/content/SaveToPocket.jsm"
);
add_task(async function() {
let tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
"https://example.com/browser/browser/components/pocket/test/test.html"
);
// We're faking a logged in test, so initially we need to fake the logged in state.
const loggedInStub = sinon
.stub(pktApi, "isUserLoggedIn")
.callsFake(() => true);
// Also we cannot actually make remote requests, so make sure we stub any functions
// we need that that make requests to api.getpocket.com.
const addLinkStub = sinon.stub(pktApi, "addLink").callsFake(() => true);
info("clicking on pocket button in toolbar");
let pocketButton = document.getElementById("save-to-pocket-button");
// The panel is created on the fly, so we can't simply wait for focus
// inside it.
let pocketPanelShowing = BrowserTestUtils.waitForEvent(
document,
"popupshown",
true
);
pocketButton.click();
await pocketPanelShowing;
// Because we're not actually logged into a remote Pocket account,
// and because we're not actually saving anything,
// we fake it, instead, by calling the function we care about.
SaveToPocket.itemSaved();
// This fakes the button from just opened, to also pocketed,
// we currently expect both from a save.
SaveToPocket.updateToolbarNodeState(window);
// The Pocket button should be set to open.
is(pocketButton.open, true, "Pocket button is open");
is(pocketButton.getAttribute("pocketed"), "true", "Pocket item is pocketed");
let pocketPanelHidden = BrowserTestUtils.waitForEvent(
document,
"popuphidden"
);
// Mochitests start with an open tab, so use that to trigger a tab change.
await BrowserTestUtils.switchTab(gBrowser, gBrowser.tabs[0]);
await pocketPanelHidden;
// Opening a new tab should have closed the Pocket panel, icon should no longer be red.
is(pocketButton.open, false, "Pocket button is closed");
is(pocketButton.getAttribute("pocketed"), "", "Pocket item is not pocketed");
loggedInStub.restore();
addLinkStub.restore();
BrowserTestUtils.removeTab(tab);
});