diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /browser/components/selfsupport | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'browser/components/selfsupport')
6 files changed, 192 insertions, 0 deletions
diff --git a/browser/components/selfsupport/SelfSupportService.js b/browser/components/selfsupport/SelfSupportService.js new file mode 100644 index 000000000..26148c6ff --- /dev/null +++ b/browser/components/selfsupport/SelfSupportService.js @@ -0,0 +1,78 @@ +/* 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"; + +const {classes: Cc, interfaces: Ci, utils: Cu} = Components; + +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); +Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/Preferences.jsm"); + +const PREF_FHR_UPLOAD_ENABLED = "datareporting.healthreport.uploadEnabled"; + +XPCOMUtils.defineLazyModuleGetter(this, "TelemetryArchive", + "resource://gre/modules/TelemetryArchive.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "TelemetryEnvironment", + "resource://gre/modules/TelemetryEnvironment.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "TelemetryController", + "resource://gre/modules/TelemetryController.jsm"); + +function MozSelfSupportInterface() { +} + +MozSelfSupportInterface.prototype = { + classDescription: "MozSelfSupport", + classID: Components.ID("{d30aae8b-f352-4de3-b936-bb9d875df0bb}"), + contractID: "@mozilla.org/mozselfsupport;1", + QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer]), + + _window: null, + + init: function (window) { + this._window = window; + }, + + get healthReportDataSubmissionEnabled() { + return Preferences.get(PREF_FHR_UPLOAD_ENABLED, false); + }, + + set healthReportDataSubmissionEnabled(enabled) { + Preferences.set(PREF_FHR_UPLOAD_ENABLED, enabled); + }, + + resetPref: function(name) { + Services.prefs.clearUserPref(name); + }, + + resetSearchEngines: function() { + Services.search.restoreDefaultEngines(); + Services.search.resetToOriginalDefaultEngine(); + }, + + getTelemetryPingList: function() { + return this._wrapPromise(TelemetryArchive.promiseArchivedPingList()); + }, + + getTelemetryPing: function(pingId) { + return this._wrapPromise(TelemetryArchive.promiseArchivedPingById(pingId)); + }, + + getCurrentTelemetryEnvironment: function() { + const current = TelemetryEnvironment.currentEnvironment; + return new this._window.Promise(resolve => resolve(current)); + }, + + getCurrentTelemetrySubsessionPing: function() { + const current = TelemetryController.getCurrentPingData(true); + return new this._window.Promise(resolve => resolve(current)); + }, + + _wrapPromise: function(promise) { + return new this._window.Promise( + (resolve, reject) => promise.then(resolve, reject)); + }, +} + +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([MozSelfSupportInterface]); diff --git a/browser/components/selfsupport/SelfSupportService.manifest b/browser/components/selfsupport/SelfSupportService.manifest new file mode 100644 index 000000000..0e87857e7 --- /dev/null +++ b/browser/components/selfsupport/SelfSupportService.manifest @@ -0,0 +1,2 @@ +component {d30aae8b-f352-4de3-b936-bb9d875df0bb} SelfSupportService.js +contract @mozilla.org/mozselfsupport;1 {d30aae8b-f352-4de3-b936-bb9d875df0bb} diff --git a/browser/components/selfsupport/moz.build b/browser/components/selfsupport/moz.build new file mode 100644 index 000000000..daa59ac97 --- /dev/null +++ b/browser/components/selfsupport/moz.build @@ -0,0 +1,14 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +EXTRA_COMPONENTS += [ + 'SelfSupportService.js', + 'SelfSupportService.manifest', +] + +BROWSER_CHROME_MANIFESTS += [ + 'test/browser.ini', +] diff --git a/browser/components/selfsupport/test/.eslintrc.js b/browser/components/selfsupport/test/.eslintrc.js new file mode 100644 index 000000000..c764b133d --- /dev/null +++ b/browser/components/selfsupport/test/.eslintrc.js @@ -0,0 +1,7 @@ +"use strict"; + +module.exports = { + "extends": [ + "../../../../testing/mochitest/browser.eslintrc.js" + ] +}; diff --git a/browser/components/selfsupport/test/browser.ini b/browser/components/selfsupport/test/browser.ini new file mode 100644 index 000000000..ba56857b3 --- /dev/null +++ b/browser/components/selfsupport/test/browser.ini @@ -0,0 +1,3 @@ +[DEFAULT] + +[browser_selfsupportAPI.js] diff --git a/browser/components/selfsupport/test/browser_selfsupportAPI.js b/browser/components/selfsupport/test/browser_selfsupportAPI.js new file mode 100644 index 000000000..2a54d4ae6 --- /dev/null +++ b/browser/components/selfsupport/test/browser_selfsupportAPI.js @@ -0,0 +1,88 @@ +Cu.import("resource://gre/modules/Preferences.jsm"); + +function test_resetPref() { + const prefNewName = "browser.newpref.fake"; + Assert.ok(!Preferences.has(prefNewName), "pref should not exist"); + + const prefExistingName = "extensions.hotfix.id"; + Assert.ok(Preferences.has(prefExistingName), "pref should exist"); + Assert.ok(!Preferences.isSet(prefExistingName), "pref should not be user-set"); + let prefExistingOriginalValue = Preferences.get(prefExistingName); + + registerCleanupFunction(function() { + Preferences.set(prefExistingName, prefExistingOriginalValue); + Services.prefs.deleteBranch(prefNewName); + }); + + // 1. do nothing on an inexistent pref + MozSelfSupport.resetPref(prefNewName); + Assert.ok(!Preferences.has(prefNewName), "pref should still not exist"); + + // 2. creation of a new pref + Preferences.set(prefNewName, 10); + Assert.ok(Preferences.has(prefNewName), "pref should exist"); + Assert.equal(Preferences.get(prefNewName), 10, "pref value should be 10"); + + MozSelfSupport.resetPref(prefNewName); + Assert.ok(!Preferences.has(prefNewName), "pref should not exist any more"); + + // 3. do nothing on an unchanged existing pref + MozSelfSupport.resetPref(prefExistingName); + Assert.ok(Preferences.has(prefExistingName), "pref should still exist"); + Assert.equal(Preferences.get(prefExistingName), prefExistingOriginalValue, "pref value should be the same as original"); + + // 4. change the value of an existing pref + Preferences.set(prefExistingName, "anyone@mozilla.org"); + Assert.ok(Preferences.has(prefExistingName), "pref should exist"); + Assert.equal(Preferences.get(prefExistingName), "anyone@mozilla.org", "pref value should have changed"); + + MozSelfSupport.resetPref(prefExistingName); + Assert.ok(Preferences.has(prefExistingName), "pref should still exist"); + Assert.equal(Preferences.get(prefExistingName), prefExistingOriginalValue, "pref value should be the same as original"); + + // 5. delete an existing pref + // deleteBranch is implemented in such a way that + // clearUserPref can't undo its action + // see discussion in bug 1075160 +} + +function test_resetSearchEngines() +{ + const defaultEngineOriginal = Services.search.defaultEngine; + const visibleEnginesOriginal = Services.search.getVisibleEngines(); + + // 1. do nothing on unchanged search configuration + MozSelfSupport.resetSearchEngines(); + Assert.equal(Services.search.defaultEngine, defaultEngineOriginal, "default engine should be reset"); + Assert.deepEqual(Services.search.getVisibleEngines(), visibleEnginesOriginal, + "default visible engines set should be reset"); + + // 2. change the default search engine + const defaultEngineNew = visibleEnginesOriginal[3]; + Assert.notEqual(defaultEngineOriginal, defaultEngineNew, "new default engine should be different from original"); + Services.search.defaultEngine = defaultEngineNew; + Assert.equal(Services.search.defaultEngine, defaultEngineNew, "default engine should be set to new"); + MozSelfSupport.resetSearchEngines(); + Assert.equal(Services.search.defaultEngine, defaultEngineOriginal, "default engine should be reset"); + Assert.deepEqual(Services.search.getVisibleEngines(), visibleEnginesOriginal, + "default visible engines set should be reset"); + + // 3. remove an engine + const engineRemoved = visibleEnginesOriginal[2]; + Services.search.removeEngine(engineRemoved); + Assert.ok(Services.search.getVisibleEngines().indexOf(engineRemoved) == -1, + "removed engine should not be visible any more"); + MozSelfSupport.resetSearchEngines(); + Assert.equal(Services.search.defaultEngine, defaultEngineOriginal, "default engine should be reset"); + Assert.deepEqual(Services.search.getVisibleEngines(), visibleEnginesOriginal, + "default visible engines set should be reset"); + + // 4. add an angine + // we don't remove user-added engines as they are only used if selected +} + +function test() +{ + test_resetPref(); + test_resetSearchEngines(); +} |