From 51060bfde7ea859f91547bac21d4fea5eccddc54 Mon Sep 17 00:00:00 2001 From: sreeise Date: Wed, 31 Oct 2018 09:25:02 +0000 Subject: [PATCH] Bug 1405477 - Added automated tests for pocket r=Gijs Added test for context menu button. Differential Revision: https://phabricator.services.mozilla.com/D8086 --HG-- extra : moz-landing-system : lando --- .../pocket/content/SaveToPocket.jsm | 8 ++-- browser/components/pocket/test/browser.ini | 5 +++ .../browser_pocket_context_menu_action.js | 36 +++++++++++++++++ .../browser_pocket_library_menu_action.js | 39 +++++++++++++++++++ .../test/browser_pocket_page_action_menu.js | 31 +++++++++++++++ .../pocket/test/browser_pocket_panel.js | 22 +++++++++++ .../pocket/test/browser_pocket_ui_check.js | 12 ------ browser/components/pocket/test/head.js | 15 ++++++- .../pocket/test/pocket_actions_test.html | 10 +++++ 9 files changed, 161 insertions(+), 17 deletions(-) create mode 100644 browser/components/pocket/test/browser_pocket_context_menu_action.js create mode 100644 browser/components/pocket/test/browser_pocket_library_menu_action.js create mode 100644 browser/components/pocket/test/browser_pocket_page_action_menu.js create mode 100644 browser/components/pocket/test/browser_pocket_panel.js create mode 100644 browser/components/pocket/test/pocket_actions_test.html diff --git a/browser/components/pocket/content/SaveToPocket.jsm b/browser/components/pocket/content/SaveToPocket.jsm index fce5374c7104..9a1e917d4bb4 100644 --- a/browser/components/pocket/content/SaveToPocket.jsm +++ b/browser/components/pocket/content/SaveToPocket.jsm @@ -430,10 +430,10 @@ var PocketOverlay = { } this.removeStyles(window); // remove script getters/objects - delete window.Pocket; - delete window.pktApi; - delete window.pktUI; - delete window.pktUIMessaging; + window.Pocket = undefined; + window.pktApi = undefined; + window.pktUI = undefined; + window.pktUIMessaging = undefined; } PocketContextMenu.shutdown(); diff --git a/browser/components/pocket/test/browser.ini b/browser/components/pocket/test/browser.ini index 3e0be8736f13..ca553a1aa075 100644 --- a/browser/components/pocket/test/browser.ini +++ b/browser/components/pocket/test/browser.ini @@ -2,5 +2,10 @@ support-files = head.js test.html + pocket_actions_test.html [browser_pocket_ui_check.js] +[browser_pocket_context_menu_action.js] +[browser_pocket_library_menu_action.js] +[browser_pocket_panel.js] +[browser_pocket_page_action_menu.js] diff --git a/browser/components/pocket/test/browser_pocket_context_menu_action.js b/browser/components/pocket/test/browser_pocket_context_menu_action.js new file mode 100644 index 000000000000..07ddf9f06fde --- /dev/null +++ b/browser/components/pocket/test/browser_pocket_context_menu_action.js @@ -0,0 +1,36 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +add_task(async function() { + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, + "https://example.com/browser/browser/components/pocket/test/test.html"); + + info("opening context menu"); + let contextMenu = document.getElementById("contentAreaContextMenu"); + let popupShown = BrowserTestUtils.waitForEvent(contextMenu, "popupshown"); + let popupHidden = BrowserTestUtils.waitForEvent(contextMenu, "popuphidden"); + + await BrowserTestUtils.synthesizeMouseAtCenter("body", { + type: "contextmenu", + button: 2, + }, tab.linkedBrowser); + await popupShown; + + info("opening pocket panel"); + let contextPocket = contextMenu.querySelector("#context-pocket"); + contextPocket.click(); + checkElements(true, ["pageActionActivatedActionPanel"]); + + info("closing pocket panel"); + let pocketPanel = document.getElementById("pageActionActivatedActionPanel"); + let pocketPanelHidden = BrowserTestUtils.waitForEvent(pocketPanel, "popuphidden"); + + pocketPanel.hidePopup(); + await pocketPanelHidden; + checkElements(false, ["pageActionActivatedActionPanel"]); + + contextMenu.hidePopup(); + await popupHidden; + BrowserTestUtils.removeTab(tab); +}); diff --git a/browser/components/pocket/test/browser_pocket_library_menu_action.js b/browser/components/pocket/test/browser_pocket_library_menu_action.js new file mode 100644 index 000000000000..61a74d205caa --- /dev/null +++ b/browser/components/pocket/test/browser_pocket_library_menu_action.js @@ -0,0 +1,39 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +add_task(async function test_setup() { + await SpecialPowers.pushPrefEnv({set: [["extensions.pocket.site", + "example.com/browser/browser/components/pocket/test/pocket_actions_test.html"]], + }); +}); + +add_task(async function() { + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, + "https://example.com/browser/browser/components/pocket/test/test.html"); + + let libraryButton = document.getElementById("library-button"); + let libraryView = document.getElementById("appMenu-libraryView"); + + info("opening library menu"); + let libraryPromise = BrowserTestUtils.waitForEvent(libraryView, "ViewShown"); + libraryButton.click(); + await libraryPromise; + + let pocketLibraryButton = document.getElementById("appMenu-library-pocket-button"); + ok(pocketLibraryButton, "library menu should have pocket button"); + is(pocketLibraryButton.disabled, false, "element appMenu-library-pocket-button is not disabled"); + + info("clicking on pocket library button"); + let pocketPagePromise = BrowserTestUtils.waitForNewTab(gBrowser, + "https://example.com/browser/browser/components/pocket/test/pocket_actions_test.html/?src=ff_ext"); + pocketLibraryButton.click(); + await pocketPagePromise; + + is(gBrowser.currentURI.spec, + "https://example.com/browser/browser/components/pocket/test/pocket_actions_test.html/?src=ff_ext", + "pocket button in library menu button opens correct page"); + + BrowserTestUtils.removeTab(tab); + BrowserTestUtils.removeTab(gBrowser.selectedTab); +}); diff --git a/browser/components/pocket/test/browser_pocket_page_action_menu.js b/browser/components/pocket/test/browser_pocket_page_action_menu.js new file mode 100644 index 000000000000..07a685d317f5 --- /dev/null +++ b/browser/components/pocket/test/browser_pocket_page_action_menu.js @@ -0,0 +1,31 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +add_task(async function() { + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, + "https://example.com/browser/browser/components/pocket/test/test.html"); + + let pageActionContextMenu = document.getElementById("pageActionPanel"); + let pageActionButton = document.getElementById("pageActionButton"); + let pageActionShown = BrowserTestUtils.waitForEvent(pageActionContextMenu, "popupshown"); + let pageActionHidden = BrowserTestUtils.waitForEvent(pageActionContextMenu, "popuphidden"); + + info("opening page action panel"); + pageActionButton.click(); + await pageActionShown; + checkElements(true, ["pageAction-panel-pocket"]); + + let pocketButton = document.getElementById("pageAction-panel-pocket"); + info("clicking on pageAction-panel-pocket"); + pocketButton.click(); + await pageActionHidden; + + let pocketPanel = document.getElementById("pageActionActivatedActionPanel"); + is(pocketPanel.state, "showing", "panel pageActionActivatedActionPanel is showing"); + + let pocketPanelHidden = BrowserTestUtils.waitForEvent(pocketPanel, "popuphidden"); + pocketPanel.hidePopup(); + await pocketPanelHidden; + BrowserTestUtils.removeTab(tab); +}); diff --git a/browser/components/pocket/test/browser_pocket_panel.js b/browser/components/pocket/test/browser_pocket_panel.js new file mode 100644 index 000000000000..5f12d110c1d9 --- /dev/null +++ b/browser/components/pocket/test/browser_pocket_panel.js @@ -0,0 +1,22 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +add_task(async function() { + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, + "https://example.com/browser/browser/components/pocket/test/test.html"); + + info("clicking on pocket button in url bar"); + let pocketButton = document.getElementById("pocket-button"); + pocketButton.click(); + + checkElements(true, ["pageActionActivatedActionPanel"]); + let pocketPanel = document.getElementById("pageActionActivatedActionPanel"); + is(pocketPanel.state, "showing", "pocket panel is showing"); + + info("closing pocket panel"); + pocketButton.click(); + checkElements(false, ["pageActionActivatedActionPanel"]); + + BrowserTestUtils.removeTab(tab); +}); diff --git a/browser/components/pocket/test/browser_pocket_ui_check.js b/browser/components/pocket/test/browser_pocket_ui_check.js index b29738df3e18..81218a0977a2 100644 --- a/browser/components/pocket/test/browser_pocket_ui_check.js +++ b/browser/components/pocket/test/browser_pocket_ui_check.js @@ -1,17 +1,5 @@ "use strict"; -function checkWindowProperties(expectPresent, l) { - for (let name of l) { - is(!!window.hasOwnProperty(name), expectPresent, "property " + name + (expectPresent ? " is" : " is not") + " present"); - } -} -function checkElements(expectPresent, l) { - for (let id of l) { - let el = document.getElementById(id) || gNavToolbox.palette.querySelector("#" + id); - is(!!el, expectPresent, "element " + id + (expectPresent ? " is" : " is not") + " present"); - } -} - add_task(async function test_setup() { let clearValue = Services.prefs.prefHasUserValue("extensions.pocket.enabled"); let enabledOnStartup = Services.prefs.getBoolPref("extensions.pocket.enabled"); diff --git a/browser/components/pocket/test/head.js b/browser/components/pocket/test/head.js index 07307c43179e..a538ac85760d 100644 --- a/browser/components/pocket/test/head.js +++ b/browser/components/pocket/test/head.js @@ -34,7 +34,7 @@ function promisePocketDisabled() { }).then(() => { // wait for a full unload of pocket return BrowserTestUtils.waitForCondition(() => { - return !window.hasOwnProperty("pktUI"); + return !window.hasOwnProperty("pktUI") || !window.pktUI; }); }); } @@ -47,3 +47,16 @@ function promisePocketReset() { info("reset is disabling pocket addon"); return promisePocketDisabled(); } + +function checkWindowProperties(expectPresent, l) { + for (let name of l) { + is(window.hasOwnProperty(name) && !!window[name], expectPresent, "property " + name + (expectPresent ? " is" : " is not") + " present"); + } +} + +function checkElements(expectPresent, l) { + for (let id of l) { + let el = document.getElementById(id) || gNavToolbox.palette.querySelector("#" + id); + is(!!el, expectPresent, "element " + id + (expectPresent ? " is" : " is not") + " present"); + } +} diff --git a/browser/components/pocket/test/pocket_actions_test.html b/browser/components/pocket/test/pocket_actions_test.html new file mode 100644 index 000000000000..98aa4c60eab6 --- /dev/null +++ b/browser/components/pocket/test/pocket_actions_test.html @@ -0,0 +1,10 @@ + + + + + Pocket Test + + +

Pocket Actions Test

+ +