summaryrefslogtreecommitdiffstats
path: root/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/Preferences.jsm
blob: aa2b3f2a7cae0009d04a9ce1111e012a6f1c0ce6 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

this.EXPORTED_SYMBOLS = ["Preferences"];

const {classes: Cc, interfaces: Ci, utils: Cu} = Components;

Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://testing-common/TestUtils.jsm");
Cu.import("resource://testing-common/ContentTask.jsm");

this.Preferences = {

  init(libDir) {
    let panes = [
      ["paneGeneral", null],
      ["paneSearch", null],
      ["paneContent", null],
      ["paneApplications", null],
      ["panePrivacy", null],
      ["panePrivacy", null, DNTDialog],
      ["panePrivacy", null, clearRecentHistoryDialog],
      ["paneSecurity", null],
      ["paneSync", null],
      ["paneAdvanced", "generalTab"],
      ["paneAdvanced", "dataChoicesTab"],
      ["paneAdvanced", "networkTab"],
      ["paneAdvanced", "networkTab", connectionDialog],
      ["paneAdvanced", "updateTab"],
      ["paneAdvanced", "encryptionTab"],
      ["paneAdvanced", "encryptionTab", certManager],
      ["paneAdvanced", "encryptionTab", deviceManager],
    ];
    for (let [primary, advanced, customFn] of panes) {
      let configName = primary.replace(/^pane/, "prefs") + (advanced ? "-" + advanced : "");
      if (customFn) {
        configName += "-" + customFn.name;
      }
      this.configurations[configName] = {};
      this.configurations[configName].applyConfig = prefHelper.bind(null, primary, advanced, customFn);
    }
  },

  configurations: {},
};

let prefHelper = Task.async(function*(primary, advanced = null, customFn = null) {
  let browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
  let selectedBrowser = browserWindow.gBrowser.selectedBrowser;

  // close any dialog that might still be open
  yield ContentTask.spawn(selectedBrowser, null, function*() {
    if (!content.window.gSubDialog) {
      return;
    }
    content.window.gSubDialog.close();
  });

  let readyPromise = null;
  if (selectedBrowser.currentURI.specIgnoringRef == "about:preferences") {
    if (selectedBrowser.currentURI.spec == "about:preferences#" + primary.replace(/^pane/, "")) {
      // We're already on the correct pane.
      readyPromise = Promise.resolve();
    } else {
      readyPromise = paintPromise(browserWindow);
    }
  } else {
    readyPromise = TestUtils.topicObserved("advanced-pane-loaded");
  }

  if (primary == "paneAdvanced") {
    browserWindow.openAdvancedPreferences(advanced);
  } else {
    browserWindow.openPreferences(primary);
  }

  yield readyPromise;

  if (customFn) {
    let customPaintPromise = paintPromise(browserWindow);
    yield* customFn(selectedBrowser);
    yield customPaintPromise;
  }
});

function paintPromise(browserWindow) {
  return new Promise((resolve) => {
    browserWindow.addEventListener("MozAfterPaint", function onPaint() {
      browserWindow.removeEventListener("MozAfterPaint", onPaint);
      resolve();
    });
  });
}

function* DNTDialog(aBrowser) {
  yield ContentTask.spawn(aBrowser, null, function* () {
    content.document.getElementById("doNotTrackSettings").click();
  });
}

function* connectionDialog(aBrowser) {
  yield ContentTask.spawn(aBrowser, null, function* () {
    content.document.getElementById("connectionSettings").click();
  });
}

function* clearRecentHistoryDialog(aBrowser) {
  yield ContentTask.spawn(aBrowser, null, function* () {
    content.document.getElementById("historyRememberClear").click();
  });
}

function* certManager(aBrowser) {
  yield ContentTask.spawn(aBrowser, null, function* () {
    content.document.getElementById("viewCertificatesButton").click();
  });
}

function* deviceManager(aBrowser) {
  yield ContentTask.spawn(aBrowser, null, function* () {
    content.document.getElementById("viewSecurityDevicesButton").click();
  });
}