browser_aboutwelcome.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. "use strict";
  2. const {ASRouter} = ChromeUtils.import("resource://activity-stream/lib/ASRouter.jsm");
  3. const BRANCH_PREF = "trailhead.firstrun.branches";
  4. /**
  5. * Sets the trailhead branch pref to the passed value.
  6. */
  7. async function setTrailheadBranch(value) {
  8. Services.prefs.setCharPref(BRANCH_PREF, value);
  9. // Reset trailhead so it loads the new branch.
  10. Services.prefs.clearUserPref("trailhead.firstrun.didSeeAboutWelcome");
  11. await ASRouter.setState({trailheadInitialized: false});
  12. await ASRouter.setupTrailhead();
  13. registerCleanupFunction(() => {
  14. Services.prefs.clearUserPref(BRANCH_PREF);
  15. });
  16. }
  17. /**
  18. * Test a specific trailhead branch.
  19. */
  20. async function test_trailhead_branch(branchName, expectedSelectors = [], unexpectedSelectors = []) {
  21. await setTrailheadBranch(branchName);
  22. let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:welcome", false);
  23. let browser = tab.linkedBrowser;
  24. await ContentTask.spawn(
  25. browser,
  26. {expectedSelectors, branchName, unexpectedSelectors},
  27. async ({expectedSelectors: expected, branchName: branch, unexpectedSelectors: unexpected}) => {
  28. for (let selector of expected) {
  29. await ContentTaskUtils.waitForCondition(() => content.document.querySelector(selector),
  30. `Should render ${selector} in the ${branch} branch`);
  31. }
  32. for (let selector of unexpected) {
  33. ok(!content.document.querySelector(selector),
  34. `Should not render ${selector} in the ${branch} branch`);
  35. }
  36. }
  37. );
  38. BrowserTestUtils.removeTab(tab);
  39. }
  40. /**
  41. * Test the the various trailhead branches.
  42. */
  43. add_task(async function test_trailhead_branches() {
  44. await test_trailhead_branch(
  45. "join-privacy",
  46. // Expected selectors:
  47. [".trailhead.joinCohort",
  48. "button[data-l10n-id=onboarding-browse-privately-button]",
  49. "button[data-l10n-id=onboarding-tracking-protection-button2]",
  50. "button[data-l10n-id=onboarding-lockwise-passwords-button2]"]);
  51. await test_trailhead_branch(
  52. "sync-supercharge",
  53. // Expected selectors:
  54. [".trailhead.syncCohort",
  55. "button[data-l10n-id=onboarding-mobile-phone-button]",
  56. "button[data-l10n-id=onboarding-data-sync-button2]",
  57. "button[data-l10n-id=onboarding-firefox-monitor-button]"]);
  58. await test_trailhead_branch(
  59. "cards-multidevice",
  60. // Expected selectors:
  61. ["button[data-l10n-id=onboarding-mobile-phone-button]",
  62. "button[data-l10n-id=onboarding-pocket-anywhere-button]",
  63. "button[data-l10n-id=onboarding-send-tabs-button]"],
  64. // Unexpected selectors:
  65. ["#trailheadDialog"]);
  66. await test_trailhead_branch(
  67. "join-payoff",
  68. // Expected selectors:
  69. [".trailhead.joinCohort",
  70. "button[data-l10n-id=onboarding-firefox-monitor-button]",
  71. "button[data-l10n-id=onboarding-facebook-container-button]",
  72. "button[data-l10n-id=onboarding-firefox-send-button]"]);
  73. await test_trailhead_branch(
  74. "nofirstrun",
  75. [],
  76. // Unexpected selectors:
  77. ["#trailheadDialog",
  78. ".trailheadCards"]);
  79. await test_trailhead_branch(
  80. "control",
  81. // Expected selectors:
  82. [".firstrun-scene"],
  83. // Unexpected selectors:
  84. ["#trailheadDialog",
  85. ".trailheadCards"]);
  86. });