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
|
"use strict";
const CC_VALUES = {
"cc-name": "User",
"cc-number": "5577000055770004",
"cc-exp-month": 12,
"cc-exp-year": 2017,
};
add_setup(async function () {
await SpecialPowers.pushPrefEnv({
set: [
["extensions.formautofill.creditCards.supported", "on"],
["extensions.formautofill.creditCards.enabled", true],
["extensions.formautofill.heuristics.captureOnFormRemoval", true],
],
});
await removeAllRecords();
});
/**
* Tests if the credit card is captured (cc doorhanger is shown) after a
* successful xhr or fetch request followed by a form removal and
* that the stored credit card record has the right values.
*/
add_task(async function test_credit_card_captured_after_form_removal() {
const onStorageChanged = waitForStorageChangedEvents("add");
await BrowserTestUtils.withNewTab(
{ gBrowser, url: CREDITCARD_FORM_URL },
async function (browser) {
const onPopupShown = waitForPopupShown();
info("Update identified credit card fields");
// We don't submit the form
await focusUpdateSubmitForm(
browser,
{
focusSelector: "#cc-name",
newValues: {
"#cc-name": CC_VALUES["cc-name"],
"#cc-number": CC_VALUES["cc-number"],
"#cc-exp-month": CC_VALUES["cc-exp-month"],
"#cc-exp-year": CC_VALUES["cc-exp-year"],
},
},
false
);
info("Infer a successfull fetch request");
await SpecialPowers.spawn(browser, [], async () => {
await content.fetch(
"https://example.org/browser/browser/extensions/formautofill/test/browser/empty.html"
);
});
info("Infer form removal");
await SpecialPowers.spawn(browser, [], async function () {
let form = content.document.getElementById("form");
form.parentNode.remove(form);
});
info("Wait for credit card doorhanger");
await onPopupShown;
info("Click Save in credit card doorhanger");
await clickDoorhangerButton(MAIN_BUTTON);
}
);
info("Wait for the credit card to be added to the storage.");
await onStorageChanged;
const storedCreditCards = await getCreditCards();
let actualCreditCard = storedCreditCards[0];
actualCreditCard["cc-number"] = await OSKeyStore.decrypt(
actualCreditCard["cc-number-encrypted"]
);
for (let key in CC_VALUES) {
let expected = CC_VALUES[key];
let actual = actualCreditCard[key];
is(expected, actual, `${key} should be equal`);
}
await removeAllRecords();
});
/**
* Tests that the credit card is not captured without a prior fetch or xhr request event
*/
add_task(async function test_credit_card_not_captured_without_prior_fetch() {
await BrowserTestUtils.withNewTab(
{ gBrowser, url: CREDITCARD_FORM_URL },
async function (browser) {
info("Update identified credit card fields");
// We don't submit the form
await focusUpdateSubmitForm(
browser,
{
focusSelector: "#cc-name",
newValues: {
"#cc-name": CC_VALUES["cc-name"],
"#cc-number": CC_VALUES["cc-number"],
"#cc-exp-month": CC_VALUES["cc-exp-month"],
"#cc-exp-year": CC_VALUES["cc-exp-year"],
},
},
false
);
info("Infer form removal");
await SpecialPowers.spawn(browser, [], async function () {
let form = content.document.getElementById("form");
form.parentNode.remove(form);
});
info("Ensure that credit card doorhanger is not shown");
await ensureNoDoorhanger(browser);
}
);
});
|