summaryrefslogtreecommitdiffstats
path: root/browser/components/preferences/tests/browser_site_login_exceptions.js
blob: 508232b2340a4cd910af9cfe6133bba60cff6445 (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
"use strict";
const PERMISSIONS_URL =
  "chrome://browser/content/preferences/dialogs/permissions.xhtml";

var exceptionsDialog;

add_task(async function openLoginExceptionsSubDialog() {
  // ensure rememberSignons is off for this test;
  ok(
    !Services.prefs.getBoolPref("signon.rememberSignons"),
    "Check initial value of signon.rememberSignons pref"
  );

  // Undo the save password change.
  registerCleanupFunction(async function () {
    await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
      let doc = content.document;
      let savePasswordCheckBox = doc.getElementById("savePasswords");
      if (savePasswordCheckBox.checked) {
        savePasswordCheckBox.click();
      }
    });

    gBrowser.removeCurrentTab();
  });

  await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });

  let dialogOpened = promiseLoadSubDialog(PERMISSIONS_URL);

  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
    let doc = content.document;
    let savePasswordCheckBox = doc.getElementById("savePasswords");
    Assert.ok(
      !savePasswordCheckBox.checked,
      "Save Password CheckBox should be unchecked by default"
    );
    savePasswordCheckBox.click();

    let loginExceptionsButton = doc.getElementById("passwordExceptions");
    loginExceptionsButton.click();
  });

  exceptionsDialog = await dialogOpened;
});

add_task(async function addALoginException() {
  let doc = exceptionsDialog.document;

  let richlistbox = doc.getElementById("permissionsBox");
  Assert.equal(richlistbox.itemCount, 0, "Row count should initially be 0");

  let inputBox = doc.getElementById("url");
  inputBox.focus();

  EventUtils.sendString("www.example.com", exceptionsDialog);

  let btnBlock = doc.getElementById("btnBlock");
  btnBlock.click();

  await TestUtils.waitForCondition(() => richlistbox.itemCount == 2);

  let expectedResult = ["http://www.example.com", "https://www.example.com"];
  for (let website of expectedResult) {
    let elements = richlistbox.getElementsByAttribute("origin", website);
    is(elements.length, 1, "It should find only one coincidence");
  }
});

add_task(async function deleteALoginException() {
  let doc = exceptionsDialog.document;

  let richlistbox = doc.getElementById("permissionsBox");
  let currentItems = 2;
  Assert.equal(
    richlistbox.itemCount,
    currentItems,
    `Row count should initially be ${currentItems}`
  );
  richlistbox.focus();

  while (richlistbox.itemCount) {
    richlistbox.selectedIndex = 0;

    if (AppConstants.platform == "macosx") {
      EventUtils.synthesizeKey("KEY_Backspace");
    } else {
      EventUtils.synthesizeKey("KEY_Delete");
    }

    currentItems -= 1;

    await TestUtils.waitForCondition(
      () => richlistbox.itemCount == currentItems
    );
    is_element_visible(
      content.gSubDialog._dialogs[0]._box,
      "Subdialog is visible after deleting an element"
    );
  }
});