1 const { OSKeyStoreTestUtils } = ChromeUtils.importESModule(
2 "resource://testing-common/OSKeyStoreTestUtils.sys.mjs"
4 const { OSKeyStore } = ChromeUtils.importESModule(
5 "resource://gre/modules/OSKeyStore.sys.mjs"
8 add_task(async function () {
9 let prefs = await openPreferencesViaOpenPreferencesAPI("panePrivacy", {
12 is(prefs.selectedPane, "panePrivacy", "Privacy pane was selected");
14 let doc = gBrowser.contentDocument;
15 // Fake the subdialog and LoginHelper
16 let win = doc.defaultView;
18 let dialogOpened = false;
19 ChromeUtils.defineLazyGetter(win, "gSubDialog", () => ({
20 open(aDialogURL, { closingCallback: aCallback }) {
22 dialogURL = aDialogURL;
23 primaryPasswordSet = primaryPasswordNextState;
28 let primaryPasswordSet = false;
30 isPrimaryPasswordSet() {
31 return primaryPasswordSet;
34 return true; // Since enabled by default.
38 let checkbox = doc.querySelector("#useMasterPassword");
39 checkbox.scrollIntoView();
42 "primary password checkbox should be unchecked by default"
44 let button = doc.getElementById("changeMasterPassword");
45 ok(button.disabled, "primary password button should be disabled by default");
47 let primaryPasswordNextState = false;
48 if (OSKeyStoreTestUtils.canTestOSKeyStoreLogin() && OSKeyStore.canReauth()) {
49 let osAuthDialogShown = OSKeyStoreTestUtils.waitForOSKeyStoreLogin(false);
51 info("waiting for os auth dialog to appear and get canceled");
52 await osAuthDialogShown;
53 await TestUtils.waitForCondition(
54 () => !checkbox.checked,
55 "wait for checkbox to get unchecked"
57 ok(!dialogOpened, "the dialog should not have opened");
60 "the changemp dialog should not have been opened when the os auth dialog is canceled"
64 "primary password checkbox should be unchecked after canceling os auth dialog"
66 ok(button.disabled, "button should be disabled after canceling os auth");
69 primaryPasswordNextState = true;
70 if (OSKeyStoreTestUtils.canTestOSKeyStoreLogin() && OSKeyStore.canReauth()) {
71 let osAuthDialogShown = OSKeyStoreTestUtils.waitForOSKeyStoreLogin(true);
73 info("waiting for os auth dialog to appear");
74 await osAuthDialogShown;
75 info("waiting for dialogURL to get set");
76 await TestUtils.waitForCondition(
78 "wait for open to get called asynchronously"
82 "chrome://mozapps/content/preferences/changemp.xhtml",
83 "clicking on the checkbox should open the primary password dialog"
86 primaryPasswordSet = true;
87 doc.defaultView.gPrivacyPane._initMasterPasswordUI();
88 await TestUtils.waitForCondition(
89 () => !button.disabled,
90 "waiting for primary password button to get enabled"
93 ok(!button.disabled, "primary password button should now be enabled");
94 ok(checkbox.checked, "primary password checkbox should be checked now");
98 await TestUtils.waitForCondition(
100 "wait for open to get called asynchronously"
104 "chrome://mozapps/content/preferences/changemp.xhtml",
105 "clicking on the button should open the primary password dialog"
107 ok(!button.disabled, "primary password button should still be enabled");
108 ok(checkbox.checked, "primary password checkbox should be checked still");
110 // Confirm that we won't automatically respond to the dialog,
111 // since we don't expect a dialog here, we want the test to fail if one appears.
113 Services.prefs.getStringPref(
114 "toolkit.osKeyStore.unofficialBuildOnlyLogin",
118 "Pref should be set to an empty string"
121 primaryPasswordNextState = false;
126 "chrome://mozapps/content/preferences/removemp.xhtml",
127 "clicking on the checkbox to uncheck primary password should show the removal dialog"
129 ok(button.disabled, "primary password button should now be disabled");
130 ok(!checkbox.checked, "primary password checkbox should now be unchecked");
132 BrowserTestUtils.removeTab(gBrowser.selectedTab);