browser_topsites_contextMenu_options.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. test_newtab({
  6. before: setDefaultTopSites,
  7. // Test verifies the menu options for a default top site.
  8. test: async function defaultTopSites_menuOptions() {
  9. const siteSelector = ".top-site-outer:not(.search-shortcut):not(.placeholder)";
  10. await ContentTaskUtils.waitForCondition(() => content.document.querySelector(siteSelector),
  11. "Topsite tippytop icon not found");
  12. const contextMenuItems = content.openContextMenuAndGetOptions(siteSelector).map(v => v.textContent);
  13. Assert.equal(contextMenuItems.length, 5, "Number of options is correct");
  14. const expectedItemsText = ["Pin", "Edit", "Open in a New Window", "Open in a New Private Window", "Dismiss"];
  15. for (let i = 0; i < contextMenuItems.length; i++) {
  16. Assert.equal(contextMenuItems[i], expectedItemsText[i], "Name option is correct");
  17. }
  18. },
  19. });
  20. test_newtab({
  21. before: setDefaultTopSites,
  22. // Test verifies that the next top site in queue replaces a dismissed top site.
  23. test: async function defaultTopSites_dismiss() {
  24. const siteSelector = ".top-site-outer:not(.search-shortcut):not(.placeholder)";
  25. await ContentTaskUtils.waitForCondition(() => content.document.querySelector(siteSelector),
  26. "Topsite tippytop icon not found");
  27. // Don't count search topsites
  28. const defaultTopSitesNumber = content.document.querySelectorAll(siteSelector).length;
  29. Assert.equal(defaultTopSitesNumber, 5, "5 top sites are loaded by default");
  30. // Skip the search topsites select the second default topsite
  31. const secondTopSite = content.document.querySelectorAll(siteSelector)[1].getAttribute("href");
  32. const contextMenuItems = content.openContextMenuAndGetOptions(siteSelector);
  33. Assert.equal(contextMenuItems[4].textContent, "Dismiss", "'Dismiss' is the 5th item in the context menu list");
  34. contextMenuItems[4].querySelector("button").click();
  35. // Wait for the topsite to be dismissed and the second one to replace it
  36. await ContentTaskUtils.waitForCondition(() => content.document.querySelector(siteSelector).getAttribute("href") === secondTopSite,
  37. "First default topsite was dismissed");
  38. await ContentTaskUtils.waitForCondition(() => content.document.querySelectorAll(siteSelector).length === 4, "4 top sites are displayed after one of them is dismissed");
  39. },
  40. async after() {
  41. await new Promise(resolve => NewTabUtils.undoAll(resolve));
  42. },
  43. });
  44. test_newtab({
  45. before: setDefaultTopSites,
  46. test: async function searchTopSites_dismiss() {
  47. const siteSelector = ".search-shortcut";
  48. await ContentTaskUtils.waitForCondition(() => content.document.querySelectorAll(siteSelector).length === 1,
  49. "1 search topsites is loaded by default");
  50. const contextMenuItems = content.openContextMenuAndGetOptions(siteSelector);
  51. is(contextMenuItems.length, 2, "Search TopSites should only have Unpin and Dismiss");
  52. // Unpin
  53. contextMenuItems[0].querySelector("button").click();
  54. await ContentTaskUtils.waitForCondition(() => content.document.querySelectorAll(siteSelector).length === 1,
  55. "1 search topsite displayed after we unpin the other one");
  56. },
  57. after: () => {
  58. // Required for multiple test runs in the same browser, pref is used to
  59. // prevent pinning the same search topsite twice
  60. Services.prefs.clearUserPref("browser.newtabpage.activity-stream.improvesearch.topSiteSearchShortcuts.havePinned");
  61. },
  62. });