summaryrefslogtreecommitdiffstats
path: root/browser/extensions/formautofill/test/browser/address/browser_edit_address_doorhanger_display_state.js
blob: 1d8933ad31d3a1199783a89468705a6fedead342 (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
"use strict";
requestLongerTimeout(2);

add_setup(async function () {
  await SpecialPowers.pushPrefEnv({
    set: [["extensions.formautofill.addresses.capture.enabled", true]],
  });
});

add_task(async function test_edit_doorhanger_display_state() {
  const DEFAULT = {
    "given-name": "Test User",
    organization: "Mozilla",
    "street-address": "123 Sesame Street",
    country: "US",
  };

  const TEST_CASES = [
    {
      filled: { "address-level1": "floridaa" }, // typo
      expected: { label: "" },
    },
    {
      filled: { "address-level1": "AB" }, // non-exist region code
      expected: { label: "" },
    },
    {
      filled: { "address-level1": "CA" },
      expected: { label: "CA" },
    },
    {
      filled: { "address-level1": "fl" },
      expected: { label: "FL" },
    },
    {
      filled: { "address-level1": "New York" },
      expected: { label: "NY" },
    },
    {
      filled: { "address-level1": "Washington" },
      expected: { label: "WA" },
    },
  ];

  for (const TEST of TEST_CASES) {
    await BrowserTestUtils.withNewTab(
      { gBrowser, url: ADDRESS_FORM_URL },
      async function (browser) {
        const onSavePopupShown = waitForPopupShown();
        await focusUpdateSubmitForm(browser, {
          focusSelector: "#given-name",
          newValues: {
            "#given-name": DEFAULT["given-name"],
            "#organization": DEFAULT.organization,
            "#street-address": DEFAULT["street-address"],
            "#address-level1": TEST.filled["address-level1"],
          },
        });
        await onSavePopupShown;

        const onEditPopupShown = waitForPopupShown();
        await clickAddressDoorhangerButton(EDIT_ADDRESS_BUTTON);
        await onEditPopupShown;

        const notification = getNotification();
        const id = AddressEditDoorhanger.getInputId("address-level1");
        const element = notification.querySelector(`#${id}`);

        is(
          element.label,
          TEST.expected.label,
          "Edit address doorhanger shows the expected address-level1 select option"
        );
      }
    );
  }
});