diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /xpcom/tests/unit | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xpcom/tests/unit')
-rw-r--r-- | xpcom/tests/unit/test_windows_registry.js | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/xpcom/tests/unit/test_windows_registry.js b/xpcom/tests/unit/test_windows_registry.js index ef5082a666..3abc9f1d2b 100644 --- a/xpcom/tests/unit/test_windows_registry.js +++ b/xpcom/tests/unit/test_windows_registry.js @@ -5,10 +5,47 @@ * 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/. */ +const { MockRegistry } = ChromeUtils.importESModule( + "resource://testing-common/MockRegistry.sys.mjs" +); + const nsIWindowsRegKey = Ci.nsIWindowsRegKey; let regKeyComponent = Cc["@mozilla.org/windows-registry-key;1"]; -function run_test() { +// We run these tests twice: once against the native Windows registry, and a +// second time against `MockRegistry`. This gives some confidence that +// `MockRegistry` implements the same APIs as the native Windows registry. + +// This order is important: the native registry test must run first, because +// otherwise we would end up running the `MockRegistry` test twice without +// checking it against the native Windows registry. + +add_task(function test_native_registry() { + info("Running test for native Windows registry"); + run_one_test(); +}); + +add_task(function test_MockRegistry() { + let registry = new MockRegistry(); + registerCleanupFunction(() => { + registry.shutdown(); + }); + + // Before, there's nothing -- just the 3 roots (HKLM, HKCU, HKCR). + let linesBefore = []; + MockRegistry.dump(null, "", linesBefore.push.bind(linesBefore)); + strictEqual(linesBefore.length, 3); + + info("Running test for MockRegistry"); + run_one_test({ cleanup: false }); + + // After, there's something -- more than just the roots. + let linesAfter = []; + MockRegistry.dump(null, "", linesAfter.push.bind(linesAfter)); + strictEqual(linesAfter.length, 8); +}); + +function run_one_test({ cleanup = true } = {}) { //* create a key structure in a spot that's normally writable (somewhere under HKCU). let testKey = regKeyComponent.createInstance(nsIWindowsRegKey); @@ -28,11 +65,16 @@ function run_test() { //* check that the get* functions fail with the right exception codes if we ask for the wrong type or if the value name doesn't exist at all test_invalidread_functions(testKey); + //* check that removing/deleting values works + test_remove_functions(testKey); + //* check that creating/enumerating/deleting child keys works test_childkey_functions(testKey); //* clean up - cleanup_test_run(testKey, keyName); + if (cleanup) { + cleanup_test_run(testKey, keyName); + } } function setup_test_run(testKey, keyName) { @@ -152,6 +194,15 @@ function test_invalidread_functions(testKey) { } } +function test_remove_functions(testKey) { + strictEqual(testKey.valueCount, 4); + testKey.removeValue(TESTDATA_INT64NAME); + strictEqual(testKey.valueCount, 3); + + testKey.removeValue(TESTDATA_INT64NAME); + strictEqual(testKey.valueCount, 3); +} + function test_childkey_functions(testKey) { strictEqual(testKey.childCount, 0); strictEqual(testKey.hasChild(TESTDATA_CHILD_KEY), false); |