browser_asrouter_bookmarkpanel.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. const {PanelTestProvider} = ChromeUtils.import("resource://activity-stream/lib/PanelTestProvider.jsm");
  2. const {BookmarkPanelHub} = ChromeUtils.import("resource://activity-stream/lib/BookmarkPanelHub.jsm");
  3. add_task(async function test_fxa_message_shown() {
  4. const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
  5. registerCleanupFunction(async () => {
  6. await clearHistoryAndBookmarks();
  7. BrowserTestUtils.removeTab(tab);
  8. });
  9. const testURL = "data:text/plain,test cfr fxa bookmark panel message";
  10. const browser = gBrowser.selectedBrowser;
  11. await SpecialPowers.pushPrefEnv({set: [["browser.newtabpage.activity-stream.asrouter.devtoolsEnabled", false]]});
  12. BrowserTestUtils.loadURI(browser, testURL);
  13. await BrowserTestUtils.browserLoaded(browser, false, testURL);
  14. const [msg] = PanelTestProvider.getMessages();
  15. const response = BookmarkPanelHub.onResponse(msg, {
  16. container: document.getElementById("editBookmarkPanelRecommendation"),
  17. infoButton: document.getElementById("editBookmarkPanelInfoButton"),
  18. recommendationContainer: document.getElementById("editBookmarkPanelRecommendation"),
  19. url: testURL,
  20. document,
  21. }, window);
  22. Assert.ok(response, "We sent a valid message");
  23. const popupShownPromise = BrowserTestUtils.waitForEvent(StarUI.panel, "popupshown");
  24. // Wait for the bookmark panel state to settle and be ready to open the panel
  25. await BrowserTestUtils.waitForCondition(() => BookmarkingUI.status !== BookmarkingUI.STATUS_UPDATING);
  26. BookmarkingUI.star.click();
  27. await popupShownPromise;
  28. await BrowserTestUtils.waitForCondition(() => document.getElementById("cfrMessageContainer"), `Should create a
  29. container for the message`);
  30. Assert.equal(document.getElementById("cfrMessageContainer").childElementCount, 4,
  31. `Should attach 4 children elements`);
  32. const ftlFiles = Array.from(document.querySelectorAll("link"))
  33. .filter(l => l.getAttribute("href") === "browser/newtab/asrouter.ftl" ||
  34. l.getAttribute("href") === "browser/branding/sync-brand.ftl");
  35. Assert.equal(ftlFiles.length, 2, "Two fluent files required for translating the message");
  36. const popupHiddenPromise = BrowserTestUtils.waitForEvent(StarUI.panel, "popuphidden");
  37. let removeButton = document.getElementById("editBookmarkPanelRemoveButton");
  38. removeButton.click();
  39. await popupHiddenPromise;
  40. });