summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/browser/browser_exceptions_dialog.js
blob: 09fbe0eea7e1d0bca6e0c2e5018ca79713ecb275 (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

"use strict";

const LOGIN_HOST = "http://example.com";

function openExceptionsDialog() {
  return window.openDialog(
    "chrome://browser/content/preferences/permissions.xul",
    "Toolkit:PasswordManagerExceptions", "",
    {
      blockVisible: true,
      sessionVisible: false,
      allowVisible: false,
      hideStatusColumn: true,
      prefilledHost: "",
      permissionType: "login-saving"
    }
  );
}

function countDisabledHosts(dialog) {
  let doc = dialog.document;
  let rejectsTree = doc.getElementById("permissionsTree");

  return rejectsTree.view.rowCount;
}

function promiseStorageChanged(expectedData) {
  function observer(subject, data) {
    return data == expectedData && subject.QueryInterface(Ci.nsISupportsString).data == LOGIN_HOST;
  }

  return TestUtils.topicObserved("passwordmgr-storage-changed", observer);
}

add_task(function* test_disable() {
  let dialog = openExceptionsDialog();
  let promiseChanged = promiseStorageChanged("hostSavingDisabled");

  yield BrowserTestUtils.waitForEvent(dialog, "load");
  Services.logins.setLoginSavingEnabled(LOGIN_HOST, false);
  yield promiseChanged;
  is(countDisabledHosts(dialog), 1, "Verify disabled host added");
  yield BrowserTestUtils.closeWindow(dialog);
});

add_task(function* test_enable() {
  let dialog = openExceptionsDialog();
  let promiseChanged = promiseStorageChanged("hostSavingEnabled");

  yield BrowserTestUtils.waitForEvent(dialog, "load");
  Services.logins.setLoginSavingEnabled(LOGIN_HOST, true);
  yield promiseChanged;
  is(countDisabledHosts(dialog), 0, "Verify disabled host removed");
  yield BrowserTestUtils.closeWindow(dialog);
});