browser_topsites_section.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. "use strict";
  2. // Check TopSites edit modal and overlay show up.
  3. test_newtab(
  4. // it should be able to click the topsites add button to reveal the add top site modal and overlay.
  5. function topsites_edit() {
  6. // Open the section context menu.
  7. content.document.querySelector(".top-sites .section-top-bar .context-menu-button").click();
  8. let contextMenu = content.document.querySelector(".top-sites .section-top-bar .context-menu");
  9. ok(contextMenu, "Should find a visible topsite context menu");
  10. const topsitesAddBtn = content.document.querySelector(".top-sites .context-menu-item button");
  11. topsitesAddBtn.click();
  12. let found = content.document.querySelector(".topsite-form");
  13. ok(found && !found.hidden, "Should find a visible topsite form");
  14. found = content.document.querySelector(".modalOverlayOuter");
  15. ok(found && !found.hidden, "Should find a visible overlay");
  16. }
  17. );
  18. // Test pin/unpin context menu options.
  19. test_newtab({
  20. before: setDefaultTopSites,
  21. // it should pin the website when we click the first option of the topsite context menu.
  22. test: async function topsites_pin_unpin() {
  23. const siteSelector = ".top-site-outer:not(.search-shortcut):not(.placeholder)";
  24. await ContentTaskUtils.waitForCondition(() => content.document.querySelector(siteSelector),
  25. "Topsite tippytop icon not found");
  26. // There are only topsites on the page, the selector with find the first topsite menu button.
  27. let topsiteEl = content.document.querySelector(siteSelector);
  28. let topsiteContextBtn = topsiteEl.querySelector(".context-menu-button");
  29. topsiteContextBtn.click();
  30. await ContentTaskUtils.waitForCondition(() => topsiteEl.querySelector(".top-sites-list .context-menu"),
  31. "No context menu found");
  32. let contextMenu = topsiteEl.querySelector(".top-sites-list .context-menu");
  33. ok(contextMenu, "Should find a topsite context menu");
  34. const pinUnpinTopsiteBtn = contextMenu.querySelector(".top-sites .context-menu-item button");
  35. // Pin the topsite.
  36. pinUnpinTopsiteBtn.click();
  37. // Need to wait for pin action.
  38. await ContentTaskUtils.waitForCondition(() => topsiteEl.querySelector(".icon-pin-small"),
  39. "No pinned icon found");
  40. let pinnedIcon = topsiteEl.querySelectorAll(".icon-pin-small").length;
  41. is(pinnedIcon, 1, "should find 1 pinned topsite");
  42. // Unpin the topsite.
  43. topsiteContextBtn = topsiteEl.querySelector(".context-menu-button");
  44. ok(topsiteContextBtn, "Should find a context menu button");
  45. topsiteContextBtn.click();
  46. topsiteEl.querySelector(".context-menu-item button").click();
  47. // Need to wait for unpin action.
  48. await ContentTaskUtils.waitForCondition(() => !topsiteEl.querySelector(".icon-pin-small"),
  49. "Topsite should be unpinned");
  50. },
  51. });
  52. // Check Topsites add
  53. test_newtab({
  54. before: setDefaultTopSites,
  55. // it should be able to click the topsites edit button to reveal the edit topsites modal and overlay.
  56. test: async function topsites_add() {
  57. let nativeInputValueSetter = Object.getOwnPropertyDescriptor(content.window.HTMLInputElement.prototype, "value").set;
  58. let event = new content.Event("input", {bubbles: true});
  59. // Find the add topsites button
  60. content.document.querySelector(".top-sites .section-top-bar .context-menu-button").click();
  61. let contextMenu = content.document.querySelector(".top-sites .section-top-bar .context-menu");
  62. ok(contextMenu, "Should find a visible topsite context menu");
  63. const topsitesAddBtn = content.document.querySelector(".top-sites .context-menu-item button");
  64. topsitesAddBtn.click();
  65. let found = content.document.querySelector(".modalOverlayOuter");
  66. ok(found && !found.hidden, "Should find a visible overlay");
  67. // Write field title
  68. let fieldTitle = content.document.querySelector(".field input");
  69. ok(fieldTitle && !fieldTitle.hidden, "Should find field title input");
  70. nativeInputValueSetter.call(fieldTitle, "Bugzilla");
  71. fieldTitle.dispatchEvent(event);
  72. is(fieldTitle.value, "Bugzilla", "The field title should match");
  73. // Write field url
  74. let fieldURL = content.document.querySelector(".field.url input");
  75. ok(fieldURL && !fieldURL.hidden, "Should find field url input");
  76. nativeInputValueSetter.call(fieldURL, "https://bugzilla.mozilla.org");
  77. fieldURL.dispatchEvent(event);
  78. is(fieldURL.value, "https://bugzilla.mozilla.org", "The field url should match");
  79. // Click the "Add" button
  80. let addBtn = content.document.querySelector(".done");
  81. addBtn.click();
  82. // Wait for Topsite to be populated
  83. await ContentTaskUtils.waitForCondition(() => (content.document.querySelector(".top-site-outer:first-child a").getAttribute("href") === "https://bugzilla.mozilla.org"), "No Topsite found");
  84. // Remove topsite after test is complete
  85. let topsiteContextBtn = content.document.querySelector(".top-sites-list .context-menu-button");
  86. topsiteContextBtn.click();
  87. await ContentTaskUtils.waitForCondition(() => content.document.querySelector(".top-sites-list .context-menu"),
  88. "No context menu found");
  89. let contextMen = content.document.querySelector(".top-sites-list .context-menu");
  90. const dismissBtn = contextMen.querySelector(".top-sites .context-menu-item button .icon-dismiss");
  91. dismissBtn.click();
  92. // Wait for Topsite to be removed
  93. await ContentTaskUtils.waitForCondition(() => (content.document.querySelector(".top-site-outer:first-child a").getAttribute("href") !== "https://bugzilla.mozilla.org"), "Topsite not removed");
  94. },
  95. });
  96. test_newtab({
  97. before: setDefaultTopSites,
  98. test: async function test_search_topsite_keyword() {
  99. await ContentTaskUtils.waitForCondition(() => content.document.querySelector(".search-shortcut .title.pinned"), "Wait for pinned search topsites");
  100. const searchTopSites = content.document.querySelectorAll(".title.pinned");
  101. ok(searchTopSites.length >= 1, "There should be at least 2 search topsites");
  102. searchTopSites[0].click();
  103. return searchTopSites[0].innerText;
  104. },
  105. after(searchTopSiteTag) {
  106. ok(gURLBar.focused, "We clicked a search topsite the focus should be in location bar");
  107. ok(gURLBar.value.includes(searchTopSiteTag), "Should contain the tag of the search topsite clicked");
  108. },
  109. });