browser_highlights_section.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. "use strict";
  2. /**
  3. * Helper for setup and cleanup of Highlights section tests.
  4. * @param bookmarkCount Number of bookmark higlights to add
  5. * @param test The test case
  6. */
  7. function test_highlights(bookmarkCount, test) {
  8. test_newtab({
  9. async before({tab}) {
  10. if (bookmarkCount) {
  11. await addHighlightsBookmarks(bookmarkCount);
  12. // Wait for HighlightsFeed to update and display the items.
  13. await ContentTask.spawn(tab.linkedBrowser, null, async () => {
  14. await ContentTaskUtils.waitForCondition(() => content.document.querySelector(".card-outer:not(.placeholder)"),
  15. "No highlights cards found.");
  16. });
  17. }
  18. },
  19. test,
  20. async after() {
  21. await clearHistoryAndBookmarks();
  22. },
  23. });
  24. }
  25. test_highlights(
  26. 2, // Number of highlights cards
  27. function check_highlights_cards() {
  28. let found = content.document.querySelectorAll(".card-outer:not(.placeholder)").length;
  29. is(found, 2, "there should be 2 highlights cards");
  30. found = content.document.querySelectorAll(".section-list .placeholder").length;
  31. is(found, 6, "there should be 2 rows * 4 - 2 = 6 highlights placeholder");
  32. found = content.document.querySelectorAll(".card-context-icon.icon-bookmark-added").length;
  33. is(found, 2, "there should be 2 bookmark icons");
  34. }
  35. );
  36. test_highlights(
  37. 1, // Number of highlights cards
  38. function check_highlights_context_menu() {
  39. const menuButton = content.document.querySelector(".card-outer .context-menu-button");
  40. // Open the menu.
  41. menuButton.click();
  42. const found = content.document.querySelector(".card-outer .context-menu");
  43. ok(found && !found.hidden, "Should find a visible context menu");
  44. }
  45. );
  46. test_highlights(
  47. 1, // Number of highlights cards
  48. async function check_highlights_context_menu() {
  49. let found = content.document.querySelectorAll(".card-context-icon.icon-bookmark-added").length;
  50. is(found, 1, "there should be 1 bookmark icon");
  51. const menuButton = content.document.querySelector(".card-outer .context-menu-button");
  52. // Open the menu.
  53. menuButton.click();
  54. const contextMenu = content.document.querySelector(".card-outer .context-menu");
  55. ok(contextMenu && !contextMenu.hidden, "Should find a visible context menu");
  56. const removeBookmarkBtn = contextMenu.querySelector("button .icon-bookmark-added");
  57. removeBookmarkBtn.click();
  58. await ContentTaskUtils.waitForCondition(() => content.document.querySelectorAll(".card-context-icon.icon-bookmark-added").length === 0,
  59. "no more bookmark cards should be visible");
  60. }
  61. );