summaryrefslogtreecommitdiffstats
path: root/browser/components/enterprisepolicies/tests/browser/browser_policy_masterpassword_aboutlogins.js
blob: 91cc9ebc2ebd955bec8f1fdd3a20b77514791fd4 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

let { LoginTestUtils } = ChromeUtils.importESModule(
  "resource://testing-common/LoginTestUtils.sys.mjs"
);

// Test that create in about:logins asks for primary password
add_task(async function test_policy_admin() {
  await setupPolicyEngineWithJson({
    policies: {
      PrimaryPassword: true,
    },
  });

  let aboutLoginsTab = await BrowserTestUtils.openNewForegroundTab({
    gBrowser,
    url: "about:logins",
  });

  let browser = gBrowser.selectedBrowser;

  // Fake the subdialog
  let dialogURL = "";
  let originalOpenDialog = window.openDialog;
  window.openDialog = function (aDialogURL, unused, unused2, aCallback) {
    dialogURL = aDialogURL;
    if (aCallback) {
      aCallback();
    }
  };

  await SpecialPowers.spawn(browser, [], async () => {
    let loginList = Cu.waiveXrays(content.document.querySelector("login-list"));
    let createButton = loginList._createLoginButton;
    ok(
      !createButton.disabled,
      "Create button should not be disabled initially"
    );
    let loginItem = Cu.waiveXrays(content.document.querySelector("login-item"));

    createButton.click();

    let usernameInput = loginItem.shadowRoot.querySelector(
      "input[name='username']"
    );
    let originInput = loginItem.shadowRoot.querySelector(
      "input[name='origin']"
    );
    let passwordInput = loginItem.shadowRoot.querySelector(
      "input[name='password']"
    );

    originInput.value = "https://www.example.org";
    usernameInput.value = "testuser1";
    passwordInput.value = "testpass1";

    let saveChangesButton = loginItem.shadowRoot.querySelector(
      ".save-changes-button"
    );
    saveChangesButton.click();
  });
  await TestUtils.waitForCondition(
    () => dialogURL,
    "wait for open to get called asynchronously"
  );
  is(
    dialogURL,
    "chrome://mozapps/content/preferences/changemp.xhtml",
    "clicking on the save-changes-button should open the masterpassword dialog"
  );
  window.openDialog = originalOpenDialog;
  BrowserTestUtils.removeTab(aboutLoginsTab);
});