Loading
Bug 1825157 - Unify the fake pref implementations used in tests. r=nanj
Before this commit, the New Tab tests had two fake pref
implementations:
* The `Services.prefs` mock in `TEST_GLOBAL`, which stubbed out a
handful of `nsIPrefBranch` methods.
* `FakensIPrefBranch`, which mocked a different handful of
`nsIPrefBranch` methods.
This commit:
* Consolidates the two fake implementations into the mock
`FakensIPrefBranch` class.
* Adds a `FakensIPrefService` subclass of `FakensIPrefBranch`, with
additional methods specific to `nsIPrefService`.
* Replaces `FakensIPrefBranch.prototype.prefs` with a new
`FAKE_GLOBAL_PREFS` map. The new approach still lets tests change and
clear prefs on existing instances of `FakensIPrefBranch` and its
subclasses, but makes the shared state explicit. The old approach of
mutating `FakensIPrefBranch.prototype.prefs` relied on a subtle quirk
of `prefs` being shared by all instances of `FakensIPrefBranch` and
its subclasses, and broke when setting `prefs` to a new, empty
object.
* Moves `{observe, ignore}Branch` into `FakePrefs`, since these are
not part of the `nsIPrefBranch` interface.
Differential Revision: https://phabricator.services.mozilla.com/D173897