summaryrefslogtreecommitdiffstats
path: root/extensions/permissions/test/gtest
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /extensions/permissions/test/gtest
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--extensions/permissions/test/gtest/PermissionManagerTest.cpp52
-rw-r--r--extensions/permissions/test/gtest/moz.build11
2 files changed, 63 insertions, 0 deletions
diff --git a/extensions/permissions/test/gtest/PermissionManagerTest.cpp b/extensions/permissions/test/gtest/PermissionManagerTest.cpp
new file mode 100644
index 0000000000..b69a7d46f2
--- /dev/null
+++ b/extensions/permissions/test/gtest/PermissionManagerTest.cpp
@@ -0,0 +1,52 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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/. */
+
+#include "nsNetUtil.h"
+#include "mozilla/BasePrincipal.h"
+#include "mozilla/OriginAttributes.h"
+#include "mozilla/PermissionManager.h"
+#include "mozilla/RefPtr.h"
+#include "mozilla/Unused.h"
+#include "gtest/gtest.h"
+#include "gtest/MozGTestBench.h"
+
+using namespace mozilla;
+
+class PermissionManagerTester : public ::testing::Test {
+ protected:
+ PermissionManagerTester()
+ : mNonExistentType("permissionTypeThatIsGuaranteedToNeverExist"_ns) {}
+ void SetUp() override {
+ mPermissionManager = PermissionManager::GetInstance();
+ nsCOMPtr<nsIURI> uri;
+ nsresult rv =
+ NS_NewURI(getter_AddRefs(uri),
+ "https://test.origin.with.subdomains.example.com"_ns);
+ MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
+ mPrincipal =
+ mozilla::BasePrincipal::CreateContentPrincipal(uri, OriginAttributes());
+ }
+
+ void TearDown() override {
+ mPermissionManager = nullptr;
+ mPrincipal = nullptr;
+ }
+
+ static const unsigned kNumIterations = 100000;
+
+ nsLiteralCString mNonExistentType;
+ RefPtr<PermissionManager> mPermissionManager;
+ nsCOMPtr<nsIPrincipal> mPrincipal;
+};
+
+MOZ_GTEST_BENCH_F(PermissionManagerTester,
+ TestNonExistentPermissionFromPrincipal, [this] {
+ for (unsigned i = 0; i < kNumIterations; ++i) {
+ uint32_t result = 0;
+ Unused << mPermissionManager->TestPermissionFromPrincipal(
+ mPrincipal, mNonExistentType, &result);
+ }
+ });
diff --git a/extensions/permissions/test/gtest/moz.build b/extensions/permissions/test/gtest/moz.build
new file mode 100644
index 0000000000..132c384597
--- /dev/null
+++ b/extensions/permissions/test/gtest/moz.build
@@ -0,0 +1,11 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# 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/.
+
+UNIFIED_SOURCES += [
+ "PermissionManagerTest.cpp",
+]
+
+FINAL_LIBRARY = "xul-gtest"