Bug 1410818 - Add a test to verify the menu options for a default top site. r=Mardak

This commit is contained in:
Ioana Crisan 2018-02-22 15:25:45 +02:00
parent c6d3def00e
commit abf91f5026
4 changed files with 66 additions and 7 deletions

View File

@ -7,4 +7,5 @@ support-files =
[browser_as_render.js]
[browser_getScreenshots.js]
[browser_highlights_section.js]
[browser_topsites_contextMenu_options.js]
[browser_topsites_section.js]

View File

@ -0,0 +1,27 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/**
* Test verifies the menu options for a default top site.
*/
test_newtab({
before: setDefaultTopSites,
test: async function defaultTopSites_menuOptions() {
await ContentTaskUtils.waitForCondition(() => content.document.querySelector(".top-site-icon"),
"Topsite tippytop icon not found");
let contextMenuItems = content.openContextMenuAndGetOptions(".top-sites-list li:first-child").map(v => v.textContent);
Assert.equal(contextMenuItems.length, 5, "Number of options is correct");
const expectedItemsText = ["Pin", "Edit", "Open in a New Window", "Open in a New Private Window", "Dismiss"];
for (let i = 0; i < contextMenuItems.length; i++) {
Assert.equal(contextMenuItems[i], expectedItemsText[i], "Name option is correct");
}
}
});

View File

@ -17,13 +17,7 @@ test_newtab(
// Test pin/unpin context menu options.
test_newtab({
async before({pushPrefs}) {
// The pref for TopSites is empty by default.
await pushPrefs(["browser.newtabpage.activity-stream.default.sites", "https://www.youtube.com/,https://www.facebook.com/,https://www.amazon.com/,https://www.reddit.com/,https://www.wikipedia.org/,https://twitter.com/"]);
// Toggle the feed off and on as a workaround to read the new prefs.
await pushPrefs(["browser.newtabpage.activity-stream.feeds.topsites", false]);
await pushPrefs(["browser.newtabpage.activity-stream.feeds.topsites", true]);
},
before: setDefaultTopSites,
// it should pin the website when we click the first option of the topsite context menu.
test: async function topsites_pin_unpin() {
await ContentTaskUtils.waitForCondition(() => content.document.querySelector(".top-site-icon"),

View File

@ -10,6 +10,15 @@ function pushPrefs(...prefs) {
return SpecialPowers.pushPrefEnv({set: prefs});
}
async function setDefaultTopSites() {
// The pref for TopSites is empty by default.
await pushPrefs(["browser.newtabpage.activity-stream.default.sites",
"https://www.youtube.com/,https://www.facebook.com/,https://www.amazon.com/,https://www.reddit.com/,https://www.wikipedia.org/,https://twitter.com/"]);
// Toggle the feed off and on as a workaround to read the new prefs.
await pushPrefs(["browser.newtabpage.activity-stream.feeds.topsites", false]);
await pushPrefs(["browser.newtabpage.activity-stream.feeds.topsites", true]);
}
async function clearHistoryAndBookmarks() { // eslint-disable-line no-unused-vars
await PlacesUtils.bookmarks.eraseEverything();
await PlacesUtils.history.clear();
@ -57,6 +66,31 @@ async function addHighlightsBookmarks(count) { // eslint-disable-line no-unused-
refreshHighlightsFeed();
}
/**
* Helper to add various helpers to the content process by injecting variables
* and functions to the `content` global.
*/
function addContentHelpers() {
const {document} = content;
Object.assign(content, {
/**
* Click the context menu button for an item and get its options list.
*
* @param selector {String} Selector to get an item (e.g., top site, card)
* @return {Array} The nodes for the options.
*/
openContextMenuAndGetOptions(selector) {
const item = document.querySelector(selector);
const contextButton = item.querySelector(".context-menu-button");
contextButton.click();
const contextMenu = item.querySelector(".context-menu");
const contextMenuList = contextMenu.querySelector(".context-menu-list");
return [...contextMenuList.getElementsByClassName("context-menu-item")];
}
});
}
/**
* Helper to run Activity Stream about:newtab test tasks in content.
*
@ -104,6 +138,9 @@ function test_newtab(testInfo) { // eslint-disable-line no-unused-vars
let browser = tab.linkedBrowser;
await waitForPreloaded(browser);
// Add shared helpers to the content process
ContentTask.spawn(browser, {}, addContentHelpers);
// Wait for React to render something
await BrowserTestUtils.waitForCondition(() => ContentTask.spawn(browser, {},
() => content.document.getElementById("root").children.length),