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
This commit is contained in:
sreeise 2018-10-31 09:25:02 +00:00
Родитель 0c08f9868b
Коммит 51060bfde7
9 изменённых файлов: 161 добавлений и 17 удалений

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

@ -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();

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

@ -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]

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

@ -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);
});

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

@ -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);
});

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

@ -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);
});

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

@ -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);
});

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

@ -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");

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

@ -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");
}
}

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

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Pocket Test</title>
</head>
<body>
<h1 id="pocket-actions-test">Pocket Actions Test</h1>
</body>
</html>