diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /browser/components/newtab/test/unit/lib/ActivityStreamPrefs.test.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/newtab/test/unit/lib/ActivityStreamPrefs.test.js')
-rw-r--r-- | browser/components/newtab/test/unit/lib/ActivityStreamPrefs.test.js | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/browser/components/newtab/test/unit/lib/ActivityStreamPrefs.test.js b/browser/components/newtab/test/unit/lib/ActivityStreamPrefs.test.js new file mode 100644 index 0000000000..ebc9726def --- /dev/null +++ b/browser/components/newtab/test/unit/lib/ActivityStreamPrefs.test.js @@ -0,0 +1,113 @@ +import { DefaultPrefs, Prefs } from "lib/ActivityStreamPrefs.jsm"; + +const TEST_PREF_CONFIG = new Map([ + ["foo", { value: true }], + ["bar", { value: "BAR" }], + ["baz", { value: 1 }], + ["qux", { value: "foo", value_local_dev: "foofoo" }], +]); + +describe("ActivityStreamPrefs", () => { + describe("Prefs", () => { + let p; + beforeEach(() => { + p = new Prefs(); + }); + it("should have get, set, and observe methods", () => { + assert.property(p, "get"); + assert.property(p, "set"); + assert.property(p, "observe"); + }); + describe("#observeBranch", () => { + let listener; + beforeEach(() => { + p._prefBranch = { addObserver: sinon.stub() }; + listener = { onPrefChanged: sinon.stub() }; + p.observeBranch(listener); + }); + it("should add an observer", () => { + assert.calledOnce(p._prefBranch.addObserver); + assert.calledWith(p._prefBranch.addObserver, ""); + }); + it("should store the listener", () => { + assert.equal(p._branchObservers.size, 1); + assert.ok(p._branchObservers.has(listener)); + }); + it("should call listener's onPrefChanged", () => { + p._branchObservers.get(listener)(); + + assert.calledOnce(listener.onPrefChanged); + }); + }); + describe("#ignoreBranch", () => { + let listener; + beforeEach(() => { + p._prefBranch = { + addObserver: sinon.stub(), + removeObserver: sinon.stub(), + }; + listener = {}; + p.observeBranch(listener); + }); + it("should remove the observer", () => { + p.ignoreBranch(listener); + + assert.calledOnce(p._prefBranch.removeObserver); + assert.calledWith( + p._prefBranch.removeObserver, + p._prefBranch.addObserver.firstCall.args[0] + ); + }); + it("should remove the listener", () => { + assert.equal(p._branchObservers.size, 1); + + p.ignoreBranch(listener); + + assert.equal(p._branchObservers.size, 0); + }); + }); + }); + + describe("DefaultPrefs", () => { + describe("#init", () => { + let defaultPrefs; + let sandbox; + beforeEach(() => { + sandbox = sinon.createSandbox(); + defaultPrefs = new DefaultPrefs(TEST_PREF_CONFIG); + sinon.stub(defaultPrefs, "set"); + }); + afterEach(() => { + sandbox.restore(); + }); + it("should initialize a boolean pref", () => { + defaultPrefs.init(); + assert.calledWith(defaultPrefs.set, "foo", true); + }); + it("should not initialize a pref if a default exists", () => { + defaultPrefs.prefs.set("foo", false); + + defaultPrefs.init(); + + assert.neverCalledWith(defaultPrefs.set, "foo", true); + }); + it("should initialize a string pref", () => { + defaultPrefs.init(); + assert.calledWith(defaultPrefs.set, "bar", "BAR"); + }); + it("should initialize a integer pref", () => { + defaultPrefs.init(); + assert.calledWith(defaultPrefs.set, "baz", 1); + }); + it("should initialize a pref with value if Firefox is not a local build", () => { + defaultPrefs.init(); + assert.calledWith(defaultPrefs.set, "qux", "foo"); + }); + it("should initialize a pref with value_local_dev if Firefox is a local build", () => { + sandbox.stub(global.AppConstants, "MOZILLA_OFFICIAL").value(false); + defaultPrefs.init(); + assert.calledWith(defaultPrefs.set, "qux", "foofoo"); + }); + }); + }); +}); |