summaryrefslogtreecommitdiffstats
path: root/xpcom/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:37 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:37 +0000
commita90a5cba08fdf6c0ceb95101c275108a152a3aed (patch)
tree532507288f3defd7f4dcf1af49698bcb76034855 /xpcom/tests
parentAdding debian version 126.0.1-1. (diff)
downloadfirefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz
firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xpcom/tests')
-rw-r--r--xpcom/tests/TestHarness.h1
-rw-r--r--xpcom/tests/gtest/TestFile.cpp2
-rw-r--r--xpcom/tests/gtest/TestHandleWatcher.cpp11
-rw-r--r--xpcom/tests/gtest/TestMozPromise.cpp2
-rw-r--r--xpcom/tests/gtest/TestStrings.cpp33
-rw-r--r--xpcom/tests/gtest/TestTimers.cpp2
-rw-r--r--xpcom/tests/gtest/TestTokenizer.cpp60
-rw-r--r--xpcom/tests/gtest/moz.build16
-rw-r--r--xpcom/tests/unit/test_windows_registry.js55
9 files changed, 157 insertions, 25 deletions
diff --git a/xpcom/tests/TestHarness.h b/xpcom/tests/TestHarness.h
index e575497746..40f90d988e 100644
--- a/xpcom/tests/TestHarness.h
+++ b/xpcom/tests/TestHarness.h
@@ -23,6 +23,7 @@
#include "nsAppDirectoryServiceDefs.h"
#include "nsDirectoryServiceDefs.h"
#include "nsDirectoryServiceUtils.h"
+#include "mozilla/IntegerPrintfMacros.h"
#include "nsIDirectoryService.h"
#include "nsIFile.h"
#include "nsIObserverService.h"
diff --git a/xpcom/tests/gtest/TestFile.cpp b/xpcom/tests/gtest/TestFile.cpp
index 6e95366584..fc7650ccbc 100644
--- a/xpcom/tests/gtest/TestFile.cpp
+++ b/xpcom/tests/gtest/TestFile.cpp
@@ -36,7 +36,7 @@ static void SetUseDOSDevicePathSyntax(nsIFile* aFile) {
nsCOMPtr<nsILocalFileWin> winFile = do_QueryInterface(aFile, &rv);
VerifyResult(rv, "Querying nsILocalFileWin");
- MOZ_ASSERT(winFile);
+ MOZ_RELEASE_ASSERT(winFile);
winFile->SetUseDOSDevicePathSyntax(true);
}
}
diff --git a/xpcom/tests/gtest/TestHandleWatcher.cpp b/xpcom/tests/gtest/TestHandleWatcher.cpp
index c003a026a1..b3997140d1 100644
--- a/xpcom/tests/gtest/TestHandleWatcher.cpp
+++ b/xpcom/tests/gtest/TestHandleWatcher.cpp
@@ -101,8 +101,9 @@ class TestHandleWatcher : public testing::Test {
private:
static bool sIsLive; // just for confirmation
static void AssertIsLive() {
- MOZ_ASSERT(sIsLive,
- "attempted to use `class TestHandleWatcher` outside test group");
+ MOZ_RELEASE_ASSERT(
+ sIsLive,
+ "attempted to use `class TestHandleWatcher` outside test group");
}
static RefPtr<mozilla::SharedThreadPool> sPool;
@@ -339,7 +340,7 @@ struct ActivationTestSetup {
private:
nsIEventTarget* GetQueue(TargetType targetTyoe) {
- MOZ_ASSERT(NS_IsMainThread());
+ MOZ_RELEASE_ASSERT(NS_IsMainThread());
switch (targetTyoe) {
case TargetType::Main:
return NS_GetCurrentThread();
@@ -378,9 +379,9 @@ struct ActivationTestSetup {
}
bool Execute() {
- MOZ_ASSERT(NS_IsMainThread());
+ MOZ_RELEASE_ASSERT(NS_IsMainThread());
bool const spin = SpinEventLoopUntil([this] {
- MOZ_ASSERT(NS_IsMainThread());
+ MOZ_RELEASE_ASSERT(NS_IsMainThread());
return run.load();
}).ok();
return spin && watcher.IsStopped();
diff --git a/xpcom/tests/gtest/TestMozPromise.cpp b/xpcom/tests/gtest/TestMozPromise.cpp
index 9b06304139..02dbef7114 100644
--- a/xpcom/tests/gtest/TestMozPromise.cpp
+++ b/xpcom/tests/gtest/TestMozPromise.cpp
@@ -45,7 +45,7 @@ class DelayedResolveOrReject : public Runnable {
mIterations(aIterations) {}
NS_IMETHOD Run() override {
- MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
+ MOZ_RELEASE_ASSERT(mTaskQueue->IsCurrentThreadIn());
if (!mPromise) {
// Canceled.
return NS_OK;
diff --git a/xpcom/tests/gtest/TestStrings.cpp b/xpcom/tests/gtest/TestStrings.cpp
index b1458ec6ce..450befc20d 100644
--- a/xpcom/tests/gtest/TestStrings.cpp
+++ b/xpcom/tests/gtest/TestStrings.cpp
@@ -1183,11 +1183,9 @@ TEST_F(Strings, stringbuffer) {
memcpy(data, kData, sizeof(kData));
nsCString str;
- buf->ToString(sizeof(kData) - 1, str);
-
- nsStringBuffer* buf2;
- buf2 = nsStringBuffer::FromString(str);
+ str.Assign(buf, sizeof(kData) - 1);
+ nsStringBuffer* buf2 = str.GetStringBuffer();
EXPECT_EQ(buf, buf2);
}
@@ -1283,9 +1281,6 @@ TEST_F(Strings, string_tointeger) {
int32_t result = nsAutoCString(t->str).ToInteger(&rv, t->radix);
EXPECT_EQ(rv, t->rv);
EXPECT_EQ(result, t->result);
- result = nsAutoCString(t->str).ToInteger(&rv, t->radix);
- EXPECT_EQ(rv, t->rv);
- EXPECT_EQ(result, t->result);
}
}
@@ -2288,6 +2283,30 @@ TEST_F(Strings, printf) {
create_printf_strings(format, (char*)anotherString);
verify_printf_strings(expectedOutput);
}
+ {
+ const char* format = "RightJustify %8s";
+ const char* expectedOutput = "RightJustify foo";
+ create_printf_strings(format, "foo");
+ verify_printf_strings(expectedOutput);
+ }
+ {
+ const char* format = "LeftJustify %-8s";
+ const char* expectedOutput = "LeftJustify foo ";
+ create_printf_strings(format, "foo");
+ verify_printf_strings(expectedOutput);
+ }
+ {
+ const char* format = "RightJustify2 %*s";
+ const char* expectedOutput = "RightJustify2 foo";
+ create_printf_strings(format, 8, "foo");
+ verify_printf_strings(expectedOutput);
+ }
+ {
+ const char* format = "LeftJustify2 %-*s";
+ const char* expectedOutput = "LeftJustify2 foo ";
+ create_printf_strings(format, 8, "foo");
+ verify_printf_strings(expectedOutput);
+ }
}
// We don't need these macros following the printf test.
diff --git a/xpcom/tests/gtest/TestTimers.cpp b/xpcom/tests/gtest/TestTimers.cpp
index ea8792e273..7bd4cb1a14 100644
--- a/xpcom/tests/gtest/TestTimers.cpp
+++ b/xpcom/tests/gtest/TestTimers.cpp
@@ -308,7 +308,7 @@ class FindExpirationTimeState final {
// Create timers, with aNumLowPriority low priority timers first in the queue
void InitTimers(uint32_t aNumLowPriority, uint32_t aType) {
// aType is just for readability.
- MOZ_ASSERT(aType == nsITimer::TYPE_ONE_SHOT_LOW_PRIORITY);
+ MOZ_RELEASE_ASSERT(aType == nsITimer::TYPE_ONE_SHOT_LOW_PRIORITY);
InitTimers(aNumLowPriority, nsITimer::TYPE_ONE_SHOT_LOW_PRIORITY, nullptr);
}
diff --git a/xpcom/tests/gtest/TestTokenizer.cpp b/xpcom/tests/gtest/TestTokenizer.cpp
index 1457b82fff..3c1043a92a 100644
--- a/xpcom/tests/gtest/TestTokenizer.cpp
+++ b/xpcom/tests/gtest/TestTokenizer.cpp
@@ -1421,6 +1421,66 @@ TEST(Tokenizer, ReadIntegers)
EXPECT_TRUE(t.CheckEOF());
}
+TEST(Tokenizer, ReadHexadecimals)
+{
+ Tokenizer t("0x100,0x0a,0xFe02dXXX,0a,0xX,0xffffffff,0x7fffffff,0x100000000");
+
+ uint32_t value32;
+ int32_t signed_value32;
+ uint64_t value64;
+
+ // "0x100,"
+ EXPECT_TRUE(t.ReadHexadecimal(&value32));
+ EXPECT_TRUE(value32 == 0x100);
+ EXPECT_TRUE(t.CheckChar(','));
+
+ // "0x0a,"
+ EXPECT_TRUE(t.ReadHexadecimal(&value32));
+ EXPECT_TRUE(value32 == 0xa);
+ EXPECT_TRUE(t.CheckChar(','));
+
+ // "0xFe02dX,"
+ EXPECT_TRUE(t.ReadHexadecimal(&value32));
+ EXPECT_TRUE(value32 == 0xfe02d);
+ EXPECT_TRUE(t.CheckWord("XXX"));
+ EXPECT_TRUE(t.CheckChar(','));
+
+ // "0a,"
+ EXPECT_FALSE(t.ReadHexadecimal(&value32));
+ EXPECT_TRUE(t.ReadHexadecimal(&value32, /* aPrefixed = */ false));
+ EXPECT_TRUE(value32 == 0xa);
+ EXPECT_TRUE(t.CheckChar(','));
+
+ // "0xX,"
+ EXPECT_FALSE(t.ReadHexadecimal(&value32));
+ EXPECT_TRUE(t.Check(Tokenizer::Token::Number(0)));
+ EXPECT_TRUE(t.CheckWord("xX"));
+ EXPECT_TRUE(t.CheckChar(','));
+
+ // "0xffffffff,"
+ // there is a case to be made that maybe this should be parsed as -1,
+ // but for now, this is not supported.
+ EXPECT_FALSE(t.ReadHexadecimal(&signed_value32));
+ EXPECT_FALSE(t.CheckChar(','));
+
+ EXPECT_TRUE(t.ReadHexadecimal(&value32));
+ EXPECT_TRUE(value32 == std::numeric_limits<uint32_t>::max());
+ EXPECT_TRUE(t.CheckChar(','));
+
+ // "0x7fffffff,"
+ EXPECT_TRUE(t.ReadHexadecimal(&signed_value32));
+ EXPECT_TRUE(signed_value32 == std::numeric_limits<int32_t>::max());
+ EXPECT_TRUE(t.CheckChar(','));
+
+ // "0x100000000,"
+ EXPECT_FALSE(t.ReadHexadecimal(&value32));
+ EXPECT_FALSE(t.CheckEOF());
+ EXPECT_FALSE(t.CheckChar(','));
+
+ EXPECT_TRUE(t.ReadHexadecimal(&value64));
+ EXPECT_TRUE(t.CheckEOF());
+}
+
TEST(Tokenizer, CheckPhrase)
{
Tokenizer t("foo bar baz");
diff --git a/xpcom/tests/gtest/moz.build b/xpcom/tests/gtest/moz.build
index 4d8d38e89a..22a5b1751d 100644
--- a/xpcom/tests/gtest/moz.build
+++ b/xpcom/tests/gtest/moz.build
@@ -66,8 +66,8 @@ UNIFIED_SOURCES += [
"TestTaskQueue.cpp",
"TestTextFormatter.cpp",
"TestThreadManager.cpp",
- "TestThreadPool.cpp",
"TestThreadPoolListener.cpp",
+ "TestThreadUtils.cpp",
"TestThrottledEventQueue.cpp",
"TestTimeStamp.cpp",
"TestTokenizer.cpp",
@@ -75,24 +75,24 @@ UNIFIED_SOURCES += [
"TestVariant.cpp",
]
+# Bug 1894540 - Fails under TSAN
+if not CONFIG["MOZ_TSAN"]:
+ UNIFIED_SOURCES += [
+ "TestThreadPool.cpp",
+ ]
+
if CONFIG["OS_TARGET"] != "Android":
UNIFIED_SOURCES += [
"TestPipes.cpp",
"TestThreads.cpp",
]
-# skip the test on windows10-aarch64 due to perma-fail, bug 1422219
-if not (CONFIG["OS_TARGET"] == "WINNT" and CONFIG["TARGET_CPU"] == "aarch64"):
- UNIFIED_SOURCES += ["TestThreadUtils.cpp"]
-
# skip the test on OSX due to frequent failures (bug 1571186)
if CONFIG["OS_TARGET"] != "Darwin":
UNIFIED_SOURCES += ["TestExpirationTracker.cpp"]
# skip the test on windows10-aarch64 and Android, aarch64 due to bug 1545670
-if CONFIG["OS_TARGET"] != "Android" and not (
- CONFIG["OS_TARGET"] == "WINNT" and CONFIG["TARGET_CPU"] == "aarch64"
-):
+if CONFIG["OS_TARGET"] != "Android":
UNIFIED_SOURCES += ["TestTimers.cpp"]
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);