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
|
/**
* Test that the doorhanger notification for password saving is populated with
* the correct values in various password capture cases.
*/
Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/toolkit/components/passwordmgr/test/browser/head.js",
this
);
add_task(async function test_policy_masterpassword_doorhanger() {
await setupPolicyEngineWithJson({
policies: {
PrimaryPassword: true,
},
});
let username = "username";
let password = "password";
await BrowserTestUtils.withNewTab(
{
gBrowser,
url:
"https://example.com/browser/toolkit/components/" +
"passwordmgr/test/browser/form_basic.html",
},
async function (browser) {
await SimpleTest.promiseFocus(browser.ownerGlobal);
// Update the form with credentials from the test case.
info(`update form with username: ${username}, password: ${password}`);
await changeContentFormValues(browser, {
"#form-basic-username": username,
"#form-basic-password": password,
});
// Submit the form with the new credentials. This will cause the doorhanger
// notification to be displayed.
let formSubmittedPromise = listenForTestNotification("ShowDoorhanger");
await SpecialPowers.spawn(browser, [], async function () {
let doc = this.content.document;
doc.getElementById("form-basic").submit();
});
await formSubmittedPromise;
let expectedDoorhanger = "password-save";
info("Waiting for doorhanger of type: " + expectedDoorhanger);
let notif = await waitForDoorhanger(browser, expectedDoorhanger);
// Fake the subdialog
let dialogURL = "";
let originalOpenDialog = window.openDialog;
window.openDialog = function (aDialogURL, unused, unused2, aCallback) {
dialogURL = aDialogURL;
if (aCallback) {
aCallback();
}
};
await clickDoorhangerButton(notif, REMEMBER_BUTTON);
await TestUtils.waitForCondition(
() => dialogURL,
"wait for open to get called asynchronously"
);
is(
dialogURL,
"chrome://mozapps/content/preferences/changemp.xhtml",
"clicking on the checkbox should open the masterpassword dialog"
);
window.openDialog = originalOpenDialog;
}
);
});
|