pdf.js.mirror/test/unit/app_options_spec.js
Jonas Jenwald 675e9219b5 Remove the objectSize helper function
Given that Maps are used a lot more these days, this helper function is now used very sparingly and inlining the necessary code seems reasonable.

*Note:* Once [this proposal](https://github.com/tc39/proposal-object-keys-length) makes it into Firefox, we should be able to simplify all `Object.keys(...).length` call-sites.
2026-07-24 12:49:44 +02:00

67 lines
2.3 KiB
JavaScript

/* Copyright 2024 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { AppOptions, OptionKind } from "../../web/app_options.js";
import { BasePreferences } from "../../web/preferences.js";
describe("AppOptions", function () {
it("checks that getAll returns data, for every OptionKind", function () {
expect(Object.keys(OptionKind)).toEqual([
"BROWSER",
"VIEWER",
"API",
"WORKER",
"EVENT_DISPATCH",
"PREFERENCE",
]);
for (const kind of Object.values(OptionKind)) {
expect(typeof kind).toEqual("number");
const options = AppOptions.getAll(kind);
expect(Object.keys(options).length).toBeGreaterThan(0);
}
});
it('checks that the number of "PREFERENCE" options does *not* exceed the maximum in mozilla-central', function () {
// If the following constant is updated then you *MUST* make the same change
// in mozilla-central as well to ensure that preference-fetching works; see
// https://searchfox.org/mozilla-central/source/toolkit/components/pdfjs/content/PdfStreamConverter.sys.mjs
const MAX_NUMBER_OF_PREFS = 50;
const options = AppOptions.getAll(OptionKind.PREFERENCE);
expect(Object.keys(options).length).toBeLessThanOrEqual(
MAX_NUMBER_OF_PREFS
);
});
});
describe("BasePreferences", function () {
it("checks that preference defaults are correct", async function () {
const TestPreferences = class extends BasePreferences {
async _readFromStorage(prefObj) {
return { prefs: Object.create(null) };
}
};
const testPrefs = new TestPreferences();
await testPrefs.initializedPromise;
expect(testPrefs.defaults).toEqual(
AppOptions.getAll(OptionKind.PREFERENCE, /* defaultOnly = */ true)
);
});
});