summaryrefslogtreecommitdiffstats
path: root/browser/components/payments/test/browser/browser_openPreferences.js
blob: 5d8c71f58bf3690cb8c3d2cb19ec53b5cb20a66a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"use strict";

const methodData = [PTU.MethodData.basicCard];
const details = Object.assign(
  {},
  PTU.Details.twoShippingOptions,
  PTU.Details.total2USD
);

add_task(async function setup_once() {
  // add an address and card to avoid the FTU sequence
  await addSampleAddressesAndBasicCard(
    [PTU.Addresses.TimBL],
    [PTU.BasicCards.JohnDoe]
  );
});

add_task(async function test_openPreferences() {
  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: BLANK_PAGE_URL,
    },
    async browser => {
      let { win, frame } = await setupPaymentDialog(browser, {
        methodData,
        details,
        merchantTaskFn: PTU.ContentTasks.createAndShowRequest,
      });

      let prefsTabPromise = BrowserTestUtils.waitForNewTab(
        gBrowser,
        "about:preferences#privacy-form-autofill"
      );

      let prefsLoadedPromise = TestUtils.topicObserved("sync-pane-loaded");

      await spawnPaymentDialogTask(
        frame,
        function verifyPrefsLink({ isMac }) {
          let manageTextEl = content.document.querySelector(".manage-text");

          let expectedVisibleEl;
          if (isMac) {
            expectedVisibleEl = manageTextEl.querySelector(
              ":scope > span[data-os='mac']"
            );
            ok(
              manageTextEl.innerText.includes("Preferences"),
              "Visible string includes 'Preferences'"
            );
            ok(
              !manageTextEl.innerText.includes("Options"),
              "Visible string includes 'Options'"
            );
          } else {
            expectedVisibleEl = manageTextEl.querySelector(
              ":scope > span:not([data-os='mac'])"
            );
            ok(
              !manageTextEl.innerText.includes("Preferences"),
              "Visible string includes 'Preferences'"
            );
            ok(
              manageTextEl.innerText.includes("Options"),
              "Visible string includes 'Options'"
            );
          }

          let prefsLink = expectedVisibleEl.querySelector("a");
          ok(prefsLink, "Preferences link should exist");
          prefsLink.scrollIntoView();
          EventUtils.synthesizeMouseAtCenter(prefsLink, {}, content);
        },
        {
          isMac: AppConstants.platform == "macosx",
        }
      );

      let prefsTab = await prefsTabPromise;
      ok(prefsTab, "Ensure a tab was opened");
      await prefsLoadedPromise;

      await BrowserTestUtils.removeTab(prefsTab);

      spawnPaymentDialogTask(frame, PTU.DialogContentTasks.manuallyClickCancel);
      await BrowserTestUtils.waitForCondition(
        () => win.closed,
        "dialog should be closed"
      );
    }
  );
});