summaryrefslogtreecommitdiffstats
path: root/browser/extensions/formautofill/test/browser/browser_remoteiframe.js
blob: 4dddd27a093455067b7b9a46596a6d3f0e1a151d (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"use strict";

const IFRAME_URL_PATH = BASE_URL + "autocomplete_iframe.html";

// Start by adding a few addresses to storage.
add_task(async function setup_storage() {
  await SpecialPowers.pushPrefEnv({
    set: [
      [AUTOFILL_ADDRESSES_AVAILABLE_PREF, "on"],
      [ENABLED_AUTOFILL_ADDRESSES_PREF, true],
      [ENABLED_AUTOFILL_ADDRESSES_CAPTURE_PREF, true],
    ],
  });
  await setStorage(TEST_ADDRESS_2, TEST_ADDRESS_4, TEST_ADDRESS_5);
});

// Verify that form fillin works in a remote iframe, and that changing
// a field updates storage.
add_task(async function test_iframe_autocomplete() {
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    IFRAME_URL_PATH,
    true
  );
  let browser = tab.linkedBrowser;
  let iframeBC = browser.browsingContext.children[1];
  await openPopupOnSubframe(browser, iframeBC, "#street-address");

  // Highlight the first item in the list. We want to verify
  // that the warning text is correct to ensure that the preview is
  // performed properly.

  await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, iframeBC);
  await expectWarningText(browser, "Autofills address");

  // Highlight and select the second item in the list
  await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, iframeBC);
  await expectWarningText(browser, "Also autofills organization, email");
  EventUtils.synthesizeKey("VK_RETURN", {});

  let onLoaded = BrowserTestUtils.browserLoaded(browser, true);
  await SpecialPowers.spawn(iframeBC, [], async function () {
    await ContentTaskUtils.waitForCondition(() => {
      return (
        content.document.getElementById("street-address").value ==
          "32 Vassar Street MIT Room 32-G524" &&
        content.document.getElementById("country").value == "US" &&
        content.document.getElementById("organization").value ==
          "World Wide Web Consortium"
      );
    });
  });

  let onPopupShown = waitForPopupShown();
  await focusUpdateSubmitForm(iframeBC, {
    focusSelector: "#organization",
    newValues: {
      "#tel": "+16172535702",
    },
  });
  await onPopupShown;
  await onLoaded;

  let onUpdated = waitForStorageChangedEvents("update");
  await clickDoorhangerButton(MAIN_BUTTON);
  await onUpdated;

  // Check that the tel number was updated properly.
  let addresses = await getAddresses();
  is(addresses.length, 3, "Still 3 address in storage");
  is(addresses[1].tel, "+16172535702", "Verify the tel field");

  // Fill in the details again and then clear the form from the dropdown.
  await openPopupOnSubframe(browser, iframeBC, "#street-address");
  await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, iframeBC);
  EventUtils.synthesizeKey("VK_RETURN", {});

  await waitForAutofill(iframeBC, "#tel", "+16172535702");

  // Open the dropdown and select the Clear Form item.
  await openPopupOnSubframe(browser, iframeBC, "#street-address");
  await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, iframeBC);
  EventUtils.synthesizeKey("VK_RETURN", {});

  await SpecialPowers.spawn(iframeBC, [], async function () {
    await ContentTaskUtils.waitForCondition(() => {
      return (
        content.document.getElementById("street-address").value == "" &&
        content.document.getElementById("country").value == "" &&
        content.document.getElementById("organization").value == ""
      );
    });
  });

  await BrowserTestUtils.removeTab(tab);
});

// Choose preferences from the autocomplete dropdown within an iframe.
add_task(async function test_iframe_autocomplete_preferences() {
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    IFRAME_URL_PATH,
    true
  );
  let browser = tab.linkedBrowser;
  let iframeBC = browser.browsingContext.children[1];
  await openPopupOnSubframe(browser, iframeBC, "#organization");

  await expectWarningText(browser, "Also autofills address, phone, email");

  const prefTabPromise = BrowserTestUtils.waitForNewTab(
    gBrowser,
    PRIVACY_PREF_URL
  );

  // Select the preferences item.
  EventUtils.synthesizeKey("VK_DOWN", {});
  EventUtils.synthesizeKey("VK_DOWN", {});
  EventUtils.synthesizeKey("VK_RETURN", {});

  info(`expecting tab: about:preferences#privacy opened`);
  const prefTab = await prefTabPromise;
  info(`expecting tab: about:preferences#privacy removed`);
  BrowserTestUtils.removeTab(prefTab);

  await BrowserTestUtils.removeTab(tab);
});